-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appBadge.js
27 lines (25 loc) · 934 Bytes
/
appBadge.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
(function() {
'use strict';
if (! (navigator.setAppBadge instanceof Function)) {
navigator.setAppBadge = async (n) => {
if (! Number.isInteger(n)) {
throw new TypeError('Failed to execute \'setAppBadge\' on \'Navigator\': Value is not of type \'unsigned long long\'');
} else if (n < 0) {
throw new TypeError('Failed to execute \'setAppBadge\' on \'Navigator\': Value is outside the \'unsigned long long\' value range.');
} else if (n === 0) {
if (document.title.startsWith('(')) {
document.title = document.title.replace(/^\((\d{1,2}\+?)\)\s/, '');
}
} else if (n < 100) {
await navigator.clearAppBadge();
document.title = `(${n}) ${document.title}`;
} else {
await navigator.clearAppBadge();
document.title = `(99+) ${document.title}`;
}
};
}
if (! (navigator.clearAppBadge instanceof Function)) {
navigator.clearAppBadge = () => navigator.setAppBadge(0);
}
})();