-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.js
More file actions
115 lines (105 loc) · 4.32 KB
/
config.js
File metadata and controls
115 lines (105 loc) · 4.32 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const form = document.getElementById('config-form');
const apiSchemeInput = document.getElementById('apiScheme');
const apiHostInput = document.getElementById('apiHost');
const apiPortInput = document.getElementById('apiPort');
const apiUsernameInput = document.getElementById('apiUsername');
const apiPasswordInput = document.getElementById('apiPassword');
// Load saved credentials if they exist
browser.storage.local.get(['apiScheme', 'apiHost', 'apiPort', 'apiUsername', 'apiPassword']).then(data => {
if (data.apiScheme) {
apiSchemeInput.value = data.apiScheme;
}
if (data.apiHost) {
apiHostInput.value = data.apiHost;
}
if (data.apiPort) {
apiPortInput.value = data.apiPort;
}
if (data.apiUsername) {
apiUsernameInput.value = data.apiUsername;
}
if (data.apiPassword) {
apiPasswordInput.value = data.apiPassword;
}
});
// Handle form submission
const saveButton = document.getElementById('submit');
saveButton.addEventListener('click', (event) => {
event.preventDefault();
const apiScheme = apiSchemeInput.value;
const apiHost = apiHostInput.value;
const apiPort = apiPortInput.value;
const apiUsername = apiUsernameInput.value;
const apiPassword = apiPasswordInput.value;
// Save credentials to storage
browser.storage.local.set({
apiScheme: apiScheme,
apiHost: apiHost,
apiPort: apiPort,
apiUsername: apiUsername,
apiPassword: apiPassword,
}).then(() => {
const checkmark = document.getElementById('success-checkmark');
checkmark.style.display = 'inline';
setTimeout(() => {
checkmark.style.display = 'none';
}, 2000);
}).catch(err => {
console.error('Error saving credentials:', err);
const failurex = document.getElementById('failure-x');
failurex.style.display = 'inline';
setTimeout(() => {
failurex.style.display = 'none';
}, 2000);
});
});
// Dark mode
async function getDarkMode() {
const result = await browser.storage.local.get('darkMode');
const darkMode = result.darkMode || false;
return darkMode;
}
function enableDarkMode() {
document.body.classList.add("dark-mode-body");
document.getElementById('github').classList.remove("github-light");
document.getElementById('github').classList.add("github-dark");
document.getElementById('settings').classList.remove("settings-button-light");
document.getElementById('settings').classList.add("settings-button-dark");
const inputs = document.querySelectorAll('input');
inputs.forEach(input => input.classList.add("dark-mode-others"));
const buttons = document.querySelectorAll('button');
buttons.forEach(button => button.classList.add("dark-mode-others"));
const selects = document.querySelectorAll('select');
selects.forEach(select => select.classList.add("dark-mode-others"));
const labels = document.querySelectorAll('label');
labels.forEach(label => label.classList.add("dark-mode-body"));
}
function disableDarkMode() {
document.body.classList.remove("dark-mode-body");
document.getElementById('github').classList.remove("github-dark");
document.getElementById('github').classList.add("github-light");
document.getElementById('settings').classList.remove("settings-button-dark");
document.getElementById('settings').classList.add("settings-button-light");
const inputs = document.querySelectorAll('input');
inputs.forEach(input => input.classList.remove("dark-mode-others"));
const buttons = document.querySelectorAll('button');
buttons.forEach(button => button.classList.remove("dark-mode-others"));
const selects = document.querySelectorAll('select');
selects.forEach(select => select.classList.remove("dark-mode-others"));
const labels = document.querySelectorAll('label');
labels.forEach(label => label.classList.remove("dark-mode-body"));
}
async function initializeDarkMode() {
const darkMode = await getDarkMode();
if (darkMode) {
enableDarkMode();
} else {
disableDarkMode();
}
}
initializeDarkMode()
//Handle clicks on settings and open WebUI buttons
document.getElementById('openQbit').addEventListener('click', async () => {browser.runtime.sendMessage({ action: "openQbit" });});
document.getElementById('settings').addEventListener('click', () => {
window.location.href = 'settings.html';
});