-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
253 lines (242 loc) · 9.5 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<!DOCTYPE html>
<html lang="en" class="bg-slate-800">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Start.gg Data Viewer</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="//unpkg.com/alpinejs" defer></script>
<link href="./style/mermaid.css" rel="stylesheet" />
</head>
<body x-data="{ urlParams: new URLSearchParams(window.location.search) }">
<template x-if="!urlParams.has('videogameId') && !urlParams.has('characterId')">
<div class="p-8 bg-slate-800 flex flex-col gap-8">
<div>
<h1 class="text-4xl text-slate-200 font-bold pb-4">Start.gg Data Viewer</h1>
<div class="text-slate-50 w-96 flex flex-col gap-2">
<p>
Created by
<a class="text-sky-300 underline" href="https://github.com/CarcajadaArtificial"
>Oscar Alfonso Guerrero</a
>
</p>
<p>
Hello and welcome third-party startgg developer. This is a simple and useful site for
exploring the list of videogames and characters supported. The data displayed in this site
are directly obtained from the
<a class="text-sky-300 underline" href="https://api.start.gg/videogames"
>videogames api</a
>
and the
<a class="text-sky-300 underline" href="https://api.start.gg/characters">characters api</a
>.
</p>
<code class="text-slate-500">version 0.0.9</code>
</div>
</div>
<h2 class="text-2xl text-slate-200 font-bold">Videogames</h2>
<div class="overflow-x-auto">
<div style="min-width: 800px; max-width: 800px">
<div id="videogames-wrapper"></div>
</div>
</div>
<h2 class="text-2xl text-slate-200 font-bold">Characters</h2>
<div class="overflow-x-auto">
<div style="min-width: 800px; max-width: 800px">
<div id="characters-wrapper"></div>
</div>
</div>
</div>
</template>
<!--
Videogame profile page
-->
<template x-if="urlParams.has('videogameId') && !urlParams.has('characterId')">
<div
x-data="{
async getMatchingVideogame() {
return (Object.values(await (await fetch('./data/videogames.json')).json()).find(vg => vg.id === parseInt(urlParams.get('videogameId'))))
}
}"
>
<div class="p-8 bg-slate-800 flex flex-col gap-8">
<div class="flex gap-4">
<a href="?">
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-arrow-left"
width="44"
height="44"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="#e2e8f0"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M5 12l14 0" />
<path d="M5 12l6 6" />
<path d="M5 12l6 -6" />
</svg>
</a>
<h2
x-text="(await getMatchingVideogame()).displayName"
x-if="urlParams.has('videogameId') && !urlParams.has('characterId')"
class="text-4xl text-slate-200 font-bold"
></h2>
</div>
<div class="p-4 bg-slate-200 rounded-md flex flex-col">
<template x-for="(vgDataValue, vgDataIndex) in await getMatchingVideogame()">
<div class="flex gap-4" x-show="!['images', 'expand'].includes(vgDataIndex)">
<span class="text-lg font-bold" x-text="vgDataIndex"></span>
<span x-text="String(vgDataValue)"></span>
</div>
</template>
</div>
<h3 class="text-2xl text-slate-200 font-bold">Images</h3>
<div class="flex flex-wrap gap-8">
<template x-for="imageObject in (await getMatchingVideogame()).images">
<div class="p-4 flex-1 bg-slate-200 rounded-md flex flex-col">
<img class="pb-4" x-bind:src="imageObject.url" alt="" />
<template x-for="(imgValue, imgIndex) in imageObject">
<div class="flex gap-4" x-show="!['url'].includes(imgIndex)">
<span class="text-lg font-bold" x-text="imgIndex"></span>
<span x-text="String(imgValue)"></span>
</div>
</template>
</div>
</template>
</div>
</div>
</div>
</template>
<!--
Character profile page
-->
<template x-if="urlParams.has('characterId') && !urlParams.has('videogameId')">
<div
x-data="{
async getMatchingCharacter() {
return (Object.values(await (await fetch('./data/characters.json')).json()).find(vg => vg.id === parseInt(urlParams.get('characterId'))))
}
}"
>
<div class="p-8 bg-slate-800 flex flex-col gap-8">
<div class="flex gap-4">
<a href="?">
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-arrow-left"
width="44"
height="44"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="#e2e8f0"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M5 12l14 0" />
<path d="M5 12l6 6" />
<path d="M5 12l6 -6" />
</svg>
</a>
<h2
x-text="(await getMatchingCharacter()).name"
class="text-4xl text-slate-200 font-bold"
></h2>
</div>
<div class="p-4 bg-slate-200 rounded-md flex flex-col">
<template x-for="(charDataValue, charDataIndex) in await getMatchingCharacter()">
<div class="flex gap-4" x-show="!['images', 'expand'].includes(charDataIndex)">
<span class="text-lg font-bold" x-text="charDataIndex"></span>
<span x-text="String(charDataValue)"></span>
</div>
</template>
</div>
<h3 class="text-2xl text-slate-200 font-bold">Images</h3>
<div class="flex flex-wrap gap-8">
<template x-for="imageObject in (await getMatchingCharacter()).images">
<div class="p-4 flex-1 bg-slate-200 rounded-md flex flex-col">
<img class="pb-4" x-bind:src="imageObject.url" alt="" />
<template x-for="(imgValue, imgIndex) in imageObject">
<div class="flex gap-4" x-show="!['url'].includes(imgIndex)">
<span class="text-lg font-bold" x-text="imgIndex"></span>
<span x-text="String(imgValue)"></span>
</div>
</template>
</div>
</template>
</div>
</div>
</div>
</template>
</body>
<script type="module">
import { Grid, html } from 'https://unpkg.com/gridjs?module';
const videogames = await (await fetch('./data/videogames.json')).json();
const characters = (await (await fetch('./data/characters.json')).json())
.map((character) => {
const videogameMatch = videogames.filter((videogame) => videogame.id === character.videogameId);
character.videogameName =
videogameMatch[0] && videogameMatch[0].name ? videogameMatch[0].name : undefined;
return character;
})
.filter((character) => character.videogameName);
const extractPropertyValues = (objects, propertyNames) =>
objects.map((obj) => {
const values = [];
propertyNames.forEach((prop) => {
values.push(obj[prop]);
});
return values;
});
const gridConfig = {
search: true,
sort: true,
autoWidth: false,
className: {
td: 'bg-slate-200',
th: 'bg-slate-100',
search: 'bg-slate-100',
paginationButton: 'bg-slate-100',
paginationButtonNext: 'bg-slate-100',
paginationButtonCurrent: 'bg-slate-200',
paginationButtonPrev: 'bg-slate-100',
paginationSummary: 'text-slate-50',
},
pagination: {
limit: 8,
},
};
const videogameHeaders = [{ name: 'id', width: '100px' }, { name: 'abbrev' }, { name: 'name' }];
const characterHeaders = [
{ name: 'id', width: '100px' },
{ name: 'name' },
{ name: 'videogameId', width: '200px' },
{ name: 'videogameName' },
];
await new Grid({
columns: videogameHeaders,
data: extractPropertyValues(
videogames,
videogameHeaders.map((header) => header.name)
),
...gridConfig,
})
.render(document.getElementById('videogames-wrapper'))
.on('rowClick', (_p, e) => window.location.replace(`?videogameId=${e.cells[0].data}`));
await new Grid({
columns: characterHeaders,
data: extractPropertyValues(
characters,
characterHeaders.map((header) => header.name)
),
...gridConfig,
})
.render(document.getElementById('characters-wrapper'))
.on('rowClick', (_p, e) => window.location.replace(`?characterId=${e.cells[0].data}`));
</script>
</html>