-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-timer-title.user.js
56 lines (49 loc) · 2.26 KB
/
google-timer-title.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
// ==UserScript==
// @name Google Timer Title Update
// @namespace org.alorel.googletimer
// @author Alorel <a.molcanovas@gmail.com>
// @homepage https://github.com/AlorelUserscripts/google-timer-title-switcher
// @supportURL https://github.com/AlorelUserscripts/google-timer-title-switcher/issues
// @description Automatically updates the title when using Google's timer
// @include https://*google.*/search?*
// @version 1.1
// @icon https://cdn.rawgit.com/AlorelUserscripts/google-timer-title-switcher/master/icon.png
// @run-at document-start
// @grant unsafeWindow
// @require https://cdn.rawgit.com/turuslan/HackTimer/master/HackTimer.silent.min.js
// @updateURL https://raw.githubusercontent.com/AlorelUserscripts/google-timer-title-switcher/master/google-timer-title.meta.js
// @downloadURL https://raw.githubusercontent.com/AlorelUserscripts/google-timer-title-switcher/master/google-timer-title.user.js
// ==/UserScript==
unsafeWindow.setTimeout = setTimeout;
unsafeWindow.setInterval = setInterval;
document.addEventListener('DOMContentLoaded', ()=>{
const container = document.querySelector("#act-timer-section>div");
if (container) {
const timerArea = container.querySelector("div");
try {
document.head.querySelector('link[rel="shortcut icon"]').setAttribute("href", GM_info.script.icon);
} catch (e) {
}
for (let selector of [".srg", "#searchform", "#extrares", "#top_nav", "#navcnt", "#appbar"]) {
setTimeout(() => {
const el = document.querySelector(selector);
el.parentNode.removeChild(el);
}, 0);
}
const mo = new MutationObserver(() => {
if (container.classList.contains("act-tim-paused")) {
document.title = "PAUSED";
} else if (container.classList.contains("act-tim-finished")) {
document.title = "FINISHED";
} else {
document.title = timerArea.innerText.trim();
}
});
mo.observe(timerArea, {
childList: true,
attributes: true,
characterData: true,
subtree: true
});
}
}, {once: true});