User:Wikifresc/common.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | The accompanying .css page for this skin is at User:Wikifresc/common.css. |
// remove brackets from numbered references
function nativeSelector() {
var elements = document.querySelectorAll("sup, sup a, sup i, sup em");
var results = [];
var child;
for(var i = 0; i < elements.length; i++) {
child = elements[i].childNodes[0];
if(elements[i].hasChildNodes() && child.nodeType == 3) {
results.push(child);
}
}
return results;
}
var textnodes = nativeSelector(), _nv;
for (var i = 0, len = textnodes.length; i<len; i++){
_nv = textnodes[i].nodeValue;
textnodes[i].nodeValue = _nv.replace(/\[([0-9]+)\]/gi,'$1');
}
// typekit
(function(d) {
var config = {
kitId: 'nea5oiw',
scriptTimeout: 3000,
async: true
},
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)
})(document);
// replace acronyms
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = "html body abbr { font-variant-caps: all-small-caps; font-variant-numeric: normal; }";
document.head.appendChild(css);
var matchText = function(node, regex, callback, excludeElements) {
excludeElements || (excludeElements = ['script', 'style', 'iframe', 'canvas', 'code', 'pre', 'input', 'textarea']);
var child = node.firstChild;
while (child) {
switch (child.nodeType) {
case 1:
if (excludeElements.indexOf(child.tagName.toLowerCase()) > -1)
break;
matchText(child, regex, callback, excludeElements);
break;
case 3:
var bk = 0;
child.data.replace(regex, function(all) {
var args = [].slice.call(arguments),
offset = args[args.length - 2],
newTextNode = child.splitText(offset+bk), tag;
bk -= child.data.length + all.length;
newTextNode.data = newTextNode.data.substr(all.length);
tag = callback.apply(window, [child].concat(args));
child.parentNode.insertBefore(tag, newTextNode);
child = newTextNode;
});
regex.lastIndex = 0;
break;
}
child = child.nextSibling;
}
return node;
};
utfnum = "(U\\+[0-9A-Fa-f]{4,})";
outer = "0-9-";
alphabet = "A-ZЀ-ЯΑ-ΪÁÉÍÓÚÝÀÈÌÒÙỲÂÊÎÔÛŶÄËÏÖÜŸḦẄẌĀĒĪŌŪȲĂĔĬŎŬĞÃẼĨÕŨỸÑṼȦḂĊḊĖḞĠḢİṀṄȮṖṘṠṪẆẊẎŻẠḄḌẸḤỊḲḶṂṆỌṚṢṬỤṾẈỴẒŐŰÆŒØÅŮČĎĚĽŇŘŠŤŽÇĘĢĶĻŅŖŞŢÐĐÞẞΆΈΉΊΌΎΏ";
joiners = "&:_"; // '’
longnum = "(" +
"[" + alphabet + "]*" +
"[0-9:—–-]{9,}" +
"[" + alphabet + "]*" +
")";
matchText(document.getElementsByTagName("*")[0], new RegExp(
utfnum + "|" + longnum + "|" +
"(" +
"[" + alphabet + outer + "]*" +
"[" + joiners + "]*" +
"[" + alphabet + "]{2,}" +
"[" + alphabet + outer + "]*" +
")",
"gu"), function(node, match, offset) {
var span = document.createElement("abbr");
span.textContent = match;
return span;
});