9

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

4
  • I have some trouble make this script run. I have installed tampermonkey extension for chrome as recommended here stackoverflow.com/questions/5258989/…. I have copy paste the script above but it isn't working. Also I would like to add joomla.stackexchange.com in @include but I don't understand where I am suppose to add the *. Thanks a lot! Commented Oct 9, 2014 at 10:30
  • @fosco I've made a fix to this one to get it working and added in rep as well as notifications, want me to post my changes as an edit? Commented Oct 21, 2014 at 22:12
  • Sure @DavidG go for it. Commented Oct 22, 2014 at 4:28
  • 1
    @Fosco Done, don't mind if you reject/edit btw. May also be worth mentioning that this works with Chrome/TamperMonkey too. Commented Oct 22, 2014 at 8:34

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.