// Forked from [[User:Amorymeltzer/crathighlighter]]
//<nowiki>
function createEmojiElement(char, title) {
const emoji = document.createElement("span");
emoji.textContent = char;
emoji.setAttribute("title", title);
emoji.style.margin = "0 1px";
return emoji;
}
(function($, mw) {
let acdata, crdata, osdata, cudata, sydata, swdata;
$.when(
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/arbcom.json",
function(data) {
acdata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/bureaucrat.json",
function(data) {
crdata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/oversight.json",
function(data) {
osdata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/checkuser.json",
function(data) {
cudata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amalthea_(bot)/userhighlighter.js/sysop.js",
function(data) {
sydata = data;
}
),
$.getJSON(
mw.config.get("wgScriptPath") +
"/index.php?action=raw&ctype=application/json&title=User:Amorymeltzer/crathighlighter.js/steward.json",
function(data) {
swdata = data;
}
)
).then(function() {
ADMINHIGHLIGHT_EXTLINKS = window.ADMINHIGHLIGHT_EXTLINKS || false;
ADMINHIGHLIGHT_NAMESPACES = [-1, 2, 3];
mw.loader.using(
["mediawiki.util", "mediawiki.Uri", "mediawiki.Title"],
function() {
$("#mw-content-text a").each(function(_index, link) {
try {
const url = link.getAttribute("href");
if (!url || url.charAt(0) === "#") {
return; // Skip <a> elements that aren't actually links; skip anchors
}
if (
url.lastIndexOf("http://", 0) !== 0 &&
url.lastIndexOf("https://", 0) !== 0 &&
url.lastIndexOf("/", 0) !== 0
) {
return; //require http(s) links, avoid "javascript:..." etc. which mw.Uri does not support
}
if (
link.parentElement.className &&
link.parentElement.classList[0] == "autocomment"
) {
return; // Skip span.autocomment links aka automatic section links in edit summaries
}
if (link.className && link.classList[0] == "external") {
return; // Avoid errors on hard-to-parse external links
}
const uri = new mw.Uri(url);
if (!ADMINHIGHLIGHT_EXTLINKS && !$.isEmptyObject(uri.query)) return; // Skip links with query strings if highlighting external links is disabled
if (uri.host == "en.wikipedia.org") {
const mwtitle = new mw.Title(
mw.util.getParamValue("title", url) ||
decodeURIComponent(uri.path.slice(6))
); // Try to get the title parameter of URL; if not available, remove '/wiki/' and use that
if (
$.inArray(
mwtitle.getNamespaceId(),
ADMINHIGHLIGHT_NAMESPACES
) >= 0
) {
let user = mwtitle.getMain().replace(/_/g, " ");
if (user.toLowerCase().indexOf("contributions") !== -1) {
const rolesContainer = document.createElement("sup");
if (crdata[user] == 1) {
const bureaucrat = createEmojiElement("🔧", "Bureaucrat");
rolesContainer.appendChild(bureaucrat);
}
if (sydata[user] == 1) {
const admin = createEmojiElement("🧹", "Admin");
rolesContainer.appendChild(admin);
}
if (osdata[user] == 1) {
const oversighter = createEmojiElement("👁", "Oversighter");
rolesContainer.appendChild(oversighter);
}
if (cudata[user] == 1) {
const checkuser = createEmojiElement("❓", "Checkuser");
rolesContainer.appendChild(checkuser);
}
if (swdata[user] == 1) {
const steward = createEmojiElement("🌐", "Steward");
rolesContainer.appendChild(steward);
}
if (acdata[user] == 1) {
const arbcom = createEmojiElement("⚖", "ArbCom");
rolesContainer.appendChild(arbcom);
}
rolesContainer.style.fontSize = "0.9em";
rolesContainer.style.marginLeft = "2px";
// append constructed span to user link
link.parentNode.insertBefore(
rolesContainer,
link.nextSibling
);
}
}
}
} catch (e) {
console.log(link);
// Sometimes we will run into unparsable links, so just log these and move on
window.console &&
console.error("Admin tagger recoverable error", e.message);
}
});
}
);
});
})(jQuery, mediaWiki);
//</nowiki>