User:Novem Linguae/Scripts/UserHighlighterSimple.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. |
![]() | This user script seems to have a documentation page at User:Novem Linguae/Scripts/UserHighlighterSimple. |
//<nowiki>
/*
Copied and modified. Original source (and much credit to) User:Chlod/Scripts/UserHighlighter.js.
PURPOSE:
- Highlights user names with their corresponding permissions/rights.
DIFFERENCES FROM ORIGINAL SCRIPT:
- This version contains less colors.
- Merged checkuser, oversighter, interface admin with admin.
- Merged new page reviewer with page mover and template editor.
- Changed some colors.
- Change "system operator" to "admin".
TODO:
- Add blocked.
*/
mw.hook('wikipage.content').add(function($, mw){
var ecdata, pcdata, mvdata, tpdata, addata;
$.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:Bellezzasolo Bot/userhighlighter.js/excon.js', function(data){
ecdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pcusr.js', function(data){
pcdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/pgmvr.js', function(data){
mvdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/temop.js', function(data){
tpdata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Amalthea_(bot)/userhighlighter.js/sysop.js', function(data){
addata = data;
}),
$.getJSON(mw.config.get('wgScriptPath')+'/index.php?action=raw&ctype=application/json&title=User:Bellezzasolo Bot/userhighlighter.js/ptusr.js', function(data){
ptdata = 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/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() {
// IP
// no color
// autoconfirmed
// no color
// extended confirmed (53,000)
mw.util.addCSS("[class~=userhighlighter_excon] {background-color: #99f}");
// Pending changes reviewer (7449)
mw.util.addCSS("[class~=userhighlighter_pcusr] {background-color: #ddd}");
// New page reviewer? (714)
mw.util.addCSS("[class~=userhighlighter_ptusr] {background-color: #9c9}");
// Page mover (331)
mw.util.addCSS("[class~=userhighlighter_pgmvr] {background-color: #9c9}");
// template editor (188)
mw.util.addCSS("[class~=userhighlighter_temop] {background-color: #9c9}");
// Admin
mw.util.addCSS("[class~=userhighlighter_sysop] {background-color: #9ff}");
// checkuser
// mw.util.addCSS("[class~=userhighlighter_checkuser][class~=userhighlighter_sysop] {background-color: #9cf}");
// oversight
// mw.util.addCSS("[class~=userhighlighter_oversight][class~=userhighlighter_sysop] {background-color: #999}");
// arbcom
mw.util.addCSS("[class~=userhighlighter_arbcom][class~=userhighlighter_sysop] {background-color: #f99}");
// interface admin
// mw.util.addCSS("[class~=userhighlighter_interface-admin][class~=userhighlighter_sysop] {background-color: #ff9}");
// bureaucrat
mw.util.addCSS("[class~=userhighlighter_bureaucrat][class~=userhighlighter_sysop] {background-color: #fc9}");
// steward
mw.util.addCSS("[class~=userhighlighter_steward] {background-color: #9cc}");
$('#article a, #bodyContent a, #mw_contentholder 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
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/',''); // For special page "Contributions/<username>"
if (mwtitle.getNamespaceId() === -1) user = user.replace('Contribs/',''); // The Contribs abbreviation too
if (swdata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_steward');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Steward");
}
if(crdata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_bureaucrat');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Bureaucrat");
}
if(iadata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_interface-admin');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Interface administrator");
}
if(acdata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_arbcom');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Arbitration Committee member");
}
if(osdata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_oversight');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Oversighter");
}
if(cudata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_checkuser');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "CheckUser");
}
if (addata[user] == 1) {
link.addClass(link.attr('class') + ' userhighlighter_sysop');
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Admin");
}
if(tpdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_temop"); // Override the above color by using `a.userhighlighter_temop.userhighlighter_temop {background-color: COLOR !important}`
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Template editor");
}
if(mvdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_pgmvr"); // Override the above color by using `a.userhighlighter_pgmvr.userhighlighter_pgmvr {background-color: COLOR !important}`
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Page mover");
}
if(ptdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_ptusr"); // Override the above color by using `a.userhighlighter_ptusr.userhighlighter_ptusr {background-color: COLOR !important}`
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Patroller");
}
if(pcdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_pcusr"); // Override the above color by using `a.userhighlighter_pcusr.userhighlighter_pcusr {background-color: COLOR !important}`
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Pending changes reviewer");
}
if(ecdata[user] == 1) {
link.addClass(link.attr('class') + " userhighlighter_excon"); // Override the above color by using `a.userhighlighter_excon.userhighlighter_excon {background-color: COLOR !important}`
if (link.attr("title") == null || link.attr("title").startsWith("User:")) link.attr("title", "Extended confirmed");
}
}
}
} catch (e) {
// 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>