-
Notifications
You must be signed in to change notification settings - Fork 1
/
content.js
81 lines (77 loc) · 3.26 KB
/
content.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
function displayGIF(problem_verdict, problem_index) {
if (problem_verdict === "OK") {
if (problem_index.includes('A')) { document.getElementById("gif").src = chrome.extension.getURL("icons/A.gif"); }
else if (problem_index.includes('B') ) { document.getElementById("gif").src = chrome.extension.getURL("icons/B.gif"); }
else if (problem_index.includes('C' )) { document.getElementById("gif").src = chrome.extension.getURL("icons/C.gif"); }
else if (problem_index.includes('D' )) { document.getElementById("gif").src = chrome.extension.getURL("icons/D.gif"); }
else if (problem_index.includes('E' )) { document.getElementById("gif").src = chrome.extension.getURL("icons/E.gif"); }
else { document.getElementById("gif").src = chrome.extension.getURL("icons/god.gif") } // Intended for F and above problems
document.getElementById("result").style.color = "green";
} else {
document.getElementById("gif").src = chrome.extension.getURL("icons/WA.gif");
document.getElementById("result").style.color = "red";
}
}
function publish(verdict, problem_name, problem_index) {
if (document.getElementsByClassName("resultgif").length != 0) {
document.getElementById("result").innerHTML = "Verdict : " + verdict;
document.getElementById("problem_name").innerHTML =
"Problem : " + problem_name;
} else {
const div = document.createElement("div");
div.className = "resultgif";
div.insertAdjacentHTML(
"afterbegin",
`
<style>
.resultgif {
position:fixed;
bottom:0px ;
width:279px;
align-items:center;
}
.resultgif .sidebox {
margin-bottom:0px;
}
.resultgif .CenterThis {
display: block;
margin-left: auto;
margin-right: auto;
width:75%;
}
.resultgif #close {
color:red;
float: right;
cursor: pointer;
font-size: 1.25em;
vertical-align: middle;
margin-right: 10px;
}
</style>
<div class="roundbox sidebox" style="">
<div class="roundbox-lt"> </div>
<div class="roundbox-rt"> </div>
<div class="caption titled">
→ Result of your last submission <span id='close' class='infobar-close' onclick='this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); return false;'>×</span>
</div>
<img class="CenterThis" id="gif" alt="GIF" height=150>
<strong><p id= "result" style="padding: 10px 0 2px 10px" >Verdict: </p></strong>
<p id="problem_name" style="padding:3px 0 10px 10px ">Problem: </p>
</div>
`
);
document.getElementById("sidebar").appendChild(div);
document.getElementById("result").innerHTML += verdict;
document.getElementById("problem_name").innerHTML += problem_name;
}
displayGIF(verdict, problem_index);
document.getElementById("close").addEventListener("click", function () {
chrome.runtime.sendMessage({ close: true }); //Sending message to popup.js to close all gifs
});
}
chrome.runtime.onMessage.addListener(publishGIF)
function publishGIF(message, sender, sendResponse) {
if (message.publish) {
publish(message.verdict, message.problem_name, message.problem_index);
}
}