Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
amethystnetwork-dev
GitHub Repository: amethystnetwork-dev/Incognito
Path: blob/main/static/script/gs.js
918 views
1
/**
2
* Incognito
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
/*
19
_____ _ _ _
20
| __ \ | | | | | |
21
| |__) | ___ _ __ | |_ ___ __| | | |__ _ _
22
| ___/ / _ \ | '__| | __| / _ \ / _` | | '_ \ | | | |
23
| | | (_) | | | | |_ | __/ | (_| | | |_) | | |_| |
24
|_| \___/ |_| \__| \___| \__,_| |_.__/ \__, |
25
__/ |
26
|___/
27
_ _ _ _ _ _ _
28
/\ | | | | | | | \ | | | | | |
29
/ \ _ __ ___ ___ | |_ | |__ _ _ ___ | |_ | \| | ___ | |_ __ __ ___ _ __ | | __
30
/ /\ \ | '_ ` _ \ / _ \ | __| | '_ \ | | | | / __| | __| | . ` | / _ \ | __| \ \ /\ / / / _ \ | '__| | |/ /
31
/ ____ \ | | | | | | | __/ | |_ | | | | | |_| | \__ \ | |_ | |\ | | __/ | |_ \ V V / | (_) | | | | <
32
/_/ \_\ |_| |_| |_| \___| \__| |_| |_| \__, | |___/ \__| |_| \_| \___| \__| \_/\_/ \___/ |_| |_|\_\
33
__/ |
34
|___/
35
*/
36
async function gs(app) {
37
app.search.input.placeholder = 'Search library'
38
app.search.back.style.display = 'inline';
39
app.search.back.href = '#';
40
41
app.main.library = app.createElement('div', await compileGs(app), {
42
style: {
43
'margin-bottom': '40px'
44
}
45
});
46
app.main.emptySearch = app.createElement('div', [
47
app.createElement('p', 'No results found.')
48
], {
49
class: 'gs-empty',
50
style: {
51
display: 'none'
52
}
53
});
54
app.main.player = app.createElement('div', [
55
app.createElement('iframe', [], {
56
class: 'gs-frame',
57
events: {
58
focus(event) {
59
event.target.contentWindow.focus();
60
}
61
},
62
attrs: {
63
tabindex: 1,
64
src: 'about:blank'
65
}
66
}),
67
app.createElement('p', [], {
68
class: 'author'
69
}),
70
app.createElement('div', [], {
71
class: 'description'
72
})
73
], {
74
class: 'gs-player',
75
style: {
76
display: 'none',
77
}
78
});
79
80
function searchGames() {
81
let count = 0;
82
83
app.main.library.querySelectorAll('.gs-entry').forEach(node => {
84
if (node.getAttribute('data-title').toLowerCase().includes(app.search.input.value.toLowerCase())) {
85
node.setAttribute('data-active', '1');
86
count++;
87
} else {
88
node.removeAttribute('data-active');
89
};
90
});
91
92
app.main.library.querySelectorAll('.category').forEach(node => {
93
if (!node.querySelectorAll('.gs-library .gs-entry[data-active]').length) {
94
node.style.display = 'none';
95
} else {
96
node.style.removeProperty('display');
97
};
98
});
99
100
if (!count) {
101
app.main.library.style.display = 'none';
102
app.main.emptySearch.style.display = 'block';
103
} else {
104
app.main.library.style.removeProperty('display');
105
app.main.emptySearch.style.display = 'none';
106
};
107
}
108
109
app.search.input.addEventListener('input', searchGames)
110
app.once('exit', () => app.search.input.removeEventListener('input', searchGames));
111
};
112
113
114
async function compileGs(app) {
115
const res = await fetch('./source/gs.json');
116
const json = await res.json();
117
118
const list = {
119
multi: [],
120
featured: [],
121
web: [],
122
indie: [],
123
nes: [],
124
snes: [],
125
gba: [],
126
sega: [],
127
gfn: [],
128
n64: [],
129
};
130
131
app.search.input.placeholder = `Search library (${json.length})`
132
for (const entry of json) {
133
const elem = app.createElement('div', [], {
134
class: 'gs-entry',
135
style: {
136
background: `url(${entry.img})`,
137
'background-size': 'cover'
138
},
139
attrs: {
140
'data-title': entry.title,
141
'data-active': '1'
142
},
143
events: {
144
click(event) {
145
function foc() {
146
if (window.location.hash !== '#gs' || !app.main.player) {
147
return window.removeEventListener('click', foc);
148
};
149
app.main.player.querySelector('iframe').contentWindow.focus()
150
};
151
app.main.library.style.display = 'none';
152
app.main.player.style.display = 'block';
153
app.search.input.style.display = 'none';
154
app.search.title.style.display = 'block';
155
app.search.title.textContent = entry.title;
156
157
window.addEventListener('click', foc);
158
159
app.nav.fullscreen = app.createElement('button', 'fullscreen', {
160
class: 'submit',
161
style: {
162
'font-family': 'Material Icons',
163
'font-size': '30px',
164
color: 'var(--accent)',
165
background: 'none',
166
border: 'none',
167
cursor: 'pointer'
168
},
169
events: {
170
click() {
171
app.main.player.querySelector('iframe').requestFullscreen();
172
app.main.player.querySelector('iframe').contentWindow.focus();
173
}
174
}
175
});
176
177
app.main.player.querySelector('iframe').src = entry.location;
178
app.main.player.querySelector('.author').textContent = entry.author || '';
179
app.main.player.querySelector('.description').textContent = entry.description || '';
180
181
window.scrollTo({ top: 0 });
182
183
function exitGame(event) {
184
if (window.location.hash !== '#gs') return this.removeEventListener('click', exitGame);
185
186
event.preventDefault();
187
188
app.main.library.style.removeProperty('display');
189
app.search.input.style.removeProperty('display');
190
app.search.title.style.display = 'none';
191
app.search.title.textContent = '';
192
app.main.player.style.display = 'none';
193
app.main.player.querySelector('iframe').src = 'about:blank';
194
delete app.nav.fullscreen;
195
196
this.removeEventListener('click', exitGame);
197
}
198
199
app.search.back.addEventListener('click', exitGame);
200
/*
201
nav(entry.location, entry.title, entry.img);
202
*/
203
}
204
} });
205
206
if (entry.featured) {
207
list.featured.push(elem);
208
} else {
209
(list[entry.category] || list.indie).push(elem);
210
};
211
};
212
213
return [
214
app.createElement('section', [
215
app.createElement('span', 'Featured', {
216
style: {
217
display: 'block',
218
'margin-bottom': '30px',
219
'font-size': '18px',
220
'font-weight': '500'
221
}
222
}),
223
app.createElement('div', list.featured, {
224
class: 'gs-library'
225
})
226
], {
227
class: 'data-section featured category',
228
attrs: {
229
'data-category': 'featured'
230
}
231
}),
232
app.createElement('section', [
233
app.createElement('span', 'Multiplayer', {
234
style: {
235
display: 'block',
236
'margin-bottom': '30px',
237
'font-size': '18px',
238
'font-weight': '500'
239
}
240
}),
241
app.createElement('div', list.multi, {
242
class: 'gs-library'
243
})
244
], {
245
class: 'data-section multi category',
246
attrs: {
247
'data-category': 'multi'
248
}
249
}),
250
app.createElement('section', [
251
app.createElement('span', 'Mobile & Web', {
252
style: {
253
display: 'block',
254
'margin-bottom': '30px',
255
'font-size': '18px',
256
'font-weight': '500'
257
}
258
}),
259
app.createElement('div', list.web, {
260
class: 'gs-library'
261
})
262
], {
263
class: 'data-section web category',
264
attrs: {
265
'data-category': 'web'
266
}
267
}),
268
app.createElement('section', [
269
app.createElement('span', 'Indie', {
270
style: {
271
display: 'block',
272
'margin-bottom': '30px',
273
'font-size': '18px',
274
'font-weight': '500'
275
}
276
}),
277
app.createElement('div', list.indie, {
278
class: 'gs-library'
279
})
280
], {
281
class: 'data-section indie category',
282
attrs: {
283
'data-category': 'indie'
284
}
285
}),
286
app.createElement('section', [
287
app.createElement('span', 'Nintendo', {
288
style: {
289
display: 'block',
290
'margin-bottom': '30px',
291
'font-size': '18px',
292
'font-weight': '500'
293
}
294
}),
295
app.createElement('div', [ ...list.gba, ...list.snes, ...list.nes, ...list.n64 ], {
296
class: 'gs-library'
297
})
298
], {
299
class: 'data-section nintendo category',
300
attrs: {
301
'data-category': 'nintendo'
302
}
303
}),
304
app.createElement('section', [
305
app.createElement('span', 'GeForce Now', {
306
style: {
307
display: 'block',
308
'margin-bottom': '30px',
309
'font-size': '18px',
310
'font-weight': '500'
311
}
312
}),
313
app.createElement('div', list.gfn, {
314
class: 'gs-library'
315
})
316
], {
317
class: 'data-section gfn category',
318
attrs: {
319
'data-category': 'gfn'
320
}
321
})
322
]
323
};
324
325
export { gs };
326
327