-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.js
104 lines (95 loc) · 3.61 KB
/
core.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
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
var style = document.createElement('link');
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = chrome.extension.getURL('core.css');
(document.head||document.documentElement).appendChild(style);
var divelement =$('<div class="contextMenu" id="topcoder_menu"><ul><li id="mark"> Mark as done !</li><li id="markascouldnotdo"> Mark as not done !</li><li id="unmark"> Unmark</li></ul></div>');
$(document.body).append(divelement);
//////////////////////////////////////////////////////////////////////////////////////////////////////
var problemsTable = $($("table")[6]);
var trs = problemsTable.find("tr").addClass("topcoder_question");
for(var i=0;i<trs.length;i++){
try{
var as = $(trs[i]).find("td>a");
var key = $(as[0]).text().trim()+$(as[1]).text().trim();
chrome.storage.sync.get(key, function(obj){
var key = Object.keys(obj)[0];
var marked = obj[key];
//console.log("On page load", key, marked);
if(marked){
var classToBeApplied = "";
if(marked==1){
classToBeApplied = "question_done";
}
else if(marked==2){
classToBeApplied = "question_couldnotbedone";
}
var problemsTable = $($("table")[6]);
var trs = problemsTable.find("tr").addClass("topcoder_question");
for(var i=0;i<trs.length;i++){
var as = $(trs[i]).find("td>a");
var k = $(as[0]).text().trim()+$(as[1]).text().trim();
if(k==key){
$(trs[i]).addClass(classToBeApplied);
break;
}
}
}
});
}
catch(e){
}
}
$('.topcoder_question').contextMenu('topcoder_menu', {
bindings: {
'mark': function(t) {
try{
var ele = $(t);
var as = ele.find("td>a");
var key = $(as[0]).text().trim()+$(as[1]).text().trim();
obj = {}
obj[key] = 1;
chrome.storage.sync.set(obj, function(obj){});
$(ele).addClass("question_done");
}
catch(e){
console.log("Failed to mark!");
}
},
'markascouldnotdo':function(t){
try{
var ele = $(t);
var as = ele.find("td>a");
var key = $(as[0]).text().trim()+$(as[1]).text().trim();
obj = {}
obj[key] = 2;
chrome.storage.sync.set(obj, function(obj){});
$(ele).addClass("question_couldnotbedone");
}
catch(e){
console.log("Failed to mark!");
}
},
'unmark': function(t) {
try{
var ele = $(t);
var as = ele.find("td>a");
var key = $(as[0]).text().trim()+$(as[1]).text().trim();
obj = {}
obj[key] = 0;
chrome.storage.sync.set(obj, function(obj){});
$(ele).removeClass("question_done").removeClass("question_couldnotbedone");
}
catch(e){
console.log("Failed to unmark!");
}
}
}
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
$("tr").css({'background-color':'green'});
console.log(sender.tab ?"from a content script:" + sender.tab.url :"from the zxczxccc");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});