-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
43 lines (37 loc) · 1.28 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
let isXReplacementActive = true;
chrome.storage.local.get("isReplacementEnabled", (result) => {
isXReplacementActive =
result.isReplacementEnabled !== undefined
? result.isReplacementEnabled
: true;
updateButtonText();
updateReplacementStatus(isXReplacementActive);
});
const svgContainer = document.querySelector(".icon-container");
function updateReplacementStatus(isEnabled) {
if (isEnabled) {
svgContainer.classList.add("enabled");
document.getElementById("toggleButton").classList.add("active");
} else {
svgContainer.classList.remove("enabled");
document.getElementById("toggleButton").classList.remove("active");
}
}
function updateButtonText() {
const buttonText = isXReplacementActive
? "Replacement Enabled"
: "Replacement Disabled";
document.getElementById("toggleButtonText").textContent = buttonText;
}
document.getElementById("toggleButton").addEventListener("click", () => {
isXReplacementActive = !isXReplacementActive;
updateButtonText();
updateReplacementStatus(isXReplacementActive);
chrome.storage.local.set({ isReplacementEnabled: isXReplacementActive });
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
action: "toggleReplacement",
enabled: isXReplacementActive,
});
});
});