-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.js
79 lines (59 loc) · 3.11 KB
/
problem.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
73
74
75
76
77
78
79
$('thead tr').prepend($('<td>纳入统计<input id="problemall" type="checkbox" /></td>'));
let checkboxTd = $('<td><input class="problemcheck" type="checkbox" /></td>');
$('tbody tr').prepend(checkboxTd);
let currentCId = $('tbody .problem-id:first').children().prop('href').match(/[0-9]+/);
chrome.storage.sync.get('problems', function(data) {
data.problems.forEach(function(problem) {
if (problem.chapterId == currentCId) {
$('.problem-id:contains(' + problem.problemId + ')').siblings(':first').children().prop('checked', true);
}
});
if ($('.problemcheck:checked').length == $('.problemcheck').length)
$('#problemall').prop('checked', true);
});
$('#problemall').change(function () {
if ($(this).prop('checked')) {
let problems = []
$('.problemcheck').each(function() {
let chapterId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/g)[0];
let problemId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/g)[1];
let problemName = $(this).parent().siblings('.title').text();
let problem = {chapterId: chapterId, problemId: problemId, problemName: problemName};
if (!$(this).prop('checked')) {
problems.push(problem);
$(this).prop('checked', true);
}
});
chrome.runtime.sendMessage({operation: 'add_problem', problems: problems}, undefined);
}
else {
let problems = []
$('.problemcheck').each(function() {
let chapterId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/)[0];
let problemId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/g)[1];
let problemName = $(this).parent().siblings('.title').text();
let problem = {chapterId: chapterId, problemId: problemId, problemName: problemName};
if ($(this).prop('checked')) {
problems.push(problem);
$(this).prop('checked', false);
}
});
chrome.runtime.sendMessage({operation: 'del_problem', problems: problems}, undefined);
}
});
$('.problemcheck').change(function() {
let chapterId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/g)[0];
let problemId = $(this).parent().siblings('.problem-id').children().prop('href').match(/[0-9]+/g)[1];
let problemName = $(this).parent().siblings('.title').text();
let problem = {chapterId: chapterId, problemId: problemId, problemName: problemName};
if ($(this).prop('checked')) {
chrome.runtime.sendMessage({operation: 'add_problem', problems: [problem]}, undefined);
if ($('.problemcheck:checked').length == $('.problemcheck').length)
$('#problemall').prop('checked', true);
}
else {
chrome.runtime.sendMessage({operation: 'del_problem', problems: [problem]}, undefined);
if ($('.problemcheck:checked').length != $('.problemcheck').length)
$('#problemall').prop('checked', false);
}
});