-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
148 lines (130 loc) · 4.45 KB
/
main.js
File metadata and controls
148 lines (130 loc) · 4.45 KB
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
document.addEventListener("DOMContentLoaded", () => {
// Initialize Lucide icons
if (window.lucide && typeof lucide.createIcons === "function") {
lucide.createIcons();
}
// Default to dark mode
document.body.setAttribute("data-theme", "dark");
const themeToggleBtn = document.getElementById("themeToggleBtn");
themeToggleBtn.textContent = "Toggle Light Mode";
// Game list
const games = [
{ title: "A dance of fire and ice", img: "images/ADOFAI.jpeg", url: "games/ADOFAI.html" },
{ title: "A Dark Room", img: "images/ADarkRoom.png", url: "games/ADarkRoom.html" },
{ title: "A Day in the office", img: "images/.png", url: "games/adayintheoffice.html" }
// Add more games here
];
// DOM references
const gameGrid = document.getElementById("gameGrid");
const overlay = document.getElementById("gameOverlay");
const gameFrame = document.getElementById("gameFrame");
const searchInput = document.getElementById("searchInput");
const fullscreenBtn = document.getElementById("fullscreenBtn");
const reloadBtn = document.getElementById("reloadBtn");
const downloadBtn = document.getElementById("downloadBtn");
const blobBtn = document.getElementById("blobBtn");
const closeBtn = document.getElementById("closeBtn");
const settingsIcon = document.getElementById("settingsIcon");
const settingsPopup = document.getElementById("settingsPopup");
const closeSettings = document.getElementById("closeSettings");
const blankBtn = document.getElementById("blankBtn");
// Render game cards
function renderGames(filter = "") {
gameGrid.innerHTML = "";
games
.filter(g => g.title.toLowerCase().includes(filter.toLowerCase()))
.forEach(game => {
const card = document.createElement("div");
card.className = "game-card";
card.innerHTML = `
<img src="${game.img}" alt="${game.title}" />
<div class="game-title">${game.title}</div>
`;
card.addEventListener("click", () => openGame(game));
gameGrid.appendChild(card);
});
}
// Search filter
searchInput.addEventListener("input", e => {
renderGames(e.target.value || "");
});
// Open game overlay
function openGame(game) {
gameFrame.src = game.url;
overlay.classList.add("active");
// Download original file
downloadBtn.onclick = () => {
const a = document.createElement("a");
a.href = game.url;
a.download = `${game.title}.html`;
document.body.appendChild(a);
a.click();
a.remove();
};
// Open blob URL in new tab
blobBtn.onclick = async () => {
try {
const res = await fetch(game.url);
const blob = await res.blob();
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl, "_blank");
} catch (err) {
console.error("Blob open failed:", err);
}
};
// Reload iframe game
reloadBtn.onclick = () => {
try {
if (gameFrame.contentWindow) {
gameFrame.contentWindow.location.reload();
} else {
const current = gameFrame.src;
gameFrame.src = current;
}
} catch {
const current = gameFrame.src;
gameFrame.src = current;
}
};
// Fullscreen
fullscreenBtn.onclick = () => {
const el = gameFrame;
const req =
el.requestFullscreen ||
el.webkitRequestFullscreen ||
el.mozRequestFullScreen ||
el.msRequestFullscreen;
if (req) req.call(el);
};
}
// Close game overlay
closeBtn?.addEventListener("click", () => {
overlay.classList.remove("active");
gameFrame.src = "";
});
// Open settings popup
settingsIcon.addEventListener("click", () => {
settingsPopup.classList.add("active");
});
// Close settings popup
closeSettings?.addEventListener("click", () => {
settingsPopup.classList.remove("active");
});
// Theme toggle logic
themeToggleBtn.addEventListener("click", () => {
const current = document.body.getAttribute("data-theme");
if (current === "dark") {
document.body.setAttribute("data-theme", "light");
themeToggleBtn.textContent = "Toggle Dark Mode";
} else {
document.body.setAttribute("data-theme", "dark");
themeToggleBtn.textContent = "Toggle Light Mode";
}
});
// Tab cloak
blankBtn?.addEventListener("click", () => {
window.open("about:blank", "_blank");
});
// Initial render
renderGames();
});