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

Content deleted Content added
Undid revision 1194532276 by Eejit43 (talk)
Syncing script from GitHub (via script)
 
(7 intermediate revisions by the same user not shown)
Line 1:
// <nowikipre>
// Note: This script was compiled and minified from TypeScript. For a more readable version, see https://github.com/Eejit43/wikipedia-scripts/blob/main/scripts/highlight-homographs.ts
 
"use strict";(()=>{(()=>{let n=document.querySelector("#firstHeading");if(!n)return mw.notify("highlight-homographs: Could not find title element!",{type:"error"});for(let t of n.children)t.textContent&&(t.nodeType===Node.TEXT_NODE?n.replaceChild(document.createRange().createContextualFragment(o(t.textContent)),t):(t.classList.contains("mw-page-title-main")||t.tagName==="I")&&(t.innerHTML=o(t.innerHTML)));function o(t){return[...t].map(e=>/[\u0400-\u052F\u1D2B\u1D78\u2DE0-\u2DFF\uA640-\uA69F]/.test(e)||/[ɑΑΒΕΖΗΙΚΜΝΟΡΤΥΧνο]/.test(e)||/[ԼՏոսօ]/.test(e)||/[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫⅬⅭⅮⅯ]/i.test(e)?`<abbr title="This character is a homograph!" style="text-decoration: none; background-color: #ff5555">${e}</abbr>`:e).join("")}})();})();
"use strict";
(() => {
const title = document.querySelector("#firstHeading");
if (!title)
return mw.notify("Could not find title element!", { type: "error" });
for (const element of title.children) {
if (!element.textContent)
continue;
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].map((char) => {
return (
/* Cyrillics */
/[\u0400-\u052F\u1D2B\u1D78\u2DE0-\u2DFF\uA640-\uA69F]/.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
);
}).join("");
}
})();
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vLi4vc2NyaXB0cy9oaWdobGlnaHQtaG9tb2dyYXBocy50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiKCgpID0+IHtcbiAgICBjb25zdCB0aXRsZSA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNmaXJzdEhlYWRpbmcnKTtcblxuICAgIGlmICghdGl0bGUpIHJldHVybiBtdy5ub3RpZnkoJ0NvdWxkIG5vdCBmaW5kIHRpdGxlIGVsZW1lbnQhJywgeyB0eXBlOiAnZXJyb3InIH0pO1xuXG4gICAgZm9yIChjb25zdCBlbGVtZW50IG9mIHRpdGxlLmNoaWxkcmVuKSB7XG4gICAgICAgIGlmICghZWxlbWVudC50ZXh0Q29udGVudCkgY29udGludWU7XG4gICAgICAgIGlmIChlbGVtZW50Lm5vZGVUeXBlID09PSBOb2RlLlRFWFRfTk9ERSkgdGl0bGUucmVwbGFjZUNoaWxkKGRvY3VtZW50LmNyZWF0ZVJhbmdlKCkuY3JlYXRlQ29udGV4dHVhbEZyYWdtZW50KG1hcmtIb21vZ3JhcGhzKGVsZW1lbnQudGV4dENvbnRlbnQpKSwgZWxlbWVudCk7XG4gICAgICAgIGVsc2UgaWYgKGVsZW1lbnQuY2xhc3NMaXN0LmNvbnRhaW5zKCdtdy1wYWdlLXRpdGxlLW1haW4nKSB8fCBlbGVtZW50LnRhZ05hbWUgPT09ICdJJykgZWxlbWVudC5pbm5lckhUTUwgPSBtYXJrSG9tb2dyYXBocyhlbGVtZW50LmlubmVySFRNTCk7XG4gICAgfVxuXG4gICAgLyoqXG4gICAgICogTWFya3MgaG9tb2dyYXBocyBpbiBhIHN0cmluZyB3aXRoIGEgcmVkIGJhY2tncm91bmQgY29sb3IuXG4gICAgICogQHBhcmFtIHN0cmluZyBUaGUgc3RyaW5nIHRvIG1hcmsgaG9tb2dyYXBocyBpbi5cbiAgICAgKiBAcmV0dXJucyBUaGUgc3RyaW5nIHdpdGggaG9tb2dyYXBocyBtYXJrZWQuXG4gICAgICovXG4gICAgZnVuY3Rpb24gbWFya0hvbW9ncmFwaHMoc3RyaW5nOiBzdHJpbmcpOiBzdHJpbmcge1xuICAgICAgICByZXR1cm4gWy4uLnN0cmluZ11cbiAgICAgICAgICAgIC5tYXAoKGNoYXIpID0+IHtcbiAgICAgICAgICAgICAgICByZXR1cm4gKFxuICAgICAgICAgICAgICAgICAgICAvKiBDeXJpbGxpY3MgKi9cbiAgICAgICAgICAgICAgICAgICAgL1tcXHUwNDAwLVxcdTA1MkZcXHUxRDJCXFx1MUQ3OFxcdTJERTAtXFx1MkRGRlxcdUE2NDAtXFx1QTY5Rl0vLnRlc3QoY2hhcikgfHwgLy8gZXNsaW50LWRpc2FibGUtbGluZSBuby1taXNsZWFkaW5nLWNoYXJhY3Rlci1jbGFzc1xuICAgICAgICAgICAgICAgICAgICAgICAgLyogR3JlZWsgKi9cbiAgICAgICAgICAgICAgICAgICAgICAgIC9bXHUwMjUxXHUwMzkxXHUwMzkyXHUwMzk1XHUwMzk2XHUwMzk3XHUwMzk5XHUwMzlBXHUwMzlDXHUwMzlEXHUwMzlGXHUwM0ExXHUwM0E0XHUwM0E1XHUwM0E3XHUwM0JEXHUwM0JGXS8udGVzdChjaGFyKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgLyogQXJtZW5pYW4gKi9cbiAgICAgICAgICAgICAgICAgICAgICAgIC9bXHUwNTNDXHUwNTRGXHUwNTc4XHUwNTdEXHUwNTg1XS8udGVzdChjaGFyKSB8fFxuICAgICAgICAgICAgICAgICAgICAgICAgLyogUm9tYW4gTnVtZXJhbHMgKi9cbiAgICAgICAgICAgICAgICAgICAgICAgIC9bXHUyMT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