User:GoldenRing/userlinks.js

From Wikipedia, the free encyclopedia
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.
// <pre> <nowiki>

(function() {
    $(document).ready(function() {
	var div = $("<div></div>");
        div.css({
            display: 'none',
            border: 'solid thin black',
            position: 'absolute',
            'background-color': '#ffffff',
            'z-index': '10',
            padding: '0.3em'
        });
        div.attr('id', 'gr-userlinks-hover');
        $('body').append(div);
        var hidetimer = null;
        var hidebox = function() {
            $('#gr-userlinks-hover').css('display', 'none');
            hidetimer = null;
        }            
        var wikilink = function(l, t) {
            return '<a href="' + mw.config.get('wgServer') + '/wiki/' + l + '">' + t + '</a>';
        }
        $("a.userlink[title^='User:'], a.mw-userlink[title^='User:']").hover(
            function() {
                if (hidetimer != null) {
                    window.clearTimeout(hidetimer);
                }
                var title = $(this).attr('title');
                var username = title.split(':')[1];
                var dne = ' (page does not exist)';
                if( username.endsWith(dne) )
                    username = username.substring(0, username.indexOf(dne));
                if( username.indexOf(";") > 0 )
                    username = username.substring(0, username.indexOf(";"));
                console.log(username);
                $('#gr-userlinks-hover')
                    .html(wikilink('User talk:' + username, 'talk') + ' ' + wikilink('Special:Contributions/' + username, 'contribs') + ' <a href="https://xtools.wmflabs.org/ec/en.wikipedia.org/' + username + '">X!</a> ' + wikilink('Special:Log/' + username, 'log') + ' ' + wikilink('Special:Log/block?page=' + username, 'block log') + ' ' + wikilink('Special:DeletedContributions/' + username, 'deleted contribs'))
                    .css({
                        display: 'block',
                        top: $(this).offset().top + $(this).height() + 3,
                        left: $(this).offset().left
                    });
            },
            function() {
                hidetimer = window.setTimeout(hidebox, 250);
            }
        ); 
        $("#gr-userlinks-hover").hover(
            function() {
                if (hidetimer != null) window.clearTimeout(hidetimer);
            },
            function() {
                hidetimer = window.setTimeout(hidebox, 250);
            }
        );
    });
} ());
// </nowiki> </pre>