-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
126 lines (126 loc) · 4 KB
/
index.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(async () => {
const main = document.querySelector("main");
let firstGame = document.querySelector("main > section");
const format = new Intl.DateTimeFormat("fr", {
"year":"numeric",
"month":"long",
"day":"numeric",
"timeZone":"UTC",
});
const response = await fetch("./index.json");
const json = await response.json();
for (const game of json) {
if (game.priority !== 1 && game.priority !== 2) {
continue;
}
const section = document.createElement("section");
section.id = game.repository;
if (game.priority === 2) {
section.classList.add("featured");
}
const heading = document.createElement("h2");
const link = document.createElement("a");
link.href = `//github.com/TeleGD/${game.repository}`;
link.textContent = game.title;
heading.append(link);
const paragraph = document.createElement("p");
const time = document.createElement("time");
const date = new Date(Date.parse(game.date));
time.dateTime = date.toISOString().slice(0, 10);
time.textContent = format.format(date);
paragraph.append("Commencé le ", time);
const figure = document.createElement("figure");
const caption = document.createElement("figcaption");
caption.textContent = `Capture d'écran du jeu ${game.title}`;
figure.append(caption);
const picture = document.createElement("picture");
const image = document.createElement("img");
image.width = 1280;
image.height = 720;
image.loading = "lazy";
image.src = `//raw.githubusercontent.com/TeleGD/${game.repository}/master/screenshot.png`;
image.addEventListener("load", () => {
image.width = image.naturalWidth;
image.height = image.naturalHeight;
image.alt = ""; // TODO
});
image.addEventListener("error", () => {
image.alt = "Aucun aperçu disponible";
});
picture.append(image);
figure.append(picture);
section.append(heading, paragraph, figure);
if (game.released) {
switch (game.engine) {
case "GameMaker Studio": {
const paragraph = document.createElement("p");
const link = document.createElement("a");
link.href = `//github.com/TeleGD/${game.repository}/releases/latest/download/${game.repository}.exe`;
link.download = `${game.repository}.exe`;
link.textContent = "Pour Windows";
paragraph.append(link);
section.append(paragraph);
break;
}
case "Noyo": {
const paragraph = document.createElement("p");
const link = document.createElement("a");
link.href = `//telegd.github.io/${game.repository}/`;
link.textContent = "En ligne";
paragraph.append(link);
section.append(paragraph);
break;
}
case "Slick2D": {
const assets = [
["x86", "Pour x86 (Linux, Mac et Windows)"],
["arm", "Pour ARM (Linux)"],
];
for (const asset of assets) {
const paragraph = document.createElement("p");
const link = document.createElement("a");
link.href = `//github.com/TeleGD/${game.repository}/releases/latest/download/${game.repository}-${asset[0]}.zip`;
link.download = `${game.repository}-${asset[0]}.zip`;
link.textContent = asset[1];
paragraph.append(link);
section.append(paragraph);
}
break;
}
case "Unity": {
const paragraph = document.createElement("p");
const link = document.createElement("a");
link.href = `//telegd.github.io/${game.repository}/`;
link.textContent = "En ligne";
paragraph.append(link);
section.append(paragraph);
break;
}
}
}
if (game.priority === 2) {
main.prepend(section);
continue;
}
firstGame.before(section);
firstGame = section;
}
const target = () => {
const id = location.hash.slice(1);
let element = null;
if (id !== "") {
element = document.querySelector(`main > section#${CSS.escape(id)} > h2 > a:not([download])`);
}
if (element === null) {
element = document.querySelector("main > section > h2 > a:not([download])");
}
element.focus();
element.scrollIntoView({
"block": "center",
});
};
target();
window.addEventListener("hashchange", (event) => {
target();
});
}) ();