Ir al contenido

Usuario:Benjavalero/Taller/MediaWiki:Gadget-CorrectorOrtografico.js

De Wikipedia, la enciclopedia libre
Esta es una versión antigua de esta página, editada a las 13:32 2 abr 2021 por Benjavalero (discusión · contribs.). La dirección URL es un enlace permanente a esta versión, que puede ser diferente de la versión actual.

Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.

// Minimale Rechtschreibprüfung: Version 2
// Siehe Wikipedia:Helferlein/Rechtschreibprüfung
// 
// Der Text eines Artikels (in der normalen Artikelansicht, nicht beim Bearbeiten) wird an den
// Toolserver geschickt, gegen eine Wortliste geprüft und fehlerhafte Wörter werden dann im
// Text rot hervorgehoben.

function spellcheck()
{
  // Anfrage an Toolserver senden
  var scJS = document.createElement('script');
  scJS.type = 'text/javascript';
  scJS.src = '//tools.wmflabs.org/spellcheck/es/checkArticle.php?pageName=' + encodeURIComponent( mw.config.get( 'wgPageName' ));
  
  document.getElementsByTagName('head')[0].appendChild(scJS);
}

window.markWordStart = function(text, hint)
{
  if (typeof bodyContent == 'undefined' && !(bodyContent = mw.util.$content[0]))
    bodyContent = document.getElementById('article');

  // Unfortunately not all browsers support all cool regex features
  // so we provide alternatives more or less valid for the old ones (and IE)
  var supportUnicode;
  try {
    supportUnicode = new RegExp('\\p{L}', 'u').test('á');
  } catch (e) {
    supportUnicode = false;
  }
  // Look-ahead is fully supported: https://caniuse.com/sr_js-regexp-lookahead

  var unicodeDelim = '\\P{L}';
  // https://github.com/mathiasbynens/regexpu
  var fallbackDelim = '(?:[\0-@\[-`\{-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02C2-\u02C5\u02D2-\u02DF\u02E5-\u02EB\u02ED\u02EF-\u036F\u0375\u0378\u0379\u037E\u0380-\u0385\u0387\u038B\u038D\u03A2\u03F6\u0482-\u0489\u0530\u0557\u0558\u055A-\u055F\u0589-\u05CF\u05EB-\u05EE\u05F3-\u061F\u064B-\u066D\u0670\u06D4\u06D6-\u06E4\u06E7-\u06ED\u06F0-\u06F9\u06FD\u06FE\u0700-\u070F\u0711\u0730-\u074C\u07A6-\u07B0\u07B2-\u07C9\u07EB-\u07F3\u07F6-\u07F9\u07FB-\u07FF\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u083F\u0859-\u085F\u086B-\u089F\u08B5\u08C8-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962-\u0970\u0981-\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA-\u09BC\u09BE-\u09CD\u09CF-\u09DB\u09DE\u09E2-\u09EF\u09F2-\u09FB\u09FD-\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A-\u0A58\u0A5D\u0A5F-\u0A71\u0A75-\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA-\u0ABC\u0ABE-\u0ACF\u0AD1-\u0ADF\u0AE2-\u0AF8\u0AFA-\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A-\u0B3C\u0B3E-\u0B5B\u0B5E\u0B62-\u0B70\u0B72-\u0B82\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BCF\u0BD1-\u0C04\u0C0D\u0C11\u0C29\u0C3A-\u0C3C\u0C3E-\u0C57\u0C5B-\u0C5F\u0C62-\u0C7F\u0C81-\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA-\u0CBC\u0CBE-\u0CDD\u0CDF\u0CE2-\u0CF0\u0CF3-\u0D03\u0D0D\u0D11\u0D3B\u0D3C\u0D3E-\u0D4D\u0D4F-\u0D53\u0D57-\u0D5E\u0D62-\u0D79\u0D80-\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0E00\u0E31\u0E34-\u0E3F\u0E47-\u0E80\u0E83\u0E85\u0E8B\u0EA4\u0EA6\u0EB1\u0EB4-\u0EBC\u0EBE\u0EBF\u0EC5\u0EC7-\u0EDB\u0EE0-\u0EFF\u0F01-\u0F3F\u0F48\u0F6D-\u0F87\u0F8D-\u0FFF\u102B-\u103E\u1040-\u104F\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F-\u109F\u10C6\u10C8-\u10CC\u10CE\u10CF\u10FB\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B-\u137F\u1390-\u139F\u13F6\u13F7\u13FE-\u1400\u166D\u166E\u1680\u169B-\u169F\u16EB-\u16F0\u16F9-\u16FF\u170D\u1712-\u171F\u1732-\u173F\u1752-\u175F\u176D\u1771-\u177F\u17B4-\u17D6\u17D8-\u17DB\u17DD-\u181F\u1879-\u187F\u1885\u1886\u18A9\u18AB-\u18AF\u18F6-\u18FF\u191F-\u194F\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19FF\u1A17-\u1A1F\u1A55-\u1AA6\u1AA8-\u1B04\u1B34-\u1B44\u1B4C-\u1B82\u1BA1-\u1BAD\u1BB0-\u1BB9\u1BE6-\u1BFF\u1C24-\u1C4C\u1C50-\u1C59\u1C7E\u1C7F\u1C89-\u1C8F\u1CBB\u1CBC\u1CC0-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1CFB-\u1CFF\u1DC0-\u1DFF\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FBD\u1FBF-\u1FC1\u1FC5\u1FCD-\u1FCF\u1FD4\u1FD5\u1FDC-\u1FDF\u1FED-\u1FF1\u1FF5\u1FFD-\u2070\u2072-\u207E\u2080-\u208F\u209D-\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u214F-\u2182\u2185-\u2BFF\u2C2F\u2C5F\u2CE5-\u2CEA\u2CEF-\u2CF1\u2CF4-\u2CFF\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D70-\u2D7F\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF-\u2E2E\u2E30-\u3004\u3007-\u3030\u3036-\u303A\u303D-\u3040\u3097-\u309C\u30A0\u30FB\u3100-\u3104\u3130\u318F-\u319F\u31C0-\u31EF\u3200-\u33FF\u4DC0-\u4DFF\u9FFD-\u9FFF\uA48D-\uA4CF\uA4FE\uA4FF\uA60D-\uA60F\uA620-\uA629\uA62C-\uA63F\uA66F-\uA67E\uA69E\uA69F\uA6E6-\uA716\uA720\uA721\uA789\uA78A\uA7C0\uA7C1\uA7CB-\uA7F4\uA802\uA806\uA80B\uA823-\uA83F\uA874-\uA881\uA8B4-\uA8F1\uA8F8-\uA8FA\uA8FC\uA8FF-\uA909\uA926-\uA92F\uA947-\uA95F\uA97D-\uA983\uA9B3-\uA9CE\uA9D0-\uA9DF\uA9E5\uA9F0-\uA9F9\uA9FF\uAA29-\uAA3F\uAA43\uAA4C-\uAA5F\uAA77-\uAA79\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAC3-\uAADA\uAADE\uAADF\uAAEB-\uAAF1\uAAF5-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F\uAB5B\uAB6A-\uAB6F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uDEAF]|\uD87A[\uDFE1-\uDFFF]|\uD87E[\uDE1E-\uDFFF]|\uD884[\uDF4B-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])';

  var word = text.toString().replace(/\//g, '').replace(/\\b/g, '');
  var regex;
  if (supportUnicode) {
    regex = new RegExp(unicodeDelim + word + '(?=' + unicodeDelim + ')', 'u');
  } else {
    regex = new RegExp(fallbackDelim + word + '(?=' + fallbackDelim + ')');
  }
  markWord(bodyContent, regex, hint);
};
 
function markWord(node, text, hint)
{
  var pos, len, newnodes = 0;
  var newnode, middlenode, endnode;
 
  // textnode - search for word
  if (node.nodeType == 3)
  { 
    pos = node.data.search(text);
    if(pos >= 0)
    {
      // create new span-element
      newnode = document.createElement("span");
      newnode.style.backgroundColor = "#FF9191";
      newnode.title = hint;
 
      // get length of the matching part
      len = node.data.match(text)[0].length;
 
      // splits content in three parts: begin, middle and end
      // In the regex we capture an additional character at the left
      middlenode = node.splitText(pos + 1);
      endnode = middlenode.splitText(len - 1);
 
      // appends a copy of the middle to the new span-node
      newnode.appendChild(middlenode.cloneNode(true));
      // replace middlenode with the new span-node
      middlenode.parentNode.replaceChild(newnode, middlenode);
 
      newnodes = 1;
    }
  }
  else if ((node.nodeType == 1)  // element node
           && (node.hasChildNodes()) // with child nodes
           && (node.tagName.toLowerCase() != "script") // no script, style and form
           && (node.tagName.toLowerCase() != "style")
           && (node.tagName.toLowerCase() != "form"))
  {
    var this_child;
    for (this_child = 0; this_child < node.childNodes.length; this_child++)
    {
      this_child = this_child + markWord(node.childNodes[this_child], text, hint);
    }
  }
  return newnodes;
}
 
function RP_load()
{
  // Variablenabfrage, ob '''keine''' automatische RP bei jedem Aufruf eines Artikels gewünscht ist.
  // wenn automatische RP nicht gewünscht ist, dann einfach "'''var DontAutorunRP = true;'''" vor die Einbindung schreiben
  // ansonsten einfach weg lassen.
  
  if ( !window.DontAutorunRP )
  {
    // Nur beim Betrachten, aber nicht auch unnötigerweise beim Bearbeiten, auf der Versionsgschichte
    // etc. laden: spart Wartezeit beim Benutzer und Ressourcen auf dem Toolserver
    // Standardmäßig RP nur auf Artikelseiten, wenn RPonAllPages "true" RP in allen Seiten
    
    if (mw.config.get( 'wgAction' ) == 'view' && (($.inArray( mw.config.get( 'wgNamespaceNumber' ), [0, 4, 8, 10, 12, 14, 100, 102, 104]) > -1 && !mw.config.get( 'wgPageName' ).match( "^(Anexo:Falsos_amigos|Wikipedia:(Café|Consultas|Corrector_ortográfico/Listado|Informes_de_error|Tablón_de_anuncios_de_los_bibliotecarios|Taller_idiomático|Vandalismo_en_curso))" ) ) || window.RPonAllPages )) 
    {
      spellcheck();
    }
  }
}

$( RP_load );