-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostMan.js
151 lines (74 loc) · 2.86 KB
/
PostMan.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 links = document.getElementsByTagName("a");
var arr = [];
for (var i = 0; i < links.length; i++) {
arr.push(links[i].href.split("/"));
}
var handle;
var problemNo;
var problemType;
for (var i = 0; i < arr.length; i++) {
if (arr[i][2] === "codeforces.com" && arr[i][3] === "profile") {
handle = arr[i][4];
localStorage.setItem("HANDLE", handle);
}
}
let SecondLevelMenu = document.getElementsByClassName("second-level-menu-list");
let ACTIVE = localStorage.getItem("CURRENT_ACTIVE_PROBLEM");
INSERT()
function INSERT() {
if (ACTIVE) {
let html = `
<span class = "ContainerTimer">
${ACTIVE} <span id = "SignAdd">➕</span> <span id = "SignCancel">❌</span>
</span>
`
let Parent = SecondLevelMenu[0];
let ChildrenCnt = Parent.children.length;
Parent.children[ChildrenCnt - 1].insertAdjacentHTML("afterEnd", html);
let Add = document.getElementById("SignAdd");
let Cancel = document.getElementById("SignCancel");
if (Add) {
Add.addEventListener("click", () => {
let Payload = {
contestId: localStorage.getItem("PROBLEM_NO"),
type: localStorage.getItem("PROBLEM_TYPE"),
time: localStorage.getItem(localStorage.getItem("PROBLEM_NO") + localStorage.getItem("PROBLEM_TYPE")),
handle: handle,
startTime: localStorage.getItem(localStorage.getItem("PROBLEM_NO") + localStorage.getItem("PROBLEM_TYPE") + "StartTime")
}
chrome.runtime.sendMessage({ message: ["FetchPset", Payload] }, (response) => {
console.log(response)
if (response == 201) {
console.log("hi");
alert("Successfull");
localStorage.removeItem("CURRENT_ACTIVE_PROBLEM");
let firstKey = localStorage.getItem("PROBLEM_NO");
let secondKey = localStorage.getItem("PROBLEM_TYPE");
localStorage.removeItem(firstKey + secondKey);
localStorage.removeItem(firstKey + secondKey + "StartTime");
window.location.reload();
}
else if (response == 400) {
alert("Un-Authorized");
window.location.reload();
}
else {
alert(response);
window.location.reload();
}
})
})
}
if (Cancel) {
Cancel.addEventListener("click", () => {
alert(`Deleted the information about ${localStorage.getItem("CURRENT_ACTIVE_PROBLEM")}`)
localStorage.removeItem("CURRENT_ACTIVE_PROBLEM");
let firstKey = localStorage.getItem("PROBLEM_NO");
let secondKey = localStorage.getItem("PROBLEM_TYPE");
localStorage.removeItem(firstKey + secondKey);
localStorage.removeItem(firstKey + secondKey + "StartTime");
window.location.reload();
})
}
}
}