User:Richwales/markusers2.js

function Richwales_markUsers { // if (!window.mbTempStyle) mbTempStyle = 'opacity: 0.7; text-decoration-line: line-through'; // if (!window.mbIndefStyle) mbIndefStyle = 'opacity: 0.4; font-style: italic; text-decoration-line: line-through'; // if (!window.mbTipBoxStyle) mbTipBoxStyle = 'font-size:smaller; background:#FFFFF0; ' + 'border:1px solid #FEA; padding:0 0.3em; color:#AAA'; if (!window.mbTooltip) { i18n = { 'dsb': '(blokěrowany wót $2 za traśe wót $1: $3)', 'en': '(blocked by $2 with an expiry time of $1: $3)', 'eo': '(forbarita de $2 por daŭro de $1: $3)', 'hsb': '(zablokowany wot $2 za traće wot $1: $3)', 'ja': '($2によるブロック. 期限:$1 理由:$3)', 'pt': '(bloqueado por $2 até $1: $3)', 'ru': '(блокировка $2 на срок $1: $3)', 'sv': '(har blockerats av $2 till $1: $3)', 'uk': '(блокування $2 на термін $1: $3)' };   mbTooltip = i18n[mw.config.get('wgUserLanguage')] || i18n.en; } appendCSS('a.user-blocked-temp    {' + mbTempStyle   + '}\n' +            'a.user-blocked-indef   {' + mbIndefStyle  + '}\n' +            'a.user-blocked-tipbox  {' + mbTipBoxStyle + '}\n' +            'a.user-not-blocked     { }\n' +            '.user-is-unconfirmed  { background-color: #ddd }\n' +            '.user-is-new          { background-color: #fdd }\n' +            '.user-has-5k-edits    { background-color: #fffff0 }\n' +            '.user-has-10k-edits   { background-color: #ffffe4 }\n' +            '.user-has-15k-edits   { background-color: #ffffd8 }\n' +            '.user-has-20k-edits   { background-color: #ffffcc }\n' +            '.user-has-25k-edits   { background-color: #ffffc0 }\n' +            '.user-has-30k-edits   { background-color: #ffffb4 }\n' +            '.user-has-35k-edits   { background-color: #ffffa8 }\n' +            '.user-has-40k-edits   { background-color: #ffff9c }\n' + '.user-has-45k-edits  { background-color: #ffff90 }\n' + '.user-has-50k-edits  { background-color: #ffff84 }\n' + '.user-is-sysop       { background-color: #cff }\n' + '.user-is-sysop-plus  { background-color: #cfc }\n' + '.user-may-be-arb     { background-color: #fddd77 }\n' ); //  function apiRequest(params, callback) { //    var aj = sajax_init_object //    aj.onreadystatechange = function { //      if (aj.readyState != 4 || aj.status != 200) return  //      callback(eval('(' + aj.responseText + ')')) //    } //    aj.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=json&' + params, true) //    aj.send('') //  }

function apiRequest (params, callback) { // gotta rewrite because sajax_init_object no longer exists var request = $.ajax ({		url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=json&' + params	}); request.done (function (msg) {		callback (msg);	}); }

var users = []; var userLinks = []; function target(link) { var hr = link.href; if (!hr || hr === '') hr = link.baseURI; hr = decodeURIComponent(hr); if (hr.match(/&action=edit/) && !hr.match(/&action=edit&redlink=1/)) return ''; hr = hr.replace(/^.*\/(wiki\/|w\/index\.php\?title=)/, ''); hr = hr.replace(/[?&].*$/, ''); hr = hr.replace(/_/g, ' '); // hr = decodeURIComponent(hr); if (hr.match(/#/)) hr = ''; if (hr.match(/\//) && !hr.match(/Special:Contributions\//)) hr = ''; return hr; } function checkLinks(namespaces) { // function target(link) { //   ap = wgArticlePath.replace('$1', '') //   var hr = link.href //   if (!hr || hr == '') hr = link.baseURI //   if (hr.replace(wgServer, ).match(/^http:/)) return  //     // elimnating the decodeURIComponent error on non-UTF links //   if (hr.replace(wgServer, '').substr(0, ap.length) == ap) // .wikipedia.org/wiki/... //   if (hr.replace(wgServer, '').match(/wiki[pm]edia\.org.*\/wiki\//)) //     return decodeURIComponent(hr.replace(/^.*\/wiki\//, '') //                                  .replace(/^(.*?)[?&#].*$/, '$1') //                                  .replace(/_/g, ' ')) //     return link.title + (hr.match(/#/) ? '#...' : '') //                       // that's risky, but we can't bypass IE6's bugs another way... //                       // "thanks" Tim Starling if it breaks eventually :( //    else // .wikipedia.org/w/index.php?title=... //      return decodeURIComponent(hr.replace(wgScript, '') //                                        .replace(/.*[?&]title=(.*?)&[^#]*/, '$1') //                                         .replace(/_/g, ' ')) //  }    var content = document.getElementById('content') ||                  document.getElementById('mw_content') ||                  document.body;    var links = content.getElementsByTagName('a');    var ns = namespaces.query.namespaces;    var ca;    for (var i = 0; i < namespaces.query.specialpagealiases.length; i++) {      if (namespaces.query.specialpagealiases[i].realname == 'Contributions')        ca = namespaces.query.specialpagealiases[i].aliases;    }    if (!namespaces.fromcookie) {      document.cookie = 'mbNamespaces='            + escape([ns[-1]['*'], ns[2]['*'], ns[3]['*'], ca.join('|')].join(':'))            + '; expires=' + (new Date((new Date).getTime + Math.exp(20))).toGMTString;    }    //   User:   User_talk:   Special:Contributions/   in canonical form, as they are in hrefs    var isUser = new RegExp('^((' + ns[2]['*'] + '|' + ns[3]['*'] + '):|' + ns[-1]['*'] + ':(' + ca.join('|').replace(/_/g, ' ') + ')\\/)([^\\/#]*)$'); var j = 0; for (i = 0; i < links.length; i++) { var li = links[i]; var tli = target(li); if (!tli || tli === '') continue; if (tli.match(isUser)) { users[j++] = tli.replace(isUser, '$4'); userLinks[j-1] = li; li.style.opacity = window.mbLoadingOpacity || 0.65; // a way to mark that the data is loading }   }    if (j === 0) return; // nobody to mark // performing sort and duplicate cleanup, otherwise we risk of some users being marked twice var usersTemp = users.join('|').split('|'); usersTemp.sort; var u = []; u[0] = usersTemp[0]; if (usersTemp[1]) { j = 1; for (i = 1; i < usersTemp.length; i++) { if (usersTemp[i] != usersTemp[i-1]) u[j++] = usersTemp[i]; }   }    usersTemp = null; for (i = 0; i < links.length; i++) links[i].style.opacity = ''; var query = ''; for (i = 0; i < u.length; i++) { if (query.length > 1000) { // splitting the URL into small parts when needed apiRequest('action=query&list=users&usprop=groups|editcount&ususers=' + query, markSysops); apiRequest('action=query&list=blocks&bkprop=user|expiry|by|reason&bkusers=' + query, markBlocked); query = ''; }     query += (query ? '|' : '') + encodeURIComponent(u[i]); }   if (query) { apiRequest('action=query&list=users&usprop=groups|editcount&ususers=' + query, markSysops); apiRequest('action=query&list=blocks&bkprop=user|expiry|by|reason&bkusers=' + query, markBlocked); }   contents = links = ns = ca = null; } function markBlocked(ulist) { if (!ulist || !ulist.query) return; var ul = ulist.query.blocks; if (!ul) return; var mark = []; var tips = {}; var infin = {}; var j = 0; for (var i = 0; i < ul.length; i++) { var u = ul[i]; if (u.expiry) { var name = u.user; mark[j++] = name; tips[name] = ' ' + mbTooltip.replace('$1', u.expiry.replace(/(.*)T(.*)Z/, '$1 $2 UTC')) .replace('$2', u.by) .replace('$3', u.reason); infin[name] = (u.expiry.substr(0, 2) == 'in'); }     u = null; }   var fenceOfShame = '|' + mark.join('|') + '|'; var span; for (i = 0; i < userLinks.length; i++) { var l = userLinks[i]; if (j > 0 && fenceOfShame.indexOf('|' + users[i] + '|') > -1) { l.className += ' user-blocked-' + (infin[users[i]] ? 'indef' : 'temp'); if (window.mbTipBox) { span = document.createElement('span'); span.title = users[i] + tips[users[i]]; span.className = 'user-blocked-tipbox'; span.innerHTML = '#'; l.parentNode.insertBefore(span, userLinks[i]); } else l.title += tips[users[i]]; }     else l.className += ' user-not-blocked'; }   ul = mark = tips = infin = null; } function markSysops(ulist) { if (!ulist || !ulist.query) return; var ul = ulist.query.users; if (!ul) return; // var plusgroups = /^(bureaucrat|checkuser|steward|oversight)$/; var name; var sysops = []; var sysops_plus = []; var maybe_arbs = []; var unconfirmed = []; var edits = {}; var s = 0; var sp = 0; var ma = 0; var uc = 0; for (var i = 0; i < ul.length; i++) { name = ul[i].name; var usergroups = []; var gl = ul[i].groups; if (gl) { for (var gi = 0; gi < gl.length; gi++) usergroups[gl[gi]] = 1; if (usergroups['sysop']) { if (usergroups['checkuser'] && usergroups['oversight']) maybe_arbs[ma++] = name; else if (usergroups['checkuser'] || usergroups['oversight'] ||                  usergroups['steward']   || usergroups['bureaucrat']) sysops_plus[sp++] = name; else sysops[s++] = name; }       else if (!usergroups['autoconfirmed'] && !usergroups['confirmed']) unconfirmed[uc++] = name; }     var e = ul[i].editcount; if (e < 100) edits[name] = -1; else if (e) { e = (Math.floor (e / 5000)) * 5; if (e > 50) e = 50; if (e > 0) edits[name] = e;     } }   if (s == 0 && sp == 0) return; var sysopFence = '|' + sysops.join('|')     + '|'; var plusFence = '|' + sysops_plus.join('|') + '|'; var arbFence  = '|' + maybe_arbs.join('|')  + '|'; var unconFence = '|' + unconfirmed.join('|') + '|'; var span; for (var i = 0; i < userLinks.length; i++) { name = users[i]; fencedName = '|' + name + '|'; if (arbFence.indexOf(fencedName) > -1) userLinks[i].className += ' user-may-be-arb'; else if (plusFence.indexOf(fencedName) > -1) userLinks[i].className += ' user-is-sysop-plus'; else if (sysopFence.indexOf(fencedName) > -1) userLinks[i].className += ' user-is-sysop'; else if (unconFence.indexOf(fencedName) > -1) userLinks[i].className += ' user-is-unconfirmed'; else if (edits[name] < 0) userLinks[i].className += ' user-is-new'; else if (edits[name]) userLinks[i].className += ' user-has-' + edits[name] + 'k-edits'; else userLinks[i].className += ' user-not-special'; }   ul = sysops = sysops_plus = maybe_arbs = unconfirmed = null } if (ca = document.getElementById('ca-showblocks')) ca.parentNode.removeChild(ca) var cookie = document.cookie.match(/mbNamespaces=(.*?);/) if (cookie) { cookie = unescape(cookie[1]).split(':') checkLinks({     'query': {        'namespaces': { '-1': { '*': cookie[0] }, '2': { '*': cookie[1] }, '3': { '*': cookie[2] } },        'specialpagealiases': [{'realname': 'Contributions', 'aliases': cookie[3].split('|')}]      },      'fromcookie': 1    }) } else { apiRequest('action=query&meta=siteinfo&siprop=namespaces|specialpagealiases', checkLinks) } } addOnloadHook(Richwales_markUsers);