-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatcoder-virtual-remaining-time-display.user.js
78 lines (72 loc) · 2.68 KB
/
atcoder-virtual-remaining-time-display.user.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
// ==UserScript==
// @name atcoder-virtual-remaining-time-display
// @namespace https://github.com/ilplrr
// @version 1.0
// @description バーチャルコンテストの残り時間を表示します。
// @author ilplrr
// @license MIT
// @match https://atcoder.jp/contests/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
if (getServerTime() < endTime) return;
const createTimer = (data) => {
if (!data.isVirtual) return;
if (!(data.virtualStartTime && data.virtualEndTime)) return;
const timer = document.createElement('div');
timer.id = 'virtual-timer';
timer.style = `
position: fixed;
right: 170px;
bottom: 0px;
width: 160px;
height: 80px;
margin: 0;
padding: 20px 0;
background-image: url("//img.atcoder.jp/assets/contest/digitalclock.png");
text-align: center;
line-height: 20px;
font-size: 15px;
cursor: pointer;
z-index: 50;
`;
document.body.appendChild(timer);
let intervalId = null;
const update = () => {
const serverTime = getServerTime();
let s = '';
if (serverTime.isAfter(data.virtualEndTime)) {
s += 'バーチャル参加終了<br>'
s += `<span style="color: #c00;">残り:${durationFormat(0)}</span>`;
if (intervalId) {
clearInterval(intervalId);
intervalId = null;
}
} else if (serverTime.isAfter(data.virtualStartTime)) {
s += 'バーチャル参加中<br>'
s += `残り:${durationFormat(data.virtualEndTime.diff(serverTime))}`;
} else {
s += 'バーチャル参加まで<br>'
s += `残り:${durationFormat(data.virtualStartTime.diff(serverTime))}`;
}
timer.innerHTML = s;
};
intervalId = setInterval(update, 100);
};
const virtualStandingURL = `${location.origin}/contests/${contestScreenName}/standings/virtual`;
fetch(virtualStandingURL).then((response) => {
return response.text();
}).then((text) => {
const doc = new DOMParser().parseFromString(text, 'text/html');
const data = {};
doc.querySelectorAll('script').forEach((e) => {
const s = e.innerHTML;
const m = s.match(/(isVirtual|virtual(Start|End)Time)\s*=\s*[^\n]*/g);
if (m) {
m.forEach((s) => eval('data.' + s));
}
});
createTimer(data);
});
})();