Content deleted Content added
No edit summary |
m Fix requested on WP:IANB |
||
(13 intermediate revisions by 2 users not shown) | |||
Line 1:
// <nowiki>
// Adjust chset-* style code chart colouration to match Unicode categories.
// Adds a button below the source editor.
Line 9 ⟶ 10:
// Furthermore, this loads JavaScript code from a third-party source for identifying Unicode character
// category. I cannot guarantee that this will not be compromised. Proceed at your own risk.
//
// Usage: mw.loader.load("//en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:HarJIT/Scripts/unicategorise.js");
Line 41 ⟶ 40:
var ezh = null;
jQuery.get("https://cdn.
b = b.pysplit("=", 1)[1].trim();
if (b.endswith(";")) {
Line 64 ⟶ 63:
};
doyogh();
var CHECKMS = "<!-- XXX: check colour -->";
var SHARED = "<!-- Note: Only the shared/invariant EBCDIC cells are colored; international glyphs are not. -->\n";
var FROM = "Invariant alphanumeric, punctuation, and control characters are shown in color.";
var TO = "Non-invariant characters are shown boxed.";
var
var SUMMARY2 = "box nationalised codes, and regenerate colour codes based on Unicode category ([[User:HarJIT/Scripts/unicategorise.js|script]])";
var FAKEHEAD = "|-\n| width=\"4%\" |\n! width=\"6%\" | \u20140 || width=\"6%\" | \u20141\n! width=\"6%\" | \u20142 || width=\"6%\" | \u20143\n! width=\"6%\" | \u20144 || width=\"6%\" | \u20145\n! width=\"6%\" | \u20146 || width=\"6%\" | \u20147\n! width=\"6%\" | \u20148 || width=\"6%\" | \u20149\n! width=\"6%\" | \u2014A || width=\"6%\" | \u2014B\n! width=\"6%\" | \u2014C || width=\"6%\" | \u2014D\n! width=\"6%\" | \u2014E || width=\"6%\" | \u2014F";
var FAKEFOOT = "|-\n||\n!—0||—1||—2||—3||—4||—5||—6||—7||—8||—9||—A||—B||—C||—D||—E||—F";
var fix = function (inp) {
Line 69 ⟶ 77:
// We need *a* colour template to begin with in order to parse it, even if
// it is the wrong one. For the places where they aren't used already.
// Also some EBCDIC pages use lack of colour as a distinguishing mark, which
inp = inp.replace(/\n\|\s*\|?\{\{[Cc]hset-c(?=ell|trl)/g, "\n|{{chset-color-intl}}|{{chset-c");▼
// no longer shows up now that -letter is white.
var iox = (inp.contains(SHARED))?("color-intl-box"):("color-intl");
▲ inp = inp.replace(/\n\|\s*\|?\{\{[Cc]hset-c(?=ell|trl)/g, "\n|{{chset-
var doz = inp.split("{{Chset-").join("{{chset-").split("\n|{{chset-color-");
output += doz[0];
Line 77 ⟶ 88:
if (i.startswith("undef")) {
output += "\n|{{chset-color-" + ii;
return; /* i.e. continue */
} else if (i.startswith("intl}}|{{chset-cell3||<u>''")) {
// Common in APL code pages, including EBCDIC ones.
output += "\n|{{chset-color-letter" + ii.substring(4);
return; /* i.e. continue */
} else if (i.startswith("hangups}}|{{chset-cell3||<u>''")) {
// What the hell (chset-color-hangups does not exist and afaik never did)
output += "\n|{{chset-color-letter" + ii.substring(7);
return; /* i.e. continue */
} else if (i.substring(0, 40).contains("l4|")) {
Line 112 ⟶ 131:
var codep = String.fromCodePoint(parseInt(cpt, 16));
i = i.split("}}]]").join("|[[" + wlink + "|" + codep + "]]}}");
}
if (cpt.trim().length === 0 && iii.startswith("ctrl")) {
// Unmapped controls, common in articles about EBCDIC variants.
cpt = "0000"; // Kludgy
}
var cpts = cpt.replace(/<ref[^>]*?(\/>|>[^<]*?<\/ref>)/g, " ");
Line 118 ⟶ 141:
cpts = cpts.split("/");
var colours = new Set([]);
var checkmsg = "";
cpts.forEach((cpt) => {
cpt = cpt.trim();
if (cpt.contains(" ")) {
cpt = cpt.pysplit(" ", 1)[0];
checkmsg = CHECKMS;
}
if (cpt.match(/^[0-9a-f]+$/i)) {
codept = String.fromCodePoint(parseInt(cpt, 16));
Line 160 ⟶ 188:
var colour = null;
if (colours.length == 0) {
output += "\n|
return; /* i.e. continue */
} else if (colours.length == 1) {
Line 171 ⟶ 199:
});
if (colour === null) {
output += "\n|
return; /* i.e. continue */
}
}
output += "\n|" + checkmsg + "{{chset-color" + colour + hilite + "}}|{{chset" + layout + nombre + "|" + i;
});
return output;
Line 188 ⟶ 216:
nxt.parentNode.insertBefore(butn, nxt);
butn.onclick = () => {
var rprt = SUMMARY;
var txt = jQuery("#wpTextbox1")[0];
var vl = txt.value;
var fx = fix(vl);
if (fx != vl) {
if (vl.contains(SHARED)) {
fx = fx.split(SHARED).join("").split(FROM).join(TO);
rprt = SUMMARY2;
}
var tytl = jQuery("#firstHeading")[0].innerText.trim().substring("Editing ".length);
fx = fx.replace(FAKEHEAD, "{{chset-table-header|" + tytl + "}}");
fx = fx.replace(FAKEFOOT, "{{chset-table-footer}}");
txt.value = fx;
jQuery("#wpSummary")[0].value = rprt;
}
▲ jQuery("#wpSummary")[0].value = "regenerate colour codes based on Unicode category ([[User:HarJIT/Scripts/unicategorise.js|script]])";
}
}
Line 202 ⟶ 239:
// End: [[m:w:User:HarJIT/Scripts/unicategorise.js]]
// </nowiki>
|