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