-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
50 lines (44 loc) · 1.55 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
47
48
49
50
document.addEventListener('DOMContentLoaded', function(){
var input = document.getElementById('clean-option');
var ban_value = document.getElementById('ban_this_shit').value;
var btn = document.getElementById('myBtn');
var clearone = document.getElementById('clearone');
var clearall = document.getElementById('clearall');
// // set the initial state of the checkbox
// chrome.storage.sync.get('banValue', function (data) {
// console.log(data);
// });
chrome.storage.sync.get("clean_news_feed", function(data){
if (data["clean_news_feed"]){
input.checked = true;
} else {
input.checked = false;
}
});
btn.addEventListener("click", function(){
ban_value = document.getElementById('ban_this_shit').value;
chrome.storage.sync.get({banValue: []}, function (data) {
let banValue = data.banValue;
banValue.push(ban_value);
chrome.storage.sync.set({clean_news_feed: input.checked, banValue: banValue}, function () {
chrome.storage.sync.get('banValue', function (data) {
console.log(data);
})
});
});
});
clearone.addEventListener("click", function () {
clear_value = document.getElementById('ban_this_shit').value;
chrome.storage.sync.get('banValue', function (data) {
let newArr = data.banValue.filter(a => a!=clear_value);
console.log(newArr);
chrome.storage.sync.set({banValue: newArr});
});
});
clearall.addEventListener("click", function () {
chrome.storage.sync.set({banValue: []});
});
input.addEventListener("change", function(){
chrome.storage.sync.set({clean_news_feed: input.checked});
});
});