-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathgame.js
195 lines (195 loc) · 8.24 KB
/
game.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
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
document.addEventListener("DOMContentLoaded", () => {
const params = new URLSearchParams(window.location.search);
const gameID = params.get("target");
let newArray = [];
const download = document.getElementById("download");
fetch("games.json")
.then((response) => response.json())
.then((dataa) => {
let data = dataa.games;
for (var i = 0; i < data.length; i++) {
newArray.push(data[i]);
}
newArray.forEach((game) => {
if (game.id == gameID && game.download) {
download.addEventListener("click", () => {
window.open(
`https://macvg-games.github.io/zips/game${gameID}.zip`,
"_blank"
);
});
} else if (game.id == gameID) {
download.style.display = "none";
}
});
})
.catch((error) => console.error("Error fetching data:", error));
//Above is code for download button
const gameFrame = document.getElementById("gameframe");
const gameIFrame = gameFrame.children[0].contentWindow;
const fullScreen = document.getElementById("fullscreen");
let isGameActive = true;
fullScreen.addEventListener("click", function () {
if (document.fullscreenElement) {
document.exitFullscreen();
fullScreen.src = "/macvg/media/expand.svg";
} else {
fullScreen.src = "/macvg/media/compress.svg";
gameFrame.requestFullscreen();
}
});
gameFrame.addEventListener("mouseenter", () => (isGameActive = true));
gameFrame.addEventListener("mouseleave", () => (isGameActive = false));
setInterval(() => {
if (isGameActive && document.activeElement !== gameIFrame) {
gameIFrame.focus();
}
}, 1000);
//Above is code for full screen and focusing on the frame
const gameShare = document.getElementById("game-share");
const gameShareBtn = document.getElementById("game-share-btn");
const share = document.getElementById("share");
gameShareBtn.addEventListener("click", function () {
gameShare.classList.add("none");
});
share.addEventListener("click", function () {
let thing123 = window.location.href;
navigator.clipboard.writeText(thing123);
gameShare.classList.remove("none");
});
//Above is code for sharing the game
const report = document.getElementById("report");
report.addEventListener("click", function () {
window.open("https://forms.gle/vKN71eKeMNGiswUY7", "_blank");
});
//Above is code for reporting the game
const star = document.getElementById("star");
let existingData = localStorage.getItem("favorites");
let favoritesArray = existingData.split(",");
if (favoritesArray.includes(gameID)) {
star.src = "/macvg/media/star-solid.svg";
}
star.addEventListener("click", function () {
if (star.src.includes("star-regular")) {
star.src = "/macvg/media/star-solid.svg";
favoritesArray.push(gameID);
localStorage.setItem("favorites", favoritesArray.join(","));
} else {
star.src = "/macvg/media/star-regular.svg";
const index = favoritesArray.indexOf(gameID);
favoritesArray.splice(index, 1);
localStorage.setItem("favorites", favoritesArray.join(","));
}
});
//Above is code for saving the game to favorites
let eRecent = localStorage.getItem("macvgRecents");
let recentArray = eRecent ? eRecent.split(",") : [];
if (!recentArray.includes(gameID)) {
recentArray.push(gameID);
eRecent = recentArray.join(",");
localStorage.setItem("macvgRecents", eRecent);
}
//Above is code for adding the game to recents
const sideSearch = document.getElementById("sideSearch");
const sideSearchForm = sideSearch.parentElement;
const nothing = document.getElementById("nothing");
nothing.style.paddingTop = "0px";
nothing.style.display = "none";
sideSearch.addEventListener('focus', () => isGameActive = false);
sideSearch.addEventListener('blur', () => isGameActive = true);
sideSearchForm.addEventListener("submit", (e) => {
e.preventDefault();
const list = document.getElementById("list");
let searchTerm = sideSearch.value.toLowerCase();
let results = [];
list.innerHTML = "";
for (var i = 0; i < newArray.length; i++) {
let item = newArray[i].name;
var itemText = item.toLowerCase();
if (itemText.includes(searchTerm)) {
let newGameElement = document.createElement("div");
newGameElement.classList.add("side-game");
newGameElement.innerHTML = item;
list.appendChild(newGameElement);
results.push(item);
let newGameID = newArray[i].id;
newGameElement.style.backgroundImage = `url(${
newArray[i].link + newArray[i].thumb
})`;
newGameElement.addEventListener("click", () => {
const params = new URLSearchParams({ target: newGameID });
window.location.href = `game.html?${params.toString()}`;
});
}
}
if (results.length < 1) {
nothing.style.display = "block";
nothing.style.paddingTop = "20px";
nothing.children[0].style.display = "inline";
} else {
nothing.style.paddingTop = "0px";
nothing.style.display = "none";
list.style.display = "flex";
}
});
//Above is code for sidebar search
let theme = localStorage.getItem("theme");
if (theme === "light") {
const root = document.documentElement;
root.style.setProperty("--link", "rgb(225, 139, 9)");
root.style.setProperty("--text-color", "black");
root.style.setProperty("--shadow-color", "0px 0px 5px rgb(84, 84, 84)");
root.style.setProperty("--black-color", "rgb(235, 235, 235)");
root.style.setProperty("--bg-color", "rgb(235, 235, 235)");
root.style.setProperty("--bg-color-2", "rgb(30, 30, 30)");
root.style.setProperty("--group-bg-color", "rgb(140, 140, 140, 0.7)");
root.style.setProperty("--bar-color", "rgb(200, 200, 200)");
} else if (theme === "deep") {
const root = document.documentElement;
root.style.setProperty("--text-color", "white");
root.style.setProperty("--link", "rgb(225, 139, 9)");
root.style.setProperty("--shadow-color", "0px 5px 5px rgb(25,25,25)");
root.style.setProperty("--black-color", "black");
root.style.setProperty("--bg-color", "black");
root.style.setProperty("--bg-color-2", "black");
root.style.setProperty("--group-bg-color", "black");
root.style.setProperty("--bar-color", "black");
root.style.setProperty("--border", "rgb(50,50,50)");
} else if (theme === "cyber") {
const root = document.documentElement;
root.style.setProperty("--link", "rgb(225, 139, 9)");
root.style.setProperty("--text-color", "white");
root.style.setProperty("--shadow-color", "0px 5px 5px #42053f");
root.style.setProperty("--black-color", "black");
root.style.setProperty("--bg-color", "#0b023a");
root.style.setProperty("--bg-color-2", "#ff00a0");
root.style.setProperty("--group-bg-color", "rgba(48, 4, 98, 0.7)");
root.style.setProperty("--bar-color", "#12827e");
root.style.setProperty("--border", "rgb(50,50,50)");
} else if (theme === "custom") {
const root = document.documentElement;
let first = localStorage.getItem("first");
let second = localStorage.getItem("second");
document.documentElement.style.setProperty("--bg-color", first);
document.documentElement.style.setProperty("--bar-color", second);
document.documentElement.style.setProperty("--link", second);
document.documentElement.style.setProperty("--text-color", "white");
document.documentElement.style.setProperty("--black-color", "black");
root.style.setProperty("--shadow-color", "transparent");
root.style.setProperty("--bg-color-2", "white");
root.style.setProperty("--group-bg-color", second);
} else {
const root = document.documentElement;
root.style.setProperty("--text-color", "white");
root.style.setProperty("--link", "rgb(225, 139, 9)");
root.style.setProperty("--shadow-color", "transparent");
root.style.setProperty("--black-color", "black");
root.style.setProperty("--bg-color", "rgb(50, 50, 50)");
root.style.setProperty("--bg-color-2", "white");
root.style.setProperty("--group-bg-color", "rgba(40, 40, 40, 0.7)");
root.style.setProperty("--bar-color", "rgb(70, 70, 70)");
}
//Above is code for setting the theme
(adsbygoogle = window.adsbygoogle || []).push({});
//Above is code for Google Ads
});