-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.js
70 lines (61 loc) · 2.41 KB
/
interface.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
let watchedThresholdInput;
let ageThresholdInput;
let filterMixPlaylistsInput;
let settingsForm;
let settingsSavedMessageDiv;
const DEFAULT_WATCHED_THRESHOLD = 0;
const DEFAULT_AGE_THRESHOLD = 5;
const DEFAULT_FILTER_MIX_PLAYLISTS = true;
document.addEventListener('DOMContentLoaded', function() {
watchedThresholdInput = document.getElementById("watched-threshold");
ageThresholdInput = document.getElementById("age-threshold");
filterMixPlaylistsInput = document.getElementById("filter-mix-playlist");
settingsForm = document.getElementById("settings");
settingsSavedMessageDiv = document.getElementById("settings-saved-message");
// add event listener to handle saving settings
settingsForm.addEventListener('submit', onSettingsSave);
});
chrome.storage.sync.get("watchedThreshold", ({ watchedThreshold }) => {
// use default if none loaded
if (!watchedThreshold && watchedThresholdInput) {
watchedThresholdInput.value = DEFAULT_WATCHED_THRESHOLD
return;
}
// use provided value
if (watchedThresholdInput) {
watchedThresholdInput.value = watchedThreshold;
}
});
chrome.storage.sync.get("ageThreshold", ({ ageThreshold }) => {
// use default if none loaded
if (!ageThreshold && ageThresholdInput) {
ageThresholdInput.value = DEFAULT_AGE_THRESHOLD
return;
}
if (ageThresholdInput) {
ageThresholdInput.value = ageThreshold;
}
});
chrome.storage.sync.get("filterMixPlaylists", ({ filterMixPlaylists }) => {
// use default if none loaded
if (filterMixPlaylists === undefined && filterMixPlaylistsInput) {
filterMixPlaylistsInput.checked = DEFAULT_FILTER_MIX_PLAYLISTS
return;
}
if (filterMixPlaylistsInput) {
filterMixPlaylistsInput.checked = filterMixPlaylists;
}
});
function onSettingsSave (e) {
e.preventDefault();
const newWatchedThreshold = watchedThresholdInput.value;
const newAgeThreshold = ageThresholdInput.value;
const newFilterMixPlaylists = filterMixPlaylistsInput.checked;
console.log(`Saving ${newWatchedThreshold} watched threshold, ${newAgeThreshold} age threshold, ${newFilterMixPlaylists} filter mix playlists...`);
chrome.storage.sync.set({
watchedThreshold: newWatchedThreshold,
ageThreshold: newAgeThreshold,
filterMixPlaylists: newFilterMixPlaylists
});
settingsSavedMessageDiv.style.setProperty("display", "block");
}