-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
39 lines (31 loc) · 1.3 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
document.addEventListener("DOMContentLoaded", () => {
const checkbox = document.getElementById("toggle-input");
const toggleContainer = document.querySelector(".toggle-container");
const body = document.body;
function updateTextSelection(enabled) {
if (enabled) {
body.classList.add("selectable");
chrome.action.setIcon({ path: "images/icon-48.png" });
} else {
body.classList.remove("selectable");
chrome.action.setIcon({ path: "images/icon-48-disabled.png" });
}
}
toggleContainer.classList.add("no-transition");
chrome.storage.sync.get("userSelectEnabled", (data) => {
const enabled = data.userSelectEnabled !== false; // Default to enabled
checkbox.checked = enabled;
updateTextSelection(enabled);
setTimeout(() => {
toggleContainer.classList.remove("no-transition");
}, 200);
});
checkbox.addEventListener("change", (event) => {
const enabled = event.target.checked;
chrome.storage.sync.set({ userSelectEnabled: enabled });
updateTextSelection(enabled);
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { userSelectEnabled: enabled });
});
});
});