-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
42 lines (36 loc) · 1.07 KB
/
content.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
let focusElement = null;
function hideSiblingsAndAncestors(element) {
// hide everything except the element and its ancestors
// make the elements visibility hidden
$(element).parentsUntil("body").siblings().css("visibility", "hidden");
}
function showSiblingsAndAncestors(element) {
// show everything except the element and its ancestors
// make the elements visibility visible
$(element).parentsUntil("body").siblings().css("visibility", "visible");
}
function toggleFocus(element) {
if (focusElement) {
focusElement = null;
showSiblingsAndAncestors(element);
return;
}
hideSiblingsAndAncestors(element);
focusElement = element;
}
document.addEventListener("click", (event) => {
let targetElement = event.target;
while (
targetElement &&
targetElement.nodeName !== "DIV" &&
targetElement.nodeName !== "SPAN"
) {
targetElement = targetElement.parentNode;
}
chrome.storage.sync.get("focusMode", function (data) {
const isFocusModeOn = data.focusMode;
if (isFocusModeOn) {
toggleFocus(targetElement);
}
});
});