-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·135 lines (105 loc) · 3.07 KB
/
script.js
File metadata and controls
executable file
·135 lines (105 loc) · 3.07 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//global section
var storage = chrome.storage.local;
var contentId = '#description-val'
var issue_numb_points = $(contentId + ' li').size();
var need_red_color = false;
window.addEventListener('load', function() {
var contentBody = document.getElementById('description-val');
contentBody.classList.remove('inactive');
contentBody.removeAttribute('title')
}, false);
function main() {
chrome.storage.local.get('red_color', function(items){
need_red_color = items.red_color;
});
$(contentId + ' li').prepend(function(n){
return "<input class='mCheckbox' type=\"checkbox\" id=\"" + n + "\"/>";
});
storage.get(null, function (items) {
showResults(0);
for (var i = 0; i < issue_numb_points; i++) {
var key = window.location.pathname.split('/')[2] + "=" + i;
var id = "#" + i;
if(items[key] == 1) {
$(id).attr('checked', true);
upCount();
} else {
$(id).attr('checked', false);
}
setClass($(contentId + " li:eq(" + i + ")").find('input'));
}
});
for (var i = 0; i < issue_numb_points; i++) {
var id = "#" + i;
$(id).on('click', function() {
var obj = {};
var key = window.location.pathname.split('/')[2];
var current_id = $(this).attr('id');
key = key + "=" + current_id;
var value = ($("#" + current_id).is(':checked') ? 1 : 0);
if(value == 1) {
var inputs = $(this.parentNode).find('input');
var counts = 1;
for (var j = 0; j < inputs.length; j++) {
var _id = inputs[j].id;
key = window.location.pathname.split('/')[2] + "=" + _id;
obj[key] = true;
counts += inputs[j].checked ? 0 : 1;
}
inputs.attr('checked', true);
upCount(counts);
} else {
obj[key] = value;
downCount();
}
var inputs = $(this.parentNode).find('input');
setClass(inputs);
storage.set(obj);
});
}
}
function showResults(done_items) {
var rez_text = "<div id='results'>Done Items / All Items: " +
"<div id='done_items_count'>" +
done_items +
"</div>" + " / " +
issue_numb_points +
"</div>";
$(contentId).append(rez_text);
}
function upCount(up) {
up = (typeof(up) !== 'undefined' ? up : 1);
var items = parseInt($('#done_items_count').text());
if (items == (issue_numb_points - up)) {
$('#results').text("All Done... Should work... Ohohohoho");
} else {
$('#done_items_count').text(items + up);
}
}
function downCount() {
var items = parseInt($('#done_items_count').text());
if (!items) {
$("#results").remove();
showResults(issue_numb_points - 1);
} else {
$('#done_items_count').text(items - 1);
}
}
function setClass(elements) {
for (var i = 0; i < elements.length; i++) {
var _id = elements[i].id;
var parent = $("#" + _id)[0].parentNode;
if(elements[i].checked) {
parent.classList.remove('unchecked');
parent.classList.remove('red_color');
parent.classList.add('checked');
} else {
parent.classList.remove('checked');
parent.classList.add('unchecked');
if (need_red_color) {
parent.classList.add('red_color');
}
}
}
}
main();