User:Beetstra/Gadget-Spamblacklistlog.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/**
 * Support for better display of log entries at en.wikipedia.
 * Tested only in Chrome.
 *
 * Author: [[:User:Beetstra]], December 2016
 * License: Quadruple licensed GFDL, GPL, LGPL and Creative Commons Attribution 3.0 (CC-BY-3.0)
 *
 * Version history:
 *
 * - start version on handling spamblacklistlog - 20161207
*/
/*jshint unused:true, eqnull:true, browser:true, white:true, indent:4 */
/*global mw, $ */
// <nowiki>
(function () {
    // Guard against double inclusions
    if (typeof window.BLLogHandler !== 'undefined') {
        return;
    }
    var conf = mw.config.get([
        'wgUserGroups',
        'wgPageName',
        'wgServer',
        'wgScriptPath',
        'wgUserName'
    ]);

    function makeRawLink(name, url, target) {
        var link = document.createElement('a');
        link.setAttribute('href', url);
        if (target) {
            link.setAttribute('target', target);
        }
        link.appendChild(document.createTextNode(name));
        return link;
    }
    function addRequestLinks(name, href, before, parent) {
        parent.insertBefore(document.createTextNode('- '), before);
        parent.insertBefore(makeRawLink(name, href), before);
        parent.insertBefore(document.createTextNode(' '), before);
    }

    if ((conf.wgPageName.substr(0, 11) !== 'Special:Log')) {
        return;
    }
    if ((conf.wgPageName == 'Special:Log/spamblacklist')) {
		edit_lks = $('span.mw-usertoollinks').toArray();    
		if (edit_lks.length === 0) {
			return;
		}
        for (i = 0; i < edit_lks.length; i++) {
        	anchors = edit_lks[i].getElementsByTagName('a');
			if (anchors != null && anchors.length > 0) {
	            anchor = anchors[0];
	            url   = anchor.getAttribute('href');
	//            https://en.wikipedia.org/wiki/Special:Contributions/2602:306:30EB:1090:14D:864F:F0D1:8D3E
	            href   =  url.replace('User_talk:', 'Special:Log/spamblacklist/');
	            title = anchor.getAttribute('title');
				orig_bracket = edit_lks[i].firstChild;
				addRequestLinks('user blacklist log', href, orig_bracket, edit_lks[i]);
				href = url.replace('/wiki/User_talk:', '/w/index.php?title=Special:AbuseLog&wpSearchUser=');
				addRequestLinks('user filter log',href,orig_bracket, edit_lks[i]);
			}
        }
	}
}());
// </nowiki>
// [[Category:Wikipedia scripts|BLLogHandler.js]]