Twitter - adds unread notifications count in the tab title

Adds unread notifications count in the tab title

目前為 2015-04-11 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Twitter - adds unread notifications count in the tab title
// @namespace   rikkie
// @description Adds unread notifications count in the tab title
// @include     https://twitter.com/
// @version     1
// @grant       none
//
// Thanks a lot to wOxxOm for his valuable help 
// ==/UserScript==

var nCount = document.querySelector('.count > span:nth-child(1)').innerHTML;
if (nCount != '0') {
  document.title = nCount + '|' + document.title;
};

var target = document.querySelector('head > title');

var observer = new MutationObserver(function (mutations) {
  mutations.forEach(function (mutation) {
    nCount = document.querySelector('.count > span:nth-child(1)').innerHTML;
    if (document.title.indexOf('|') == - 1 && nCount != '0') {
      document.title = nCount + '|' + document.title;
    }
  });
})

var config = { attributes: true, childList: true, characterData: true }

observer.observe(target, config);