Add mail count for "All Mails"

try to take over the world...and add the mail count to the title

  1. // ==UserScript==
  2. // @name Add mail count for "All Mails"
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.14
  5. // @description try to take over the world...and add the mail count to the title
  6. // @author Csabinho
  7. // @include https://mail.google.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /***********************************
  12. * Use case: if you are using the "All Mails"-view you don't see the overall mail count, this is fixed by this script.
  13. * Additionally if you have pinned the Gmail-Tab you will get a "notification" via the dot in the favicon
  14. ***********************************/
  15. function addMailCountToTitle() {
  16. var mailCountIterator/* = document.evaluate('//*[@id=":wy"]/span/span[2]', document.body, null, XPathResult.ANY_TYPE, null)*/;
  17. var mailCount/* = mailCountIterator.iterateNext()*/;
  18. var debug = false;
  19.  
  20. const re =/(.*) - (.*)@(.*) - Gmail/; //If you want to use it for "Gmail for business" at the moment you'll have to change this title regex manually, maybe one day there is gonna be a GM_config frontend
  21. var m=re.exec(document.title);
  22.  
  23. if(m)
  24. {
  25. mailCountIterator = document.evaluate('//*[@id=":wy"]/span/span[2]', document.body, null, XPathResult.ANY_TYPE, null);
  26. mailCount = mailCountIterator.iterateNext();
  27.  
  28. if(mailCount)
  29. {
  30. document.title = m[0]+" ("+mailCount.innerHTML+")";
  31. if(debug)console.log(mailCount.innerHTML);
  32. }
  33. else
  34. {
  35. if(debug)console.log("null, ffs");
  36. }
  37.  
  38. return mailCount !== null;
  39. }
  40. else
  41. {
  42. if(debug)console.log("wrong title, ffs");
  43. return false;
  44. }
  45. }
  46.  
  47. if((window.location.href) == "https://mail.google.com/mail/u/0/#all") //workaround for not working # in @include
  48. {
  49. var t=setInterval(addMailCountToTitle,1000);
  50. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址