User:Splarka/sysopdectector.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:Splarka/sysopdectector. |
/* This is a proof-of-concept 'sysop detector' script using ajax.
+ The current implementation only triggers on user pages (and not user subpages) in namespace 2.
. This could be extended to namespace 3, but suggested not to trigger on any subpages.
+ The page does not need to exist. Works on edit/history and anything with tabs. Should work in all monobook-dervied skins.
+ The current display is in ca-nstab-user (the leftmost tab). the text 'sysop' is added.
. Alternatives include adding a class to the body tag, for css manipulation.
+ Sysops versed in JS (zocky/lupin/ruud/others?) may edit this page freely (this is simply a proof-of-concept test) or fork it.
. If you do, please update these notes as appropriate.
. Please be aware my ajax is amateurish.
+ Stab MZMcBride if anything goes wrong.
*/
if(wgNamespaceNumber == 2) addOnloadHook(getGroupSysop)
function getGroupSysop() {
if(wgTitle.indexOf('/')==-1) {
var url = wgServer + wgScriptPath + '/api.php?action=query&list=allusers&aulimit=1&augroup=sysop&format=xml&aufrom=' + encodeURIComponent(wgTitle);
getXMLsysop(url);
}
}
function getXMLsysop(url) {
var getReq;
if (window.XMLHttpRequest) { // Non-IE browsers
getReq = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
getReq = new ActiveXObject('Microsoft.XMLHTTP');
}
if (getReq) {
getReq.onreadystatechange = function () {
switch (getReq.readyState) {
case 4:
if (getReq.status == 200) { // OK response
var txt = getReq.responseText;
var sysgrp = '<u name="' + wgTitle.replace(/\'/g,''') + '" />';
var isSysop = (txt.indexOf(sysgrp) > -1) ? true : false
if(isSysop) {
document.getElementById('ca-nstab-user').getElementsByTagName('a')[0].appendChild(document.createTextNode(' (sysop)'));
}
} else {
alert('Error:' + getReq.statusText)
}
break;
}
}
try {
getReq.open('GET', url, true);
getReq.send('');
} catch (e) {
alert(e);
}
} else {
alert('XMLHTTPRequest not supported');
}
}