-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
46 lines (40 loc) · 1.8 KB
/
settings.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
document.addEventListener('DOMContentLoaded', function () {
const sidebarWidthInput = document.getElementById('sidebarWidth');
const sidebarBgColorInput = document.getElementById('sidebarBgColor');
// Load the current settings and update the input fields
chrome.storage.local.get(['sidebarWidth', 'sidebarBgColor'], function (result) {
sidebarWidthInput.value = result.sidebarWidth || 500;
sidebarBgColorInput.value = result.sidebarBgColor || '#f1f1f1';
});
sidebarWidthInput.addEventListener('input', function () {
const width = sidebarWidthInput.value;
chrome.storage.local.set({ sidebarWidth: width }, function () {
applySettings();
});
});
sidebarBgColorInput.addEventListener('input', function () {
const color = sidebarBgColorInput.value;
chrome.storage.local.set({ sidebarBgColor: color }, function () {
applySettings();
});
});
function applySettings() {
chrome.storage.local.get(['sidebarWidth', 'sidebarBgColor'], function (result) {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(tab => {
chrome.scripting.executeScript({
target: { tabId: tab.id },
func: (width, color) => {
const sidebar = document.getElementById('persistent-sidebar');
if (sidebar) {
sidebar.style.width = width + 'px';
sidebar.style.backgroundColor = color;
}
},
args: [result.sidebarWidth || 500, result.sidebarBgColor || '#f1f1f1']
});
});
});
});
}
});