-
Notifications
You must be signed in to change notification settings - Fork 5
/
handler.js
49 lines (45 loc) · 1.48 KB
/
handler.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
var DEBUG=true;
(function()
{
var url=window.location.href;
if(/http:\/\/www.codechef.com\/[^\/]*\/problems\/.*/.test(url)
|| /http:\/\/www.codechef.com\/problems\/.*/.test(url))
{
var buttons = $(".button-list");
var title= $("table.pagetitle-prob").find("td").eq(0).find("h1").text();
var id=$("table.pagetitle-prob").find("td").eq(0).find("p").text().split(" ")[2];
add = "<li > <a href='#' title='" + title + "' id='" + id + "' hreff='" + url.replace('#','') + "' class='codeLater toDoAllowed' >CodeLater</a></li>"
$("table.pagetitle-prob").find("td").eq(0).attr("width", "40%");
buttons.append(add);
//check if prob already added. if yes, then strike the CodeLater button.
chrome.storage.sync.get( null, function (items)
{
for(k in items)
{
if(items[k]['href'].replace('#','')===url.replace('#',''))
{
var info=$(".button-list").find("li").find("a.codeLater");
info.css("text-decoration","line-through");
info.removeClass("toDoAllowed");
return;
}
}
});
$(document).on("click", ".codeLater", function(event)
{
var info=$(".button-list").find("li").find("a.codeLater");
if (info.hasClass("toDoAllowed"))
{
var obj={};
var items={};
items['id']=info.attr('id');
items['title']=info.attr('title');
items['href']=info.attr('hreff');
obj[items['href']]=items;
info.css("text-decoration","line-through");
info.removeClass("toDoAllowed");
chrome.storage.sync.set(obj);
};
});
}
})();