-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
116 lines (102 loc) · 3.75 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
(function() {
// URLs for hosted files
const cssUrl = "https://cdn.jsdelivr.net/gh/orn8/appmenu/appmenu.css";
const jsUrl = "https://cdn.jsdelivr.net/gh/orn8/appmenu/appmenu.js";
const htmlUrl = "https://cdn.jsdelivr.net/gh/orn8/appmenu/appmenu.html";
// Function to load CSS
function loadCSS(url) {
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = url;
document.head.appendChild(link);
}
// Function to load JavaScript
function loadJS(url) {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = url;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);
});
}
// Function to load HTML and append it to the body
function loadHTML(url) {
return fetch(url)
.then(response => response.text())
.then(html => {
document.body.insertAdjacentHTML("afterbegin", html);
});
}
// Load CSS, HTML, and JS
loadCSS(cssUrl);
loadHTML(htmlUrl)
.then(() => loadJS(jsUrl))
.catch(error => console.error("Error loading app menu:", error));
})();