-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
232 lines (216 loc) · 7.59 KB
/
index.html
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lichess Opening Tournament Schedule</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif,
Apple Color Emoji, Segoe UI Emoji;
color: #c9d1d9;
background-color: #0d1117;
padding: 2em;
}
h1 {
margin-top: 0;
}
.highlight {
background-color: #401818 !important;
}
td,
th {
padding: 2px 10px;
}
.table-day-schedule tr td:nth-child(1),
.table-day-schedule tr td:nth-child(2) {
text-align: center;
}
.table-day-schedule tr td:nth-child(3) {
text-align: right;
padding: 0;
}
.table-day-schedule tr th:nth-child(4) {
text-align: left;
}
.table-day-schedule tr:nth-child(2),
.table-day-schedule tr:nth-child(3),
.table-day-schedule tr:nth-child(4),
.table-day-schedule tr:nth-child(5),
.table-day-schedule tr:nth-child(10),
.table-day-schedule tr:nth-child(11),
.table-day-schedule tr:nth-child(12),
.table-day-schedule tr:nth-child(13) {
background-color: #231d1d;
}
#table-openings td:first-child {
text-align: center;
}
#table-openings th:last-child {
text-align: left;
}
#table-openings tr:nth-child(2n) {
background-color: #151d27;
}
a {
color: #58a6ff;
}
</style>
</head>
<body>
<h1>Lichess Opening Tournament Schedule</h1>
<p>
<small>
<a href="https://github.com/benediktwerner/lichess-themed-tournament-schedule"
>Source Code</a
>
<i>
Disclaimer: This is not official information. There is no guarantee that any of these
tournaments will take place. The tournament schedule may change at any point.
</i>
</small>
</p>
<h2>Today <span id="today-date"></span></h2>
<table class="table-day-schedule" id="table-today" cellspacing="0">
<tr>
<th>UTC</th>
<th class="tz"></th>
<th colspan="2">Format</th>
<th>Opening</th>
</tr>
</table>
<h2>Tomorrow <span id="tomorrow-date"></span></h2>
<table class="table-day-schedule" id="table-tomorrow" cellspacing="0">
<tr>
<th>UTC</th>
<th class="tz"></th>
<th colspan="2">Format</th>
<th>Opening</th>
</tr>
</table>
<h2>All openings</h2>
<p style="max-width: 800px">
The three selected openings move forward by one each day, so each opening has tournaments
three days in a row. On the first day, the opening starts at 03:00 UTC, the next day at 11:00
UTC, and the last day on 19:00 UTC, each time going through Bullet, SuperBlitz, Blitz, and
Rapid in subsequent hours.
</p>
<table id="table-openings" cellspacing="0">
<tr>
<th>No</th>
<th>Opening</th>
<th>Next occurrence</th>
</tr>
</table>
<script>
const MS_IN_DAY = 24 * 60 * 60 * 1000;
function dayOfYear(offset = 0) {
// tournaments get scheduled one day in advance
const now = new Date(+new Date() + (offset - 1) * MS_IN_DAY);
const start = Date.UTC(now.getUTCFullYear(), 0, 0);
return Math.floor((now - start) / MS_IN_DAY);
}
function formatDate(date) {
return `${pad2(date.getUTCDate())}.${pad2(
date.getUTCMonth() + 1
)}.${date.getUTCFullYear()}`;
}
function pad2(num) {
return num.toString().padStart(2, "0");
}
function h(tag, content) {
const el = document.createElement(tag);
if (content instanceof Array) content.forEach((e) => el.append(e));
else el.innerText = content;
return el;
}
async function main() {
const r = await fetch("openings.txt");
/** @type {string} */
const text = await r.text();
/** @type {HTMLElement[]} */
const openings = text
.split(/\r?\n/)
.filter(Boolean)
.map((name) => {
const a = h("a", name);
const moves = name
.split("1. ")[1]
.replace(/\d+\. /g, "")
.replace(/ /g, "_");
a.href = "https://lichess.org/opening/-/" + moves;
return a;
});
const now = new Date();
const openingsTable = document.getElementById("table-openings");
const todayTable = document.getElementById("table-today");
const tomorrowTable = document.getElementById("table-tomorrow");
const today = dayOfYear();
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const timeZoneOffset = -now.getTimezoneOffset();
Array.from(document.getElementsByClassName("tz")).forEach(
(el) =>
(el.innerHTML = `${timeZone}<br>UTC${timeZoneOffset > 0 ? "+" : ""}${pad2(
Math.floor(timeZoneOffset / 60)
)}:${pad2(timeZoneOffset % 60)}`)
);
const seen = new Set();
const currentIndices = [0, 1, 2].map((o) => (dayOfYear() + o) % openings.length);
const current = [null, null, null];
const list = [];
for (let daysOff = 1; seen.size < openings.length; daysOff++) {
const index = (dayOfYear(daysOff) + 2) % openings.length;
const curr = currentIndices.indexOf(index);
const opening = openings[index];
let nextDate = new Date();
nextDate.setUTCDate(nextDate.getUTCDate() + daysOff);
const tr = h("tr", [
h("td", ((index + openings.length - 3) % openings.length) + 1),
h("td", [opening.cloneNode(true)]),
h("td", formatDate(nextDate)),
]);
if (curr !== -1) {
const c = tr.cloneNode(true);
c.children[2].innerText +=
" (and " + ["today", "today+tomorrow", "today+next 2 days"][curr] + ")";
c.classList.add("highlight");
current[curr] = c;
}
list.push(tr);
seen.add(index);
}
current.forEach((tr) => openingsTable.append(tr));
list.forEach((tr) => openingsTable.append(tr));
[todayTable, tomorrowTable].forEach((table, dayOff) => {
[2, 1, 0].forEach((off) => {
const opening = openings[(dayOfYear(dayOff) + off) % openings.length];
const utcHourBase = [19, 11, 3][off];
[0, 1, 2, 3].forEach((off2) => {
const utcHour = utcHourBase + off2;
const localTime = (utcHour * 60 + timeZoneOffset) % (24 * 60);
const formatTime = ["1+0", " 3+0", " 5+0", "10+0"][off2];
const formatName = ["Bullet", "SuperBlitz", " Blitz", "Rapid"][off2];
table.append(
h("tr", [
h("td", pad2(utcHour) + ":00"),
h("td", pad2(Math.floor(localTime / 60)) + ":" + pad2(localTime % 60)),
h("td", formatTime),
h("td", formatName),
h("td", [opening.cloneNode(true)]),
])
);
});
});
});
document.getElementById("today-date").innerText = formatDate(now);
now.setUTCDate(now.getUTCDate() + 1);
document.getElementById("tomorrow-date").innerText = formatDate(now);
}
main();
</script>
</body>
</html>