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