add random game button

This commit is contained in:
Sky 2023-07-29 15:41:56 -04:00
parent 776fe6e42a
commit fac33033d8
3 changed files with 25 additions and 0 deletions

View File

@ -63,6 +63,7 @@
<br /> <br />
<p id="gamecounter"></p> <p id="gamecounter"></p>
<input type="text" id="gamesearch" placeholder="Type here to search.." /> <input type="text" id="gamesearch" placeholder="Type here to search.." />
<button id="random" onclick="selectRandomGame()">Click to play a random game!</button>
<br /> <br />
<br /> <br />
<h2>Pinned Games</h2> <h2>Pinned Games</h2>

View File

@ -8,6 +8,7 @@ $.getJSON("/games.json", function (data) {
console.log(starredgames); console.log(starredgames);
$("#gamesearch").prop({ placeholder: "Click here to search through our " + data.length + " games!" }); $("#gamesearch").prop({ placeholder: "Click here to search through our " + data.length + " games!" });
data.sort(dynamicSort("name")); data.sort(dynamicSort("name"));
gamelist = data;
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
let $element = $("<div>") let $element = $("<div>")
.prop({ .prop({
@ -135,3 +136,22 @@ function dynamicSort(property) {
} }
}; };
} }
function selectRandomGame() {
randomgame = Math.floor(Math.random() * gamelist.length - 1);
Toastify({
text: 'You will be redirected to ' + gamelist[randomgame].name + ' in 3 seconds',
duration: 3000,
gravity: "top", // `top` or `bottom`
position: "center", // `left`, `center` or `right`
style: {
background: "linear-gradient(42deg, rgba(36, 69, 128, 1) 100%, rgb(24, 17, 87) 0%)",
width: "25%",
},
onClick: function () {}, // Callback after click
}).showToast();
setTimeout(() => {
redirectGame(gamelist[randomgame].directory);s
}, 3000);
}

View File

@ -232,3 +232,7 @@ h3 {
#starred { #starred {
font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 48; font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 48;
} }
#random {
padding: 0.8% 0.8%;
}