-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
44 lines (37 loc) · 1.77 KB
/
popup.js
File metadata and controls
44 lines (37 loc) · 1.77 KB
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
document.addEventListener('DOMContentLoaded', () => {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
// Check OS for warning banner
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
if (!isIOS) {
document.getElementById('os-warning').style.display = 'block';
}
// Load initial state with Twitch support added
chrome.storage.sync.get(['appLinkSettings'], (data) => {
const settings = data.appLinkSettings || { spotify: 'off', youtube: 'off', ytmusic: 'off', twitch: 'off' };
checkboxes.forEach(box => {
const service = box.dataset.service;
const mode = box.dataset.mode;
box.checked = (settings[service] === mode);
});
});
// Handle toggle logic
checkboxes.forEach(box => {
box.addEventListener('change', (e) => {
const service = e.target.dataset.service;
const mode = e.target.dataset.mode;
const isChecked = e.target.checked;
chrome.storage.sync.get(['appLinkSettings'], (data) => {
let settings = data.appLinkSettings || { spotify: 'off', youtube: 'off', ytmusic: 'off', twitch: 'off' };
if (isChecked) {
settings[service] = mode;
const otherMode = mode === 'app' ? 'livecontainer' : 'app';
const otherBoxId = (otherMode === 'app' ? 'app_' : 'lc_') + service;
document.getElementById(otherBoxId).checked = false;
} else {
settings[service] = 'off';
}
chrome.storage.sync.set({ appLinkSettings: settings });
});
});
});
});