Skip to main content
9 of 9
replaced http://meta.stackoverflow.com/ with https://meta.stackoverflow.com/

A userscript to update the page/tab title with the # of unread notifications

##About

Per this question: https://meta.stackoverflow.com/questions/57315/can-we-get-notification-in-the-tab-change-of-title This user script was created to help draw attention to notifications even when the tab isn't in focus. It changes the page title to include the 'unreadCount' from the Stack Exchange Super-Collider.

Code

// ==UserScript==
// @name           SE Tab Notifier
// @namespace      http://fosco.com
// @description    Update Tab Title when Inbox has content
// @include        http://*.stackexchange.com/*
// @include        http://superuser.com/*
// @include        http://serverfault.com/*
// @include        https://meta.stackoverflow.com/*
// @include        http://stackoverflow.com/*
// @include        http://stackapps.com/*
// ==/UserScript==

var script = document.createElement("script");
script.textContent = "(" + grease.toString() + ")()";
document.body.appendChild(script);

function grease()
{
    var newNotifications = $('.network-items a.js-inbox-button .unread-count');
    var newReputations = $('.network-items a.js-achievements-button .unread-count');
    
    var oldTitle = $(document).attr('title');
    
    var notifyme = function ()
    {
        var notificationCount = newNotifications.text().trim();
        var reputationCount = newReputations.text().trim();
        
        if(newNotifications.is(':visible') && newReputations.is(':visible'))
        {
            $(document).attr('title','(' + notificationCount + '/' + reputationCount + ') ' + oldTitle);
        }
        else if(newNotifications.is(':visible'))
        {
            $(document).attr('title','(' + notificationCount + ') ' + oldTitle);
        }
        else if(newReputations.is(':visible'))
        {
            $(document).attr('title','(' + reputationCount + ') ' + oldTitle);
        }
        else
        {
            //Reset back to original title if notifications have gone
            $(document).attr('title', oldTitle);
        }
    };
    window.setInterval(notifyme, 1000);
}

###License

Free!

###Platform

Greasemonkey, Tampermonkey, and most other userscript engines

##Contact

gfosco AT gmail

Fosco
  • 191
  • 1
  • 7