Twitter - adds unread notifications count in the tab title

Adds unread notifications count in the tab title

当前为 2015-04-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Twitter - adds unread notifications count in the tab title
  3. // @namespace rikkie
  4. // @description Adds unread notifications count in the tab title
  5. // @include https://twitter.com/
  6. // @version 1
  7. // @grant none
  8. //
  9. // Thanks a lot to wOxxOm for his valuable help
  10. // ==/UserScript==
  11.  
  12. var nCount = document.querySelector('.count > span:nth-child(1)').innerHTML;
  13. if (nCount != '0') {
  14. document.title = nCount + '|' + document.title;
  15. };
  16.  
  17. var target = document.querySelector('head > title');
  18.  
  19. var observer = new MutationObserver(function (mutations) {
  20. mutations.forEach(function (mutation) {
  21. nCount = document.querySelector('.count > span:nth-child(1)').innerHTML;
  22. if (document.title.indexOf('|') == - 1 && nCount != '0') {
  23. document.title = nCount + '|' + document.title;
  24. }
  25. });
  26. })
  27.  
  28. var config = { attributes: true, childList: true, characterData: true }
  29.  
  30. observer.observe(target, config);