User:Splarka/userlog.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

addOnloadHook(addusertools);

function addusertools() {
    if(!document.getElementById) return;
    if(!document.title.indexOf("User contributions") == 0) return;
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.location.href.indexOf("\/Special:Contributions\/") == -1) { 
        addlilink(tabs, "\/index.php?title=Special:Blockip&ip=" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'ban user', 'ca-blockuser'); 
        addlilink(tabs, "\/index.php?title=Special%3ALog&type=&page=&user=" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'user logs', 'ca-userlogs'); 
        addlilink(tabs, "\/index.php?title=Special%3ALog&type=&user=&page=User:" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'status', 'ca-userstatus'); 
    }
    else { 
        addlilink(tabs, "\/index.php?title=Special:Blockip&ip=" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'ban user', 'ca-blockuser'); 
        addlilink(tabs, "\/index.php?title=Special%3ALog&type=&page=&user=" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'user logs', 'ca-userlogs'); 
        addlilink(tabs, "\/index.php?title=Special%3ALog&type=&user=&page=User:" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'status', 'ca-userstatus'); 
    }
}
function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}