-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
95 lines (82 loc) · 3.07 KB
/
script.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
document.addEventListener('DOMContentLoaded', function() {
function fetchAndSetupButtons() {
fetch('gamelist.txt')
.then(response => response.text())
.then(gamesString => {
const lines = gamesString.split('\n');
const filteredLines = lines.filter(line => line.trim() !== '' && !line.trim().startsWith('##'));
const filteredGamesString = filteredLines.join('\n');
setupButtons(filteredGamesString);
});
}
function setupButtons(gamesString) {
const buttonsContainer = document.getElementById('gameButtons');
const gamesArray = gamesString.trim().split('\n')
.map(line => {
const [name, url] = line.split(';').map(part => part.trim());
return { name, url };
})
.filter(game => game.name && game.url)
.sort((a, b) => a.name.localeCompare(b.name));
const gamesHeading = document.querySelector('h1');
gamesHeading.textContent = `Games (${gamesArray.length})`;
gamesArray.forEach(game => {
const button = document.createElement('button');
button.textContent = game.name;
button.dataset.url = game.url;
button.classList.add('button');
button.addEventListener('click', function() {
const encodedUrl = encodeURIComponent(game.url);
const encodedTitle = encodeURIComponent(game.name)
window.open(`gameX.html?url=${encodedUrl}&title=${encodedTitle}`, '_blank');
});
buttonsContainer.appendChild(button);
});
}
function searchGames() {
const input = document.getElementById('searchInput');
const filter = input.value.toUpperCase();
const buttons = [...document.getElementById('gameButtons').getElementsByTagName('button')];
buttons.forEach(button => {
const text = button.textContent || button.innerText;
button.style.display = text.toUpperCase().includes(filter) ? '' : 'none';
});
}
const searchButton = document.getElementById('searchButton');
const searchInput = document.getElementById('searchInput');
function triggerSearchButtonEffect() {
searchButton.style.backgroundColor = '#FC6A04';
searchButton.style.color = '#f5f5f5';
setTimeout(function() {
if (!searchButton.matches(':hover')) {
searchButton.style.backgroundColor = '';
searchButton.style.color = '';
}
}, 300);
}
searchInput.addEventListener('input', searchGames);
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
triggerSearchButtonEffect();
searchInput.blur();
}
});
fetchAndSetupButtons();
});
// App Menu
document.addEventListener("DOMContentLoaded", () => {
const menuButton = document.getElementById("app-menu-button");
const menuGrid = document.getElementById("app-menu-grid");
menuButton.addEventListener("click", () => {
menuGrid.classList.toggle("show");
});
const appItems = document.querySelectorAll(".app-menu-item");
appItems.forEach((item) => {
item.addEventListener("click", () => {
const link = item.dataset.link;
if (link) {
window.open(link, "_blank");
}
});
});
});