-
Notifications
You must be signed in to change notification settings - Fork 1
/
popup.js
72 lines (58 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
71
72
// chrome.storage.local.set({
// 'myKarma': myKarma
// }, function() {
// // Notify that we saved.
// console.log('Settings saved myKarma', myKarma);
// });
var parameters = [];
chrome.storage.sync.get('parameters', function(result) {
console.log("get parameters", result);
if (result.parameters) {
parameters = result.parameters;
$.each(parameters, function(index, param) {
$('#'+param).prop('checked', true);
});
}
});
console.log(parameters);
function Setchange(target) {
paramsSelect = {
currentWindow: true,
active: true
};
console.log(target);
chrome.tabs.query(paramsSelect, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, {
"toggle": target
});
}
});
}
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("vote").onclick = function(target) {
Setchange("vote");
setParameters("vote");
};
document.getElementById("whisper").onclick = function(target) {
Setchange("whisper");
setParameters("whisper");
};
document.getElementById("report").onclick = function(target) {
Setchange("report");
setParameters("report");
};
});
function setParameters(action) {
if(parameters.indexOf(action) >= 0) {
parameters.splice(parameters.indexOf(action), 1);
} else {
parameters.push(action)
}
chrome.storage.sync.set({
'parameters': parameters
}, function() {
// Notify that we saved.
console.log('Settings saved parameters', parameters);
});
}