GitHub Title Notification

A userscript that changes the document title if there are unread messages

  1. // ==UserScript==
  2. // @name GitHub Title Notification
  3. // @version 1.0.7
  4. // @description A userscript that changes the document title if there are unread messages
  5. // @license MIT
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @match https://github.com/*
  9. // @run-at document-idle
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @icon https://github.githubassets.com/pinned-octocat.svg
  14. // @supportURL https://github.com/Mottie/GitHub-userscripts/issues
  15. // ==/UserScript==
  16.  
  17. (() => {
  18. "use strict";
  19.  
  20. let timer,
  21. // indicator added to document title (it will be wrapped in parentheses)
  22. indicator = GM_getValue("indicator", "♥"),
  23. // check every 30 seconds
  24. interval = GM_getValue("interval", 30);
  25.  
  26. function check() {
  27. let title = document.title,
  28. mail = document.querySelector(".mail-status"),
  29. hasUnread = mail ? !mail.hidden : false;
  30. //
  31. if (!/^\(\d+\)/.test(title)) {
  32. title = title.replace(/^(\([^)]+\)\s)*/g, "");
  33. }
  34. document.title = hasUnread ? "(" + indicator + ") " + title : title;
  35. }
  36.  
  37. function setTimer() {
  38. clearInterval(timer);
  39. if (document.querySelector(".mail-status")) {
  40. timer = setInterval(() => {
  41. check();
  42. }, interval * 1000);
  43. check();
  44. }
  45. }
  46.  
  47. // Add GM options
  48. GM_registerMenuCommand("Set GitHub Title Notification Indicator", () => {
  49. const val = prompt("Indicator Value (it will be wrapped in parentheses)?", indicator);
  50. if (val !== null) {
  51. GM_setValue("indicator", val);
  52. check();
  53. }
  54. });
  55. GM_registerMenuCommand("Set GitHub Title Notification Interval", () => {
  56. const val = prompt("Interval Value (in seconds)?", interval);
  57. if (val !== null) {
  58. GM_setValue("interval", val);
  59. setTimer();
  60. }
  61. });
  62.  
  63. setTimer();
  64.  
  65. })();

QingJ © 2025

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