Twitter - adds unread notifications count in the tab title

Adds unread notifications count in the tab title

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

  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 lastvalue = document.querySelector('.count > span:nth-child(1)').innerHTML;
  13. if (lastvalue != '0'){
  14. document.title = lastvalue + '|' + 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. if (document.title.indexOf('|') == -1 && document.querySelector('.count > span:nth-child(1)').innerHTML != '0' ) {
  22. document.title = document.querySelector('.count > span:nth-child(1)').innerHTML + '|' + document.title;
  23. lastvalue = document.querySelector('.count > span:nth-child(1)').innerHTML;
  24. }
  25. });
  26. })
  27.  
  28. var config = {attributes: true, childList: true, characterData: true}
  29.  
  30. observer.observe(target, config);