forked from RishiRaj22/coding_shout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatcoder.js
More file actions
52 lines (48 loc) · 1.95 KB
/
Copy pathatcoder.js
File metadata and controls
52 lines (48 loc) · 1.95 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
window.browser = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
var url = window.location.href;
var submissions = [].slice.call(document.getElementsByClassName("waiting-judge")).map(it => it.getAttribute("data-id"));
function fetch_atcoder_result(base_url, ids) {
var xhr = new XMLHttpRequest();
var url_param = [].slice.call(ids).map(it => "sids[]=" + it).join("&")
var ids_to_refresh = []
var url = base_url + "/status/json?" + url_param;
xhr.open("GET", url, true);
xhr.send();
xhr.onload = function(e) {
var result = JSON.parse(xhr.response);
ids.forEach(function(id) {
var obj = result[id];
if (obj["Html"].includes("waiting-judge")) {
/* On AtCoder, a solution can be marked as judging and WA,TLE,MLE,RE at the same time.
* This means that the solution is still being run on more testcases. When this happens,
* the running time, consumed memory and score is not yet available. Since AtCoder has
* partial scores, we do not report the verdict just yet. */
ids_to_refresh.push(id);
} else {
var score = obj["Score"];
var verdict = /title=\"([^\"]*)\"/g.exec(obj["Html"])[1];
var time = /[0-9]* ms/g.exec(obj["Html"]);
var mem = /[0-9]* KB/g.exec(obj["Html"]);
browser.runtime.sendMessage({
verdict: verdict,
time: time ? time[0] : undefined,
mem: mem ? mem[0] : undefined,
id: id,
score: score
});
}
});
if (ids_to_refresh.length > 0) {
setTimeout(function() {
fetch_atcoder_result(base_url, ids_to_refresh);
},500);
}
};
}
if (submissions.length > 0) {
fetch_atcoder_result(url, submissions);
}