-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
47 lines (40 loc) · 1.6 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
44
45
46
47
// popup.js
// Font selection logic
document.getElementById('font-select').addEventListener('change', function () {
const selectedFont = this.value;
chrome.storage.sync.set({ selectedFont }, () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: 'changeFont', font: selectedFont });
});
});
});
// Set font selector to saved font on popup load
chrome.storage.sync.get('selectedFont', ({ selectedFont }) => {
if (selectedFont) {
document.getElementById('font-select').value = selectedFont;
}
});
// Toggle shorts visibility
const toggleButton = document.getElementById('toggleButton');
const toggleIcon = document.getElementById('toggleIcon');
// Update icon based on storage state
function updateIcon(isEnabled) {
toggleIcon.src = isEnabled ? 'assets/off.svg' : 'assets/on.svg';
}
// Set initial state on popup load
chrome.storage.sync.get('shortsHidden', ({ shortsHidden }) => {
updateIcon(shortsHidden);
});
// Handle toggle click to update state and icon
toggleButton.addEventListener('click', () => {
chrome.storage.sync.get('shortsHidden', ({ shortsHidden }) => {
const newState = !shortsHidden;
chrome.storage.sync.set({ shortsHidden: newState }, () => {
updateIcon(newState);
// Send message to toggle shorts visibility
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, { action: newState ? 'hideShorts' : 'showShorts' });
});
});
});
});