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)
 
(4 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";(()=>{const(()=>{let n=document.querySelector("#firstHeading");if(!n)return mw.notify("highlight-homographs: Could not find title element!",{type:"error"});for(constlet 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("")}})();})();
 
// </nowikipre>
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiLi4vc2NyaXB0cy9oaWdobGlnaHQtaG9tb2dyYXBocy50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiKCgpID0+IHtcbiAgICBjb25zdCB0aXRsZSA9IGRvY3VtZW50LnF1ZXJ5U2VsZWN0b3IoJyNmaXJzdEhlYWRpbmcnKTtcblxuICAgIGlmICghdGl0bGUpIHJldHVybiBtdy5ub3RpZnkoJ2hpZ2hsaWdodC1ob21vZ3JhcGhzOiBDb3VsZCBub3QgZmluZCB0aXRsZSBlbGVtZW50IScsIHsgdHlwZTogJ2Vycm9yJyB9KTtcblxuICAgIGZvciAoY29uc3QgZWxlbWVudCBvZiB0aXRs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