-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
70 lines (57 loc) · 1.59 KB
/
popup.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
let categories = {};
const boxes = document.querySelectorAll('.box');
setup()
function setup()
{
chrome.storage.sync.get(['data'], function(items){
try{
categories = JSON.parse(items.data);
boxes.forEach(box =>{
box.checked = categories[box.id]
})
}
catch{
console.log("no storage exist");
}
});
boxes.forEach(box => {
categories[box.id] = true;
box.addEventListener('change', function(event){
categories[event.target.id] = box.checked;
})
})
const submit = document.querySelector('#submit1');
submit.addEventListener('click',SendData)
const reset = document.querySelector('#reset');
reset.addEventListener('click',()=>{ResetSetAll(false)})
const selectAll = document.querySelector('#selectAll');
selectAll.addEventListener('click',()=>{ResetSetAll(true)})
function ResetSetAll(check)
{
for (var key in categories)
{
categories[key] = check;
}
boxes.forEach(box =>{
box.checked = check
})
}
function SendData()
{
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, categories)
.then(response =>{
console.log(response.response);
}).catch(console.log("some error"));
}
);
}
}
function onSetURL() {
console.log("set uninstall URL");
}
function onError(error) {
console.log(`Error: ${error}`);
}
let settingUrl = chrome.runtime.setUninstallURL("https://www.google.com");
settingUrl.then(onSetURL, onError);