GitHub Title Notification

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

当前为 2016-03-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GitHub Title Notification
  3. // @version 1.0.0
  4. // @description A userscript that changes the document title if there are unread messages
  5. // @license https://creativecommons.org/licenses/by-sa/4.0/
  6. // @namespace http://github.com/Mottie
  7. // @include https://github.com/*
  8. // @run-at document-idle
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @author Rob Garrison
  13. // ==/UserScript==
  14. (function() {
  15. "use strict";
  16.  
  17. var timer,
  18. // indicator added to document title (it will be wrapped in parentheses)
  19. indicator = GM_getValue("indicator", "♥"),
  20. // check every 30 seconds
  21. interval = GM_getValue("interval", 30),
  22.  
  23. hasClass = function(el, name) {
  24. if (el) {
  25. return el.classList ? el.classList.contains(name) : new RegExp("\\b" + name + "\\b").test(el.className);
  26. }
  27. return false;
  28. },
  29. check = function() {
  30. var title = document.title,
  31. hasUnread = hasClass(document.querySelector(".mail-status"), "unread");
  32. //
  33. if (!/^\(\d+\)/.test(title)) {
  34. title = title.replace(/^\([^)]+\)\s/, "");
  35. }
  36. document.title = hasUnread ? "(" + indicator + ") " + title : title;
  37. },
  38. setTimer = function() {
  39. clearInterval(timer);
  40. if (document.querySelector(".mail-status")) {
  41. timer = setInterval(function() {
  42. check();
  43. }, interval * 1000);
  44. check();
  45. }
  46. };
  47.  
  48. // Add GM options
  49. GM_registerMenuCommand("Set GitHub Title Notification Indicator", function() {
  50. indicator = prompt("Indicator Value (it will be wrapped in parentheses)?", indicator);
  51. GM_setValue("indicator", indicator);
  52. check();
  53. });
  54. GM_registerMenuCommand("Set GitHub Title Notification Interval", function() {
  55. interval = prompt("Interval Value (in seconds)?", interval);
  56. GM_setValue("interval", interval);
  57. setTimer();
  58. });
  59.  
  60. setTimer();
  61.  
  62. })();

QingJ © 2025

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