-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.js
103 lines (89 loc) · 3.17 KB
/
options.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
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
'use strict';
var sliderKeys = ['includePlaylists', 'clearSitesAtLoop', 'toggleAutoplayClearsSites'];
function loadSettings() {
setSliders();
setInputs();
}
function setSliders() {
sliderKeys.forEach(key => {
chrome.storage.local.get([key],
function(data) {
document.getElementById(key).checked = data[key];
}
);
});
}
function setInputs() {
['backgroundRedirectEntry', 'minimumVideoLength', 'maximumVideoLength', 'toggleCheckInterval', 'videoRecommendationsInterval', 'videoEndInterval'].forEach(key => {
chrome.storage.local.get([key],
function(data) {
document.getElementById(key).value = data[key];
}
);
});
setFilterlistEntries();
}
function setFilterlistEntries() {
let filterlistKeys = ['blacklist', 'whitelist'];
filterlistKeys.forEach(key => {
chrome.storage.local.get([key],
function(data) {
document.getElementById(key).value = data[key].join("\n");
}
);
});
}
function evaluateSliders() {
sliderKeys.forEach(key => {
chrome.storage.local.set({[key]: document.getElementById(key).checked});
});
}
function evaluateInputs() {
['backgroundRedirectEntry', 'minimumVideoLength', 'maximumVideoLength', 'toggleCheckInterval', 'videoRecommendationsInterval', 'videoEndInterval'].forEach(key => {
if (document.getElementById(key).value && !isNaN(document.getElementById(key).value)) {
chrome.storage.local.set({[key]: document.getElementById(key).value});
}
});
evaluateFilterlistEntries();
}
function evaluateFilterlistEntries() {
let filterlistKeys = ['blacklist', 'whitelist'];
filterlistKeys.forEach(filterlistKey => {
let filterlistValue = document.getElementById(filterlistKey).value;
if (filterlistValue) {
var filterlistLines = filterlistValue.split('\n');
let isValid = true;
filterlistLines.forEach(line => {
if (!line.startsWith("https://www.youtube.com/watch?")) {
isValid = false;
}
});
if (isValid) {
chrome.storage.local.set({[filterlistKey]: filterlistLines});
if (filterlistKey === 'blacklist') {
chrome.storage.local.get('urlHistory', function (result) {
filterlistLines.forEach(url => result.urlHistory.push(url));
chrome.storage.local.set({'urlHistory': result.urlHistory});
});
}
}
}
});
}
function submit() {
evaluateSliders();
evaluateInputs();
}
function reset() {
chrome.extension.getBackgroundPage().setupVariables();
setInputs();
}
window.addEventListener('load', function load(event) {
var submitButton = document.getElementById('submitButton');
submitButton.addEventListener('click', function() { submit(); });
});
window.addEventListener('load', function load(event) {
var resetButton = document.getElementById('resetButton');
resetButton.addEventListener('click', function() { reset(); });
});
loadSettings();