-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
45 lines (38 loc) · 1.66 KB
/
options.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
document.getElementById('tab-basic').addEventListener('click', () => {
showTab('basic');
});
document.getElementById('tab-options').addEventListener('click', () => {
showTab('options');
});
function showTab(tab) {
document.querySelectorAll('.tab-button').forEach((button) => {
button.classList.remove('active');
});
document.querySelectorAll('.tab-content').forEach((content) => {
content.style.display = 'none';
});
document.getElementById(`tab-${tab}`).classList.add('active');
document.getElementById(`content-${tab}`).style.display = 'block';
}
if (typeof chrome !== 'undefined' && chrome.storage) {
chrome.storage.sync.get(['notificationsEnabled', 'mode'], (result) => {
const notificationsEnabled = result.notificationsEnabled !== undefined ? result.notificationsEnabled : true;
const mode = result.mode || 'link-button';
document.getElementById('notification-switch').checked = notificationsEnabled;
document.getElementById(`enable-${mode}`).checked = true;
if (!result.mode) {
chrome.storage.sync.set({ mode: 'link-button' });
}
});
document.getElementById('notification-switch').addEventListener('change', (event) => {
chrome.storage.sync.set({ notificationsEnabled: event.target.checked });
});
document.querySelectorAll('input[name="mode"]').forEach((radio) => {
radio.addEventListener('change', (event) => {
const selectedMode = event.target.id.replace('enable-', '');
chrome.storage.sync.set({ mode: selectedMode });
});
});
} else {
console.error('chrome.storage.sync is not available.');
}