-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
25 lines (22 loc) · 869 Bytes
/
popup.js
File metadata and controls
25 lines (22 loc) · 869 Bytes
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
document.addEventListener('DOMContentLoaded', () => {
const toggle = document.getElementById('toggle');
const settingsLink = document.getElementById('settings');
// Load initial state
chrome.storage.sync.get(['isEnabled'], (result) => {
toggle.checked = result.isEnabled !== undefined ? result.isEnabled : true;
});
// Handle toggle
toggle.addEventListener('change', () => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {action: "toggle"}, (response) => {
if (response) {
chrome.storage.sync.set({isEnabled: response.isEnabled});
}
});
});
});
// Handle settings link
settingsLink.addEventListener('click', () => {
chrome.runtime.openOptionsPage();
});
});