Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/layout/layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,23 @@ const moreGames = (() => {
>
</p>
</footer>
{
seo && slug && (
<script define:vars={{ slug, title: seo.title, image: seo.image }} is:inline>
try {
var k = "recently-played";
var r = [];
try {
r = JSON.parse(localStorage.getItem(k)) || [];
} catch {}
if (!Array.isArray(r)) r = [];
r = [{ s: slug, t: title, i: image }]
.concat(r.filter(function (x) { return x && x.s !== slug; }))
.slice(0, 10);
localStorage.setItem(k, JSON.stringify(r));
} catch {}
</script>
)
}
</body>
</html>
43 changes: 43 additions & 0 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,49 @@ const popularGames = defaultGames.slice(0, POPULAR_COUNT);
}
</div>

<section id="recent" hidden>
<h2 class="text-lg font-bold m-5 mb-2">Recently played</h2>
<div
id="recent-row"
class="grid grid-cols-[repeat(auto-fill,minmax(min(100%,280px),1fr))] gap-[10px]"
>
</div>
<hr class="mx-5 my-4 border-gray-400" />
</section>
<script is:inline define:vars={{ valid: defaultGames }}>
(function () {
try {
var r = JSON.parse(localStorage.getItem("recently-played") || "[]");
if (!Array.isArray(r) || !r.length) return;
var sec = document.getElementById("recent");
var row = document.getElementById("recent-row");
r.slice(0, 10).forEach(function (g) {
if (!g || !g.s || !g.t || !g.i || valid.indexOf(g.s) < 0) return;
var a = document.createElement("a");
a.href = "/games/" + g.s;
a.setAttribute("data-astro-prefetch", "");
a.className = "m-5 inline-block max-w-full text-center no-underline";
var img = document.createElement("img");
img.src = g.i;
img.alt = g.t + " unblocked - play online free";
img.width = 300;
img.height = 200;
img.loading = "lazy";
img.decoding = "async";
img.className =
"aspect-[3/2] h-auto w-full max-w-[300px] rounded-xl transition-transform duration-300 hover:scale-105 hover:shadow-lg active:scale-95 transform";
var p = document.createElement("p");
p.className = "text-gray-800 transition-colors hover:text-black";
p.textContent = g.t;
a.appendChild(img);
a.appendChild(p);
row.appendChild(a);
});
if (row.children.length) sec.hidden = false;
} catch {}
})();
</script>

<h2 class="sr-only">All unblocked games</h2>
<div class="grid grid-cols-[repeat(auto-fill,minmax(min(100%,280px),1fr))] gap-[10px]">
{
Expand Down
Loading