Skip to content

Commit 26161a4

Browse files
committed
Title-notification: Use ES2015 & fix linting
1 parent 59ff893 commit 26161a4

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

github-title-notification.user.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// ==UserScript==
22
// @name GitHub Title Notification
3-
// @version 1.0.1
3+
// @version 1.0.2
44
// @description A userscript that changes the document title if there are unread messages
55
// @license https://creativecommons.org/licenses/by-sa/4.0/
6-
// @namespace http://github.com/Mottie
6+
// @namespace https://github.com/Mottie
77
// @include https://github.com/*
88
// @run-at document-idle
99
// @grant GM_registerMenuCommand
@@ -13,8 +13,7 @@
1313
// @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-title-notification.user.js
1414
// @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-title-notification.user.js
1515
// ==/UserScript==
16-
/* jshint unused:true, esnext:true */
17-
(function() {
16+
(() => {
1817
"use strict";
1918

2019
let timer,
@@ -23,40 +22,34 @@
2322
// check every 30 seconds
2423
interval = GM_getValue("interval", 30);
2524

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-
3325
function check() {
3426
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;
3629
//
3730
if (!/^\(\d+\)/.test(title)) {
38-
title = title.replace(/^\([^)]+\)\s/, "");
31+
title = title.replace(/^(\([^)]+\)\s)*/g, "");
3932
}
4033
document.title = hasUnread ? "(" + indicator + ") " + title : title;
4134
}
4235

4336
function setTimer() {
4437
clearInterval(timer);
4538
if (document.querySelector(".mail-status")) {
46-
timer = setInterval(function() {
39+
timer = setInterval(() => {
4740
check();
4841
}, interval * 1000);
4942
check();
5043
}
5144
}
5245

5346
// Add GM options
54-
GM_registerMenuCommand("Set GitHub Title Notification Indicator", function() {
47+
GM_registerMenuCommand("Set GitHub Title Notification Indicator", () => {
5548
indicator = prompt("Indicator Value (it will be wrapped in parentheses)?", indicator);
5649
GM_setValue("indicator", indicator);
5750
check();
5851
});
59-
GM_registerMenuCommand("Set GitHub Title Notification Interval", function() {
52+
GM_registerMenuCommand("Set GitHub Title Notification Interval", () => {
6053
interval = prompt("Interval Value (in seconds)?", interval);
6154
GM_setValue("interval", interval);
6255
setTimer();

0 commit comments

Comments
 (0)