MediaWiki:NormalizeMarcData.js: mudanças entre as edições

De Wikincat
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
(4 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 38: Linha 38:
);
);
instanceMains.forEach((instanceMain) => {
instanceMains.forEach((instanceMain) => {
function transform(string) {
instanceMain
const originalString = string;
.querySelectorAll('.oo-ui-inputWidget-input')
.forEach((input) => {
return (
const normalizedInput = input;
originalString
normalizedInput.value = normalizedInput.value
// "$a Bar \n$b Baz" > " $a Bar $b Baz"
// "$a Bar \n$b Baz" > " $a Bar $b Baz"
.replace(/\s*(\$[a-z0-8])\s*/g, ' $1 ')
.replace(/\s*(\$[a-z0-8])\s*/g, ' $1 ')
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo"
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo"
.replace(/\n|\s\s+|\t/g, ' ')
.replace(/\n|\s\s+|\t/g, ' ')
// "$aBar $bBaz" > "$a Bar $b Baz"
.replace(/(\$[a-z0-9])([^\s])/g, '$1 $2')
// replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404)
// replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404)
.replace('|', '%7C');
.replace('|', '%7C')
// remove consecutive spaces
.replace(/ +(?= )/g, '')
);
}

instanceMain
.querySelectorAll('.oo-ui-inputWidget-input')
.forEach((input) => {
const normalizedInput = input;
normalizedInput.value = transform(normalizedInput.value);
});
});

instanceMain.querySelectorAll('textarea').forEach((textarea) => {
instanceMain.querySelectorAll('textarea').forEach((textarea) => {
const normalizedInput = textarea;
const normalizedInput = textarea;
textarea.value = normalizedInput.value
normalizedInput.value = transform(normalizedInput.value);
// "$a Bar \n$b Baz" > " $a Bar $b Baz"
.replace(/\s*(\$[a-z0-8])\s*/g, ' $1 ')
// "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar Foo" > "$a Bar Foo"
.replace(/\n|\s\s+|\t/g, ' ')
// replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404)
.replace('|', '%7C');
});
});
});
});

Edição atual tal como às 13h23min de 30 de outubro de 2024

/* jshint esversion: 10 */
function rmCarriageReturn() {
  const textareas = document.body.querySelectorAll('textarea');
  textareas.forEach((textarea) => {
    const element = textarea;
    element.value = element.value.replace('
', '');
  });
}

function rmHtmlTags() {
  const textareas = document.body.querySelectorAll('textarea');
  textareas.forEach((textarea) => {
    const element = textarea;
    element.value = element.value.replace(
      /<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g,
      '',
    );
  });
}

function rmTxtFromHiddenFields() {
  const spans = document.body.querySelectorAll('span.hiddenByPF');
  spans.forEach((elem) => {
    elem.querySelectorAll('.input.oo-ui-inputWidget-input').forEach((input) => {
      const element = input;
      element.value = '';
    });
    elem.querySelectorAll('textarea').forEach((input) => {
      const element = input;
      element.value = '';
    });
  });
}

function normalizeInput() {
  const instanceMains = document.body.querySelectorAll(
    '.instanceMain div table',
  );
  instanceMains.forEach((instanceMain) => {
    function transform(string) {
      const originalString = string;
      return (
        originalString
          // "$a   Bar   \n$b    Baz" > " $a Bar $b Baz"
          .replace(/\s*(\$[a-z0-8])\s*/g, ' $1 ')
          // "$a Bar\nFoo" > "$a Bar Foo" ou "$a Bar  Foo" > "$a Bar Foo"
          .replace(/\n|\s\s+|\t/g, ' ')
          // "$aBar $bBaz" > "$a Bar $b Baz"
          .replace(/(\$[a-z0-9])([^\s])/g, '$1 $2')
          // replace "|" by "%7C" (Ex.: http://viaf.org/processed/WKP|Q2484404)
          .replace('|', '%7C')
          // remove consecutive spaces
          .replace(/ +(?= )/g, '')
      );
    }

    instanceMain
      .querySelectorAll('.oo-ui-inputWidget-input')
      .forEach((input) => {
        const normalizedInput = input;
        normalizedInput.value = transform(normalizedInput.value);
      });

    instanceMain.querySelectorAll('textarea').forEach((textarea) => {
      const normalizedInput = textarea;
      normalizedInput.value = transform(normalizedInput.value);
    });
  });
}