User:MZMcBride/blocklogviewer.js

/* Block log display script, version [0.0.1] */

if((wgNamespaceNumber == 2 || wgNamespaceNumber == 3) && wgArticleId > 0 ) addOnloadHook(showBlockLog) function showBlockLog { var user = wgTitle.replace(/\/.*/i,'')

var show = (document.getElementById('contentSub')) ? document.getElementById('contentSub') : document.getElementById('topbar') var loglink = document.createElement('a'); loglink.setAttribute('href',mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=Special:Log/block&page=User:' + encodeURIComponent(user)); loglink.appendChild(document.createTextNode( '\nblock log')); show.appendChild(loglink);

var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&format=json&callback=showBlockLogCB&list=logevents&letype=block&lelimit=10&leprop=user|timestamp|comment|details|type&letitle=User:' + encodeURIComponent(user); var scriptElem = document.createElement('script'); scriptElem.setAttribute('src',url); scriptElem.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(scriptElem); }

function showBlockLogCB(obj) { if(!obj['query'] || !obj['query']['logevents']) return

var show = (document.getElementById('contentSub')) ? document.getElementById('contentSub') : document.getElementById('topbar') var list = ''; var events = obj['query']['logevents']; for(var i=0;i<events.length;i++) { list = '* [' + events[i]['timestamp'] + '] [' + events[i]['action'] + '] by [' + events[i]['user'] + '] '; if(events[i]['block']) list += ' for [' + events[i]['block']['duration'] + ']' if(events[i]['comment']) list += ' reason: [' + events[i]['comment'] + ']' show.appendChild(document.createElement('br')); show.appendChild(document.createTextNode(list)); } }