mirror of
https://gitlab.com/skysthelimit.dev/selenite.git
synced 2025-06-16 02:22:07 -05:00
pinned games
This commit is contained in:
parent
df369b1284
commit
b8a04b602f
10
index.html
10
index.html
@ -1,7 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
||||
|
||||
|
||||
|
||||
<script src="/js/all.js"></script>
|
||||
<script src=" https://cdn.jsdelivr.net/npm/js-cookie@3.0.5/dist/js.cookie.min.js "></script>
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">
|
||||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
|
||||
|
||||
@ -51,7 +56,12 @@
|
||||
<p id="gamecounter"></p>
|
||||
<input type="text" id="gamesearch" placeholder="Type here to search.."> <br>
|
||||
<br>
|
||||
<div id="pinnedgames">
|
||||
<h2>Pinned Games</h2>
|
||||
<p id="message">Looks like you haven't pinned any games, click the star icon next to any game in order to pin them up here!</p>
|
||||
</div>
|
||||
<div id="games">
|
||||
<h2>All Games</h2>
|
||||
<p id="message">Please wait for the games to load.. If you see this for more than a second, try reloading and reporting a <a href="https://forms.gle/j75WUn6UhdqsRZgf7">bug report</a>.</p>
|
||||
</div>
|
||||
|
||||
|
90
js/games.js
90
js/games.js
@ -1,33 +1,91 @@
|
||||
$.getJSON("/games.json", function (data) {
|
||||
|
||||
starredgames = getCookie("starred");
|
||||
if(starredgames == "") {
|
||||
starredgames = []
|
||||
} else {
|
||||
starredgames = JSON.parse(starredgames)
|
||||
|
||||
}
|
||||
console.log(starredgames);
|
||||
$("#gamesearch").prop({placeholder: "Click here to search through our " + data.length + " games!"});
|
||||
data.sort(dynamicSort("name"));
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
$('#games').append(
|
||||
$('<div>').prop({
|
||||
id: 'game',
|
||||
style: 'cursor: pointer;',
|
||||
dir: data[i].directory
|
||||
}).append(
|
||||
$('<img>').prop({
|
||||
src: data[i].directory + "/" + data[i].image,
|
||||
alt: data[i].name + " logo"
|
||||
})
|
||||
).append(
|
||||
$('<h1>').text(data[i].name)
|
||||
)
|
||||
console.log("Loop iteration:", i);
|
||||
let $element = $('<div>').prop({
|
||||
class: 'game',
|
||||
style: 'cursor: pointer;',
|
||||
id: data[i].directory
|
||||
}).append(
|
||||
$('<img>').prop({
|
||||
src: data[i].directory + "/" + data[i].image,
|
||||
alt: data[i].name + " logo"
|
||||
})
|
||||
).append(
|
||||
$('<h1>').text(data[i].name)
|
||||
).append(
|
||||
$("<mat-icon>").prop({
|
||||
class: 'material-symbols-rounded'
|
||||
}).text("star")
|
||||
);
|
||||
|
||||
if (starredgames.includes(data[i].directory)) {
|
||||
$element.find("mat-icon").attr("id", "starred");
|
||||
let $pinnedelement = $element.clone();
|
||||
$('#pinnedgames').append($pinnedelement);
|
||||
if($("#pinnedgames #message")) {
|
||||
$("#pinnedgames #message").hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$('#games').append($element);
|
||||
|
||||
}
|
||||
$("#games #message").remove();
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).on("click", "#game", function(event) {
|
||||
redirectGame($(this).attr("dir"));
|
||||
let starred;
|
||||
$(document).on("click", ".game", function(event) {
|
||||
if($(event.target).is('mat-icon')) {
|
||||
if(!$(event.target).attr("id")) {
|
||||
$(event.target).prop({id: "starred"})
|
||||
starred = Cookies.get("starred")
|
||||
if(starred) {
|
||||
starred = JSON.parse(starred);
|
||||
} else {
|
||||
starred = []
|
||||
}
|
||||
starred.push($(this).attr("id"));
|
||||
Cookies.set("starred", JSON.stringify(starred));
|
||||
$element = $(this).clone();
|
||||
$('#pinnedgames').append($element);
|
||||
$("#pinnedgames #message").hide();
|
||||
} else {
|
||||
$(event.target).removeAttr("id");
|
||||
$thisdiv = '#' + $(this).attr("id")
|
||||
starred = Cookies.get("starred")
|
||||
starred = JSON.parse(starred);
|
||||
starred.pop(starred.indexOf($(this).attr("dir")), starred.indexOf($(this).attr("dir")));
|
||||
Cookies.set("starred", JSON.stringify(starred));
|
||||
$("#pinnedgames " + $thisdiv).remove();
|
||||
if(!$("#pinnedgames div") == "") {
|
||||
$("#pinnedgames #message").show();
|
||||
}
|
||||
$($thisdiv + " #starred").removeAttr("id");
|
||||
}
|
||||
} else {
|
||||
redirectGame($(this).attr("id"));
|
||||
}
|
||||
});
|
||||
$(document).on("click", "#game span", function(event) {
|
||||
$(this).prop({class: "material-symbols-outlined fill"})
|
||||
});
|
||||
});
|
||||
|
||||
function redirectGame(dir) {
|
||||
window.location.href = window.location.origin + "/" + dir + "/index.html";
|
||||
window.location.href = window.location.origin + "/" + dir + "/index.html";
|
||||
}
|
||||
function dynamicSort(property) {
|
||||
var sortOrder = 1;
|
||||
|
@ -1,8 +1,8 @@
|
||||
$(document).ready(function() {
|
||||
$('#gamesearch').on('input propertychange paste', function() {
|
||||
$('#games #game').hide();
|
||||
$('#games .game').hide();
|
||||
var txt = $('#gamesearch').val();
|
||||
$('#games #game').each(function(){
|
||||
$('#games .game').each(function(){
|
||||
if($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1){
|
||||
$(this).show();
|
||||
}
|
||||
|
31
style.css
31
style.css
@ -2,6 +2,7 @@ html {
|
||||
text-align: center;
|
||||
align-content: center;
|
||||
font-family: "Share Tech Mono", monospace;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.content {
|
||||
@ -39,8 +40,8 @@ button:hover {
|
||||
|
||||
|
||||
|
||||
#game {
|
||||
width: 10%;
|
||||
.game {
|
||||
width: 13%;
|
||||
display: inline-block;
|
||||
background-color: rgba(83, 118, 235, 0.4);
|
||||
padding: 1%;
|
||||
@ -51,18 +52,18 @@ button:hover {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#game:hover {
|
||||
.game:hover {
|
||||
background-color: rgba(113, 142, 238, 0.6);
|
||||
transform: scale(1.05);
|
||||
box-shadow: 0px 0px 5px 5px rgba(113, 142, 238, 0.6);
|
||||
}
|
||||
|
||||
#game h1 {
|
||||
.game h1 {
|
||||
float: right;
|
||||
font-size: 0.85em;
|
||||
color: rgb(149, 186, 241)
|
||||
}
|
||||
#game img {
|
||||
.game img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 10%;
|
||||
@ -209,3 +210,23 @@ h3 {
|
||||
cursor:pointer;
|
||||
opacity: 90%;
|
||||
}
|
||||
|
||||
.material-symbols-rounded {
|
||||
float: left;
|
||||
color: white;
|
||||
font-size: 1.9em;
|
||||
transition-duration: 0.75s;
|
||||
font-variation-settings:
|
||||
'FILL' 0,
|
||||
'wght' 400,
|
||||
'GRAD' 0,
|
||||
'opsz' 48
|
||||
}
|
||||
|
||||
#starred {
|
||||
font-variation-settings:
|
||||
'FILL' 1,
|
||||
'wght' 400,
|
||||
'GRAD' 0,
|
||||
'opsz' 48
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user