-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
121 lines (112 loc) · 5.78 KB
/
popup.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const optionsSelectors = document.querySelectorAll(".options-selector");
chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
});
optionsSelectors.forEach(el => {
const button = el;
const toggleDot = button.querySelector("span")
if (button.name === "hide-feed") {
chrome.storage.local.get("feed", function(data) {
if (data.feed === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-notifications") {
chrome.storage.local.get("notifications", function(data) {
if (data.notifications === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-side-panel") {
chrome.storage.local.get("sidePanel", function (data) {
if (data.sidePanel === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-tags") {
chrome.storage.local.get("tags", function (data) {
if (data.tags === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-recommended_videos") {
chrome.storage.local.get("recommended_videos", function (data) {
if (data.recommended_videos === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-comments") {
chrome.storage.local.get("comments", function (data) {
if (data.comments === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
} else if (button.name === "hide-description") {
chrome.storage.local.get("description", function (data) {
if (data.description === true) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5")
toggleDot.ariaHidden = "true"
}
})
}
button.addEventListener("click", function () {
chrome.tabs.query({active: true, currentWindow: true}, function (tabs) {
button.classList.toggle("bg-secondary")
toggleDot.classList.toggle("translate-x-5");
toggleDot.ariaHidden = toggleDot.ariaHidden === "true" ? "false" : "true"
// Save the state to storage
// chrome.storage.local.set({ [button.name]: toggleDot.ariaHidden === "true" });
// Send a message to the content script to update the UI
// chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
// chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
if (button.name === "hide-notifications") {
chrome.storage.local.set({ notifications: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-feed") {
chrome.storage.local.set({ feed: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-side-panel") {
chrome.storage.local.set({ sidePanel: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-tags") {
chrome.storage.local.set({ tags: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-recommended_videos") {
chrome.storage.local.set({ recommended_videos: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-comments") {
chrome.storage.local.set({ comments: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
else if (button.name === "hide-description") {
chrome.storage.local.set({ description: toggleDot.ariaHidden === "true" });
chrome.tabs.sendMessage(tabs[0].id, { message: button.name });
chrome.tabs.sendMessage(tabs[0].id, { message: "runContentScript" });
}
})
})
})