StackOverflow - Enhanced User Toolbar

By Jon Erickson Last update Feb 4, 2010 — Installed 492 times.

There are 8 previous versions of this script.

// ==UserScript==
// @name           StackOverflow - Enhanced User Toolbar
// @namespace      StackOverflow
// @include        http://stackoverflow.com/*
// @include        http://superuser.com/*
// @include        http://serverfault.com/*
// @include        http://meta.stackoverflow.com/*
// ==/UserScript==

(function(){
    function GM_init() {
        if(typeof unsafeWindow.jQuery == 'undefined') { 
            window.setTimeout(GM_init, 100); 
        } else { 
            jQuery_init(unsafeWindow.jQuery);
        }
    }

    GM_init();

    function jQuery_init($) {
        var userIds = {
            so: 1950,
            su: 1467,
            sf: 3298,
            meta: 1950		
        };

        var icons = {
            so: "data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAABMLAAATCwAAAAAAAAAAAAAAAAAAbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf8AAAAAAAAAAGxsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FAAAAAAAAAABsbG3%2FbGxt%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsbG3%2FbGxt%2FwAAAAAAAAAAbGxt%2F2xsbf8AAAAAbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf8AAAAAbGxt%2F2xsbf8AAAAAAAAAAGxsbf9sbG3%2FAAAAAGxsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FbGxt%2F2xsbf9sbG3%2FAAAAAGxsbf9sbG3%2FAAAAAAAAAABsbG3%2FbGxt%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAVHibFE94oDxKeKRkRHiqkUx4ohlsbG3%2FbGxt%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AAAAAAg4ODDoSEhMuFhYX%2FhYWFegAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAg4ODAoWFha2FhYX%2FhYWFoQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAhISEAoWFhZOFhYX%2FhYWFwYWFhQYAAAAAAAAAAAAAAAAAAAAAgAH%2F%2F4AB%2F%2F%2Bf%2Bf%2F%2FkAn%2F%2F5AJ%2F%2F%2BfAf%2F%2F4Af%2F%2F%2BAH%2F%2F%2Fgg%2F%2F%2F%2FgH%2F%2F%2FAB%2F%2F%2FwIf%2F%2F%2BMP%2F%2F%2F%2BH%2F%2F%2F%2FD%2F%2F%2F%2Fg%2F%2F%2Fw%3D%3D"
        };

        var badgeLocation = $('#hlinks');
        var messages = badgeLocation.children('a:first').clone();
        var logout = badgeLocation.children('a[href*=logout]:first').clone();
        var todaysReputationUrl = getTodaysReputationUrl();
        var todaysReputationLocation = " div#tabs a[href^='/users/recent/'][href*='tab=reputation']:first span.bounty-indicator-tab:first";
        var lsep = '<span class="lsep">|</span>';
        var cache = $('<div></div>');

        function getTodaysReputationUrl() {
            function ensureNumberPadded(num) {
                if(num < 10) return '0' + num;
                return num;
            }

            var today = new Date();
            var todayUTC = today.getUTCFullYear() + '-' + ensureNumberPadded(today.getUTCMonth() + 1) + '-' + ensureNumberPadded(today.getUTCDate());
            var url = ($("#topbar a[href^='/users/recent/']:first").attr('href').match(/^[^?]+/))[0] + '?StartDate=' + todayUTC + '&EndDate=' + todayUTC;
            var result = url;
            return result;
        }

        function addProfileInfo(title, data, image) {
            cache
                .append(lsep)
                .append(' ')
                .append("<a id='user-'" + title + " href='" + data.profileUrl + "'><img src='" + image + "' title='" + title + "' style='padding:1px'></a>")
                .append(' ')
                .append("<span class='reputation-score'>" + data.reputation + "</span>")
                .append(data.badgeHtml + " ");
        }

        function begin() {
            if (badgeLocation.children('a[href*=logout]').length) {
                stackoverflow();
            }
        }

        function stackoverflow() {
            $.getJSON('http://stackoverflow.com/users/flair/' + userIds.so + '.json?callback=?', function(data){
                addProfileInfo('so', data, icons.so);
                superuser();
            });
        }

        function superuser() {
            $.getJSON('http://superuser.com/users/flair/' + userIds.su + '.json?callback=?', function(data){
                addProfileInfo('su', data, icons.su);
                serverfault();
            });
        }

        function serverfault() {
            $.getJSON('http://serverfault.com/users/flair/' + userIds.sf + '.json?callback=?', function(data){
                addProfileInfo('sf', data, icons.sf);
                meta();
            });
        }

        function meta() {
            $.getJSON('http://meta.stackoverflow.com/users/flair/' + userIds.meta + '.json?callback=?', function(data){
                addProfileInfo('meta', data, icons.meta);
                finalize();
            });
        }

        function finalize() {
            var url = todaysReputationUrl + todaysReputationLocation;
            $('<span></span>').load(url, function() {
                var repToday = $(this).text();
                $(this).remove();
                if(!repToday) repToday = 0;
                var repToday = parseInt(repToday, 10);

                var color = (repToday < 200) 
                    ? '#75845C'     // Greenish
                    : '#9A4444';    // Redish

                $('#search input').css('max-width', '100px');

                var badgeLocation = $('#hlinks');

                badgeLocation.css('margin-right', '10px');
                badgeLocation.empty();

                badgeLocation.append(messages)
                    .append(' ')
                    .append(lsep)
                    .append(' ')
                    .append('<span title="you have earned ' + repToday + ' reputation today" class="reputation-score"><a href="' + todaysReputationUrl + '" style="color:' + color + ';">' + repToday + '</a></span>')
                    .append(' ')
                    .append(cache.html())
                    .append(lsep)
                    .append(' ')
                    .append(logout);
            });
        }

        begin();
    }
})();