User:PeterL/block.js

function getblocktoken_api { // get block token (see http://www.mediawiki.org/wiki/API:Block) var api = sajax_init_object; api.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=query&prop=info&intoken=block&titles=Whatever', false); api.send(null); if(api.status==200) { var response = eval('(' + api.responseText + ')'); var token = response['query']['pages'][0]['blocktoken']; } else { alert('The token query returned an error.'); } return token; }

function jsblock { var toollinks = getElementsByClassName(document.getElementById('bodyContent'),"*","mw-usertoollinks"); // existing "(Talk | contribs | block)" links var blocklinks = new Array; // new links for (var j = 0; j < toollinks.length; j++) { // iterating through the existing links to add new links j.appendChild(document.createTextNode(getblocktoken_api)); } } addOnloadHook(jsblock);