-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
61 lines (55 loc) · 2.07 KB
/
content.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
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "saveAnswer") {
var nodes = document.querySelectorAll("div.form-group");
var infos = [];
for (var i = 0; i < nodes.length; i++) {
questionString = nodes[i].children[0].innerHTML;
question = questionString.slice(questionString.indexOf("."));
for (var j = 1; j < nodes[i].children.length; j++) {
if (nodes[i].children[j].children[1].checked) {
infos.push({
"question": question,
"answer": nodes[i].children[j].children[2].innerHTML
})
}
}
}
sendResponse({
infos: infos
})
}
})
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "searchAnswer") {
var nodes = document.querySelectorAll("div.form-group");
var infos = [];
for (var i = 0; i < nodes.length; i++) {
questionString = nodes[i].children[0].innerHTML
question = questionString.slice(questionString.indexOf("."));
infos.push({
"question": question,
})
}
sendResponse({
infos: infos
})
}
})
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "choose") {
var nodes = document.querySelectorAll("div.form-group");
var node = nodes[request.no];
for (var j = 1; j <node.children.length; j++) {
if (node.children[j].children[2].innerHTML === request.answer) {
node.children[j].children[1].checked = true;
}
}
}
})
chrome.extension.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "mark") {
var nodes = document.querySelectorAll("div.form-group");
var node = nodes[request.no];
node.style.color = "red";
}
})