User:Stwalkerster/grouphighlight.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. |
Documentation for this user script can be added at User:Stwalkerster/grouphighlight. |
// Mercilessly stolen from https://en.wikipedia.org/w/index.php?title=User:Amorymeltzer/crathighlighter.js&oldid=877594709
//
//
//Taken from https://en.wikipedia.org/w/index.php?title=User:Bellezzasolo/Scripts/adminhighlighter.js&oldid=829278273
//Inspired from https://en.wikipedia.org/w/index.php?title=User:Amalthea/userhighlighter.js&oldid=437693511
//Apply to sysops, IA, CU, OS, 'crats', AC members
//
//If you want different colors, add something like
//.userhighlighter_bureaucrat {background-color: red !important}
//to your modern.css file.
//
//Not at all friendly to other styles, erases 'em all completely
//<nowiki>
;(function($, mw){
var acdata, crdata, osdata, cudata, iadata, sydata, swdata;
$.when(
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/arbcom.json', function(data){
acdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/bureaucrat.json', function(data){
crdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/oversight.json', function(data){
osdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/checkuser.json', function(data){
cudata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/interface-admin.json', function(data){
iadata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/crathighlighter.js/sysop.json', function(data){
sydata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:AmoryBot/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.util.addCSS(".userhighlighter_arbcom {background-color: #888888}");
mw.util.addCSS(".userhighlighter_bureaucrat {background-color: #5588FF}");
mw.util.addCSS(".userhighlighter_oversight {background-color: #DD66DD}");
mw.util.addCSS(".userhighlighter_checkuser {background-color: #FFFF00}");
mw.util.addCSS(".userhighlighter_interface-admin {background-color: #66DD66}");
mw.util.addCSS(".userhighlighter_sysop {background-color: #00FFFF}");
mw.util.addCSS(".userhighlighter_steward {background-color: #FF9933}");
$('#mw-content-text a').each(function(index,linkraw){
try {
var link = $(linkraw);
var url = link.attr('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[0].parentElement.className && link[0].parentElement.classList[0] == 'autocomment') return; // Skip span.autocomment links aka automatic section links in edit summaries
if (link[0].className && link[0].classList[0] == 'external') return; // Avoid errors on hard-to-parse external links
var 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') {
var 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) {
var user = mwtitle.getMain().replace(/_/g," ");
if (mwtitle.getNamespaceId() === -1) user = user.replace('Contributions/','');
if(acdata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_arbcom");
}
if(crdata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_bureaucrat");
}
if(osdata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_oversight");
}
if(cudata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_checkuser");
}
if(iadata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_interface-admin");
}
if (sydata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_sysop");
}
if (swdata[user] == 1) {
link.attr("class", link.attr("class") + " userhighlighter_steward");
}
}
}
} catch (e) {
console.log(linkraw);
// Sometimes we will run into unparsable links, so just log these and move on
window.console && console.error('Admin highlighter recoverable error',e.message);
}
});
});
});
}(jQuery, mediaWiki));
//</nowiki>