forked from kallepersson/inboxtheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathin.js
89 lines (78 loc) · 2.34 KB
/
in.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const _styleElement = document.createElement("style");
_styleElement.innerText = _css;
const init = (evt) => {
document.head.appendChild(_styleElement);
setupNodes();
initMenu();
updateTitle();
document.body.classList.toggle("_in");
}
const updateTitle = () => {
const observer = new MutationObserver(() => {
const { title } = _nodes;
let linkElements = document.querySelectorAll(".aim a");
if (title && linkElements.length > 0) {
handleHashChange();
observer.disconnect();
}
});
observer.observe(document.body, {subtree:true, childList:true});
}
const handleHashChange = (evt) => {
let hash = window.location.hash;
document.body.dataset.hash = hash;
const { title } = _nodes;
let linkElement = document.querySelector(`.aim a[href$="${hash}"]`);
if (!title || !linkElement) {
return;
}
title.innerHTML = '';
title.style = 'text-decoration: none;';
titleSpan = document.createElement("span");
titleSpan.classList.add("_inTitle");
title.appendChild(titleSpan);
titleSpan.innerText = linkElement.innerText;
title.href = linkElement.href;
setupSweepButtons();
}
const setupSweepButtons = () => {
let sections = document.querySelectorAll(".ae4");
sections.forEach((section) => {
let sweepButton = section.querySelector("._inSweep");
let buttonContainer = section.querySelector(".Cr");
if (buttonContainer && !sweepButton) {
sweepButton = document.createElement("button");
sweepButton.classList.add("_inSweep");
sweepButton.addEventListener("click", handleSweepButtonClick);
buttonContainer.insertBefore(sweepButton, buttonContainer.firstChild);
}
})
}
/**
*/
const getMessageRowIsStarred = (elm) => {
const starredButton = elm.querySelector(".T-KT");
return starredButton && starredButton.classList.contains("T-KT-Jp");
}
/**
*/
const archiveMessageRow = (elm) => {
const archiveButton = elm.querySelector(".brq");
if (archiveButton) {
archiveButton.click();
}
}
const handleSweepButtonClick = (evt) => {
let section = queryParentSelector(evt.target, ".aDM");
section.querySelectorAll("tr").forEach((elm) => {
if (!getMessageRowIsStarred(elm)) {
archiveMessageRow(elm);
}
})
}
window.addEventListener("hashchange", handleHashChange);
if (document.head) {
init();
} else {
document.addEventListener("DOMContentLoaded", init);
}