-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
56 lines (53 loc) · 1.78 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
$(function () {
chrome.storage.sync.get(["noun", "verb", "adverb"], function (checklist) {
if (checklist.noun && checklist.verb && checklist.adverb) {
$("#check_all").prop("checked", true);
}
if (checklist.noun) {
$("#noun").prop("checked", true);
}
if (checklist.verb) {
$("#verb").prop("checked", true);
}
if (checklist.adverb) {
$("#adverb").prop("checked", true);
}
});
$("#check_all").click(function () {
if ($("#check_all").prop("checked")) {
$('input[name="checkList"]').prop("checked", true);
} else {
$('input[name="checkList"]').prop("checked", false);
}
});
$("input[name='checkList']").click(function () {
let checklist = $("input[name='checkList']:checked");
console.log(checklist);
if (checklist.length < 4) {
if (checklist.length == 3 && checklist[0].id == "noun" && checklist[1].id == "verb" && checklist[2].id == "adverb") {
$("#check_all").prop("checked", true);
} else {
$("#check_all").prop("checked", false);
}
}
});
$("#save").click(function () {
chrome.storage.sync.set({ noun: false, verb: false, adverb: false }, function () {
$("input[name='checkList']:checked").each(function () {
if ($(this).val() == "check_all") {
chrome.storage.sync.set({ noun: true, verb: true, adverb: true }, function () {});
} else {
if ($(this).val() == "noun") {
chrome.storage.sync.set({ noun: true }, function () {});
}
if ($(this).val() == "verb") {
chrome.storage.sync.set({ verb: true }, function () {});
}
if ($(this).val() == "adverb") {
chrome.storage.sync.set({ adverb: true }, function () {});
}
}
});
});
});
});