User:Eejit43/scripts/highlight-homographs.js: Difference between revisions

Content deleted Content added
Syncing script from GitHub (via script)
Syncing script from GitHub (via script)
Line 4:
"use strict";
(() => {
const title = document.getElementByIdquerySelector("#firstHeading");
if (!title)
return mw.notify("Could not find title element!", { type: "error" });
[...for (const element of title.children].forEach((element) => {
if (!element.textContent)
returncontinue;
if (element.nodeType === Node.TEXT_NODE)
title.replaceChild(document.createRange().createContextualFragment(markHomographs(element.textContent)), element);
else if (element.classList.contains("mw-page-title-main") || element.tagName === "I")
element.innerHTML = markHomographs(element.innerHTML);
});
function markHomographs(string) {
return string[.split("")..string].map((char) => {
ifreturn (
/* Cyrillics */
/[\u0400-\u04FFu052F\u0500-u1D2B\u052Fu1D78\u2DE0-\u2DFF\uA640-\uA69F\u1D2B\u1D78]/.test(char) || // eslint-disable-line no-misleading-character-class
/* Greek */
/[ονɑΑΒΕΗΙΚΜΝΟΡΤΧΥΖɑΑΒΕΖΗΙΚΜΝΟΡΤΥΧνο]/.test(char) || /* Armenian */
/[օոսՏԼԼՏոսօ]/.test(char) || /* Roman Numerals */
/[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯ]/i.test(char) ? `<abbr title="This character is a homograph!" style="text-decoration: none; background-color: #ff5555">${char}</abbr>` : char
);
return `<abbr title="This character is a homograph!" style="text-decoration: none; background-color: #ff5555">${char}</abbr>`;
else
return char;
}).join("");
}