Jump to content

User:Þjarkur/Highlight homographs in title.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* 
  Highlight Unicode tricks to bypass creation protection, such as at [[Artem Kahаn]] (one of the A's is a Cyrillic a)
  CC0
*/
$.ready.then(function () {

  if (
    mw.config.get('wgNamespaceNumber') !== 0 &&
    mw.config.get('wgNamespaceNumber') !== 118
  ) return;

  $('#firstHeading').contents().each(function () {
    if (this.nodeType === Node.TEXT_NODE) {
      var text = $(this).text()
      var newText = text.split('').map(i => {
        if (
          /* Cyrillics */
          /[\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F\u1D2B\u1D78]/.test(i) ||
          /* Greek */
          /[ονɑΑΒΕΗΙΚΜΝΟΡΤΧΥΖ]/.test(i) ||
          /* Armenian */
          /[օոսՏԼ] /.test(i)
        ) {
          return `<span style="background:#76deb2;padding:0 4px">${i}</span>`
        }
        return i
      }).join('')
      if (text !== newText) {
        $(this).replaceWith(newText + ' <div style="font-size:13px;font-family:sans-serif;color: #bb2400;padding-bottom: 6px;"><b>Note</b>: The highlighted letter in the title is a homograph, the current title may be evading watchlists.</div>')
      }
    }
  })
})