-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
39 lines (35 loc) · 1.47 KB
/
options.js
File metadata and controls
39 lines (35 loc) · 1.47 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
// Default settings
const DEFAULT_MIRROR_URL = "https://freedium-mirror.cfd/";
const DEFAULT_OPEN_BEHAVIOR = "current_tab";
const DEFAULT_BUTTON_POSITION = "bottom_center";
// Saves options to chrome.storage
const saveOptions = () => {
const mirrorUrl = document.getElementById('mirrorUrl').value;
const openBehavior = document.getElementById('openBehavior').value;
const buttonPosition = document.getElementById('buttonPosition').value;
chrome.storage.sync.set(
{ bypassMirrorUrl: mirrorUrl, openBehavior: openBehavior, buttonPosition: buttonPosition },
() => {
// Update status to let user know options were saved.
const status = document.getElementById('status');
status.textContent = 'Settings saved.';
setTimeout(() => {
status.textContent = '';
}, 2000);
}
);
};
// Restores select box and text field state using the preferences
// stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{ bypassMirrorUrl: DEFAULT_MIRROR_URL, openBehavior: DEFAULT_OPEN_BEHAVIOR, buttonPosition: DEFAULT_BUTTON_POSITION },
(items) => {
document.getElementById('mirrorUrl').value = items.bypassMirrorUrl;
document.getElementById('openBehavior').value = items.openBehavior;
document.getElementById('buttonPosition').value = items.buttonPosition;
}
);
};
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('saveBtn').addEventListener('click', saveOptions);