studyable-math 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin.html +227 -0
- package/ai.html +77 -0
- package/games-data.js +1 -0
- package/games.html +88 -0
- package/games.js +173 -0
- package/home.html +84 -0
- package/index.html +28 -0
- package/package.json +24 -6
- package/rug-catalog.js +212 -0
- package/settings.html +43 -0
- package/settings.js +243 -0
- package/style.css +243 -0
- package/README.md +0 -3
package/games.html
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Games</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="achroma-shell">
|
|
11
|
+
<aside class="side-rail">
|
|
12
|
+
<a class="rail-logo" href="home.html" title="Home">ภ</a>
|
|
13
|
+
<a class="rail-btn" href="home.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 11.5 12 4l9 7.5"/><path d="M5 10v10h14V10"/></svg><span>Home</span></a>
|
|
14
|
+
<a class="rail-btn active" href="games.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="7" width="18" height="11" rx="5"/><path d="M8 11v3M6.5 12.5h3M15 12h.01M18 13h.01"/></svg><span>Games</span></a>
|
|
15
|
+
<a class="rail-btn" href="ai.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 3l1.8 4.7L18.5 9l-4.7 1.8L12 15.5l-1.8-4.7L5.5 9l4.7-1.3L12 3z"/><path d="M19 15l.8 2 2 .8-2 .8-.8 2-.8-2-2-.8 2-.8.8-2z"/></svg><span>AI</span></a>
|
|
16
|
+
<a class="rail-btn" href="settings.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19 12a7 7 0 0 0-.1-1l2-1.5-2-3.4-2.3 1a7 7 0 0 0-1.7-1L14.5 3h-5l-.4 2.6a7 7 0 0 0-1.7 1l-2.3-1-2 3.4 2 1.5a7 7 0 0 0 0 2l-2 1.5 2 3.4 2.3-1a7 7 0 0 0 1.7 1l.4 2.6h5l.4-2.6a7 7 0 0 0 1.7-1l2.3 1 2-3.4-2-1.5c.07-.33.1-.66.1-1z"/></svg><span>Settings</span></a>
|
|
17
|
+
<div class="rail-spacer"></div>
|
|
18
|
+
</aside>
|
|
19
|
+
|
|
20
|
+
<main class="main-pane">
|
|
21
|
+
<div class="top-shortcuts">
|
|
22
|
+
<a class="shortcut" href="https://www.youtube.com" target="_blank" rel="noopener" title="YouTube"><svg viewBox="0 0 24 24" fill="#ff0033"><path d="M23 12s0-3.8-.5-5.6a2.9 2.9 0 0 0-2-2C18.6 4 12 4 12 4s-6.6 0-8.5.4a2.9 2.9 0 0 0-2 2C1 8.2 1 12 1 12s0 3.8.5 5.6a2.9 2.9 0 0 0 2 2c1.9.4 8.5.4 8.5.4s6.6 0 8.5-.4a2.9 2.9 0 0 0 2-2c.5-1.8.5-5.6.5-5.6zM9.8 15.5v-7l6 3.5-6 3.5z"/></svg></a>
|
|
23
|
+
<a class="shortcut" href="https://discord.com" target="_blank" rel="noopener" title="Discord"><svg viewBox="0 0 24 24" fill="#5865f2"><path d="M20 4.5A18.5 18.5 0 0 0 15.6 3l-.6 1.2a17 17 0 0 0-6 0L8.4 3A18.5 18.5 0 0 0 4 4.5C1.4 8.6.8 12.6 1.1 16.6A18.7 18.7 0 0 0 6.6 19l1.3-2.1a12 12 0 0 1-1.9-.9l.4-.3a13.4 13.4 0 0 0 11.2 0l.4.3c-.6.4-1.2.7-1.9.9L17.4 19a18.7 18.7 0 0 0 5.5-2.4c.4-4.5-.7-8.5-2.9-12.1zM8.7 14.3c-1.1 0-2-1-2-2.2s.9-2.2 2-2.2 2 1 2 2.2-.9 2.2-2 2.2zm6.6 0c-1.1 0-2-1-2-2.2s.9-2.2 2-2.2 2 1 2 2.2-.9 2.2-2 2.2z"/></svg></a>
|
|
24
|
+
<a class="shortcut" href="https://open.spotify.com" target="_blank" rel="noopener" title="Spotify"><svg viewBox="0 0 24 24" fill="#1ed760"><path d="M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm4.6 14.4a.6.6 0 0 1-.8.2c-2.3-1.4-5.2-1.7-8.6-.9a.6.6 0 1 1-.3-1.2c3.7-.9 6.9-.5 9.5 1a.6.6 0 0 1 .2.9zm1.2-2.8a.75.75 0 0 1-1 .25c-2.6-1.6-6.6-2.1-9.7-1.1a.75.75 0 1 1-.4-1.4c3.5-1.1 8-.5 11 1.3.3.2.4.6.1 1zm.1-2.9C15.2 8.9 9.7 8.7 6.3 9.6a1 1 0 1 1-.6-1.9c3.9-1.2 9.9-1 13.7 1.3a1 1 0 0 1-1 1.7z"/></svg></a>
|
|
25
|
+
<a class="shortcut" href="https://www.instagram.com" target="_blank" rel="noopener" title="Instagram"><svg viewBox="0 0 24 24" fill="none" stroke="url(#ig)" stroke-width="2"><defs><linearGradient id="ig" x1="0" y1="1" x2="1" y2="0"><stop stop-color="#feda75"/><stop offset=".5" stop-color="#d62976"/><stop offset="1" stop-color="#4f5bd5"/></linearGradient></defs><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="url(#ig)" stroke="none"/></svg></a>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<div class="pane-scroll">
|
|
29
|
+
<section class="achroma-search">
|
|
30
|
+
<div class="pane-title">Games</div>
|
|
31
|
+
<div class="search-box">
|
|
32
|
+
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>
|
|
33
|
+
<input id="gameSearch" type="search" placeholder="Search games…" autocomplete="off" aria-label="Search games">
|
|
34
|
+
<span class="search-count" id="searchCount"></span>
|
|
35
|
+
</div>
|
|
36
|
+
</section>
|
|
37
|
+
<div class="chips" id="chips"></div>
|
|
38
|
+
<section class="game-grid achroma-grid" id="gameGrid"></section>
|
|
39
|
+
<div class="empty-state hidden" id="emptyState">No games match that search.</div>
|
|
40
|
+
<button class="btn btn-ghost show-more hidden" id="showMore" type="button">Show more</button>
|
|
41
|
+
</div>
|
|
42
|
+
</main>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<nav class="bottom-menu">
|
|
46
|
+
<a href="home.html">Home</a>
|
|
47
|
+
<a class="active" href="games.html">Games</a>
|
|
48
|
+
<a href="ai.html">AI</a>
|
|
49
|
+
<a href="settings.html">Settings</a>
|
|
50
|
+
</nav>
|
|
51
|
+
|
|
52
|
+
<section class="player hidden" id="player">
|
|
53
|
+
<div class="player-bar">
|
|
54
|
+
<button class="icon-btn" id="gpBack" type="button" title="Back">←</button>
|
|
55
|
+
<h3 id="gpTitle">Game</h3>
|
|
56
|
+
<div class="player-actions">
|
|
57
|
+
<button class="icon-btn" id="gpReload" type="button" title="Reload">⟳</button>
|
|
58
|
+
<button class="icon-btn" id="gpFullscreen" type="button" title="Fullscreen">⛶</button>
|
|
59
|
+
<button class="icon-btn" id="gpClose" type="button" title="Close">✕</button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
<div class="player-frame-wrap" id="playerFrameWrap">
|
|
63
|
+
<div class="gp-loader" id="gpLoader">
|
|
64
|
+
<div class="loader-box">
|
|
65
|
+
<div class="loader-art" id="gpArt"><svg viewBox="0 0 24 24" width="54" height="54" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="11" rx="5"/><path d="M8 11v3M6.5 12.5h3M15 12h.01M18 13h.01"/></svg></div>
|
|
66
|
+
<div id="gpLoadName" style="font-weight:900;font-size:18px">Loading game</div>
|
|
67
|
+
<div class="loader-bar"><div class="loader-fill" id="gpBarFill"></div></div>
|
|
68
|
+
<div class="loader-status" id="gpLoadStatus">Connecting…</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
<iframe id="gpFrame" title="Game player" allow="autoplay; fullscreen; gamepad; clipboard-write"></iframe>
|
|
72
|
+
<div class="unavailable hidden" id="gpUnavailable">
|
|
73
|
+
<div>
|
|
74
|
+
<div style="font-size:48px;margin-bottom:10px">!</div>
|
|
75
|
+
<h3 id="guTitle">Unavailable</h3>
|
|
76
|
+
<p class="muted">This game could not be loaded from the mirrors.</p>
|
|
77
|
+
<button class="btn btn-primary" id="guRetry" type="button">Retry</button>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</section>
|
|
82
|
+
|
|
83
|
+
<script src="games-data.js"></script>
|
|
84
|
+
<script src="rug-catalog.js"></script>
|
|
85
|
+
<script src="games.js"></script>
|
|
86
|
+
<script src="settings.js"></script>
|
|
87
|
+
</body>
|
|
88
|
+
</html>
|
package/games.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const $ = s => document.querySelector(s);
|
|
3
|
+
const $$ = s => [...document.querySelectorAll(s)];
|
|
4
|
+
|
|
5
|
+
/* Secret entrance gate (password is checked on index.html) */
|
|
6
|
+
const PHK_PARAMS=new URLSearchParams(location.search);
|
|
7
|
+
if(PHK_PARAMS.get('secret')==='1') sessionStorage.setItem('phk_secret','1');
|
|
8
|
+
if(!sessionStorage.getItem('phk_secret')) location.replace('index.html');
|
|
9
|
+
|
|
10
|
+
function phkSettings(){try{return JSON.parse(localStorage.getItem('phk_settings')||'{}')}catch{return{}}}
|
|
11
|
+
|
|
12
|
+
/* ---------- catalog ---------- */
|
|
13
|
+
let RAW_GAMES=[];
|
|
14
|
+
let games=[];
|
|
15
|
+
let byId=new Map();
|
|
16
|
+
let activeCat='All';
|
|
17
|
+
let query=PHK_PARAMS.get('q')||'';
|
|
18
|
+
let shown=phkSettings().initialCount??180;
|
|
19
|
+
let loadCtl=null,loadTextTimer=null;
|
|
20
|
+
const LOAD_PHRASES=['triple t is my poookie..','me is black','loading the good parts','almost there','one sec','gimme a moment','booting the fun','hold on','almost ready','stay black','loading...'];
|
|
21
|
+
function pickPhrase(){const S=phkSettings();if(S.phraseMode==='off')return "";if(S.phraseMode==='fixed')return S.fixedPhrase||LOAD_PHRASES[0];return LOAD_PHRASES[Math.floor(Math.random()*LOAD_PHRASES.length)]}
|
|
22
|
+
function startLoaderText(){stopLoaderText();const el=$('#gpLoadName'),mode=phkSettings().loaderTitleMode||'phrase';if(mode==='game'){el.textContent=current?current.title:"";return}if(mode==='off'){el.textContent="";return}el.textContent=pickPhrase();const iv=phkSettings().phraseInterval??1400;loadTextTimer=setInterval(()=>{if(!player.classList.contains('hidden'))el.textContent=pickPhrase()},iv)}
|
|
23
|
+
function stopLoaderText(){if(loadTextTimer){clearInterval(loadTextTimer);loadTextTimer=null}}
|
|
24
|
+
const searchInput=$('#gameSearch');
|
|
25
|
+
if(searchInput)searchInput.value=query;
|
|
26
|
+
|
|
27
|
+
function esc(s){return String(s??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]))}
|
|
28
|
+
|
|
29
|
+
async function init(){
|
|
30
|
+
const data=await window.RUG.ready;
|
|
31
|
+
RAW_GAMES=data.games||[];
|
|
32
|
+
games=RAW_GAMES.map(r=>({...r,title:r.name||r.id,cat:r.tag||'Arcade',logo:window.RUG.logo(r)}));
|
|
33
|
+
games.forEach(g=>byId.set(g.id,g));
|
|
34
|
+
shown=phkSettings().initialCount??shown;
|
|
35
|
+
window.RUG.gameCache.KEEP=phkSettings().cacheLimit??12;
|
|
36
|
+
buildChips();
|
|
37
|
+
render();
|
|
38
|
+
const play=PHK_PARAMS.get('play');
|
|
39
|
+
if(play&&byId.has(play))setTimeout(()=>openGame(play),250);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* ---------- chips/search/render ---------- */
|
|
43
|
+
function buildChips(){
|
|
44
|
+
const counts={};
|
|
45
|
+
games.forEach(g=>counts[g.cat]=(counts[g.cat]||0)+1);
|
|
46
|
+
const cats=Object.keys(counts).sort((a,b)=>counts[b]-counts[a]);
|
|
47
|
+
$('#chips').innerHTML=['All',...cats].map(c=>`<button class="chip ${c===activeCat?'active':''}" data-cat="${esc(c)}">${esc(c)} <span style="opacity:.65">${c==='All'?games.length:counts[c]}</span></button>`).join('');
|
|
48
|
+
$$('#chips .chip').forEach(b=>b.addEventListener('click',()=>{activeCat=b.dataset.cat;shown=phkSettings().initialCount??180;buildChips();render();}));
|
|
49
|
+
}
|
|
50
|
+
function filtered(){
|
|
51
|
+
const q=query.trim().toLowerCase();
|
|
52
|
+
const out=games.filter(g=>{
|
|
53
|
+
const catOk=activeCat==='All'||g.cat===activeCat;
|
|
54
|
+
if(!catOk)return false;
|
|
55
|
+
if(!q)return true;
|
|
56
|
+
return (g.title+' '+g.cat+' '+(g.desc||'')+' '+g.id).toLowerCase().includes(q);
|
|
57
|
+
});
|
|
58
|
+
const sort=phkSettings().sortBy||'catalog';
|
|
59
|
+
if(sort==='az')out.sort((a,b)=>a.title.localeCompare(b.title));
|
|
60
|
+
if(sort==='za')out.sort((a,b)=>b.title.localeCompare(a.title));
|
|
61
|
+
if(sort==='size')out.sort((a,b)=>(b.size||0)-(a.size||0));
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function gameMeta(g){
|
|
65
|
+
const S=phkSettings();
|
|
66
|
+
if(!(S.showNames||S.showDescriptions||S.showTags))return "";
|
|
67
|
+
let h='<div class="game-meta">';
|
|
68
|
+
if(S.showNames)h+=`<div class="game-name">${esc(g.title)}</div>`;
|
|
69
|
+
if(S.showTags)h+=`<span class="game-tag">${esc(g.cat)}</span>`;
|
|
70
|
+
if(S.showDescriptions)h+=`<div class="game-desc" style="margin-top:4px">${esc(g.desc||"")}</div>`;
|
|
71
|
+
return h+"</div>";
|
|
72
|
+
}
|
|
73
|
+
function render(){
|
|
74
|
+
const S=phkSettings();
|
|
75
|
+
const list=filtered();
|
|
76
|
+
const slice=list.slice(0,shown);
|
|
77
|
+
$('#searchCount').textContent=list.length===games.length?`${games.length} games`:`${list.length} / ${games.length}`;
|
|
78
|
+
$('#emptyState').classList.toggle('hidden',list.length>0);
|
|
79
|
+
$('#showMore').classList.toggle('hidden',list.length<=shown);
|
|
80
|
+
$('#gameGrid').innerHTML=slice.map((g,i)=>`
|
|
81
|
+
<article class="game-card achroma-card" data-id="${esc(g.id)}" title="${esc(g.title)}" aria-label="${esc(g.title)}" style="animation-delay:${Math.min(i*(S.stagger??18),700)}ms">
|
|
82
|
+
<div class="game-thumb">
|
|
83
|
+
${g.logo?`<img src="${esc(g.logo)}" alt="" loading="lazy" decoding="async" onerror="this.remove()">`:''}
|
|
84
|
+
</div>
|
|
85
|
+
${gameMeta(g)}
|
|
86
|
+
</article>`).join('');
|
|
87
|
+
$$('#gameGrid .game-card').forEach(c=>c.addEventListener('click',()=>openGame(c.dataset.id)));
|
|
88
|
+
}
|
|
89
|
+
$('#gameSearch').addEventListener('input',e=>{query=e.target.value;shown=phkSettings().initialCount??180;render();});
|
|
90
|
+
$('#showMore').addEventListener('click',()=>{shown+=(phkSettings().showMoreStep??240);render();});
|
|
91
|
+
|
|
92
|
+
/* ---------- player ---------- */
|
|
93
|
+
const player=$('#player'), loader=$('#gpLoader'), unavail=$('#gpUnavailable');
|
|
94
|
+
let frame=$('#gpFrame'), current=null;
|
|
95
|
+
function freshFrame(){const f=frame.cloneNode(false);frame.replaceWith(f);frame=f;f.onload=null;return f}
|
|
96
|
+
function setStatus(t){$('#gpLoadStatus').textContent=t}
|
|
97
|
+
function setFill(p){$('#gpBarFill').style.width=Math.min(100,p)+'%'}
|
|
98
|
+
function stopLoad(){if(loadCtl){loadCtl.controller.abort();loadCtl=null}}
|
|
99
|
+
function closePlayer(){stopLoaderText();player.classList.add('hidden');document.body.style.overflow='';stopLoad();freshFrame();unavail.classList.add('hidden');loader.classList.remove('done')}
|
|
100
|
+
function openGame(id){
|
|
101
|
+
const g=byId.get(id);if(!g)return;
|
|
102
|
+
current=g;
|
|
103
|
+
$('#gpTitle').textContent=g.title;
|
|
104
|
+
loader.classList.remove('done');unavail.classList.add('hidden');
|
|
105
|
+
frame.removeAttribute('srcdoc');frame.removeAttribute('src');frame.style.display='block';
|
|
106
|
+
freshFrame();player.classList.remove('hidden');document.body.style.overflow='hidden';
|
|
107
|
+
stopLoad();startLoaderText();playRug(g);
|
|
108
|
+
if(phkSettings().autoFullscreen)$('#playerFrameWrap').requestFullscreen?.().catch(()=>{});
|
|
109
|
+
}
|
|
110
|
+
async function playRug(g){
|
|
111
|
+
const r=g; // catalog entries are already RUG records
|
|
112
|
+
const controller=new AbortController();loadCtl={controller,id:g.id};
|
|
113
|
+
setStatus('Connecting…');setFill(8);
|
|
114
|
+
const urls=window.RUG.urls(r),total=r.size||1,loaded=new Array(urls.length).fill(0);
|
|
115
|
+
const update=()=>{const got=loaded.reduce((a,b)=>a+b,0);setFill(total?got/total*100:35);setStatus(r.size?`${window.RUG.fmtMB(got)} / ${window.RUG.fmtMB(total)}${urls.length>1?` · ${urls.length} parts`:''}`:`${window.RUG.fmtMB(got)} loaded`)};
|
|
116
|
+
try{
|
|
117
|
+
const cached=await window.RUG.gameCache.get(urls[0]);
|
|
118
|
+
if(cached&&phkSettings().keepCache!==false&&loadCtl?.id===g.id){setStatus('Starting (saved copy)…');setFill(100);startHtml(g,await cached.text());return}
|
|
119
|
+
const pieces=await Promise.all(urls.map(async(url,i)=>{
|
|
120
|
+
const sources=window.RUG.mirrors(url);let lastErr;
|
|
121
|
+
for(let attempt=0;attempt<sources.length;attempt++){
|
|
122
|
+
if(controller.signal.aborted)throw new DOMException('Aborted','AbortError');
|
|
123
|
+
if(attempt){setStatus(`Connection hiccup, trying backup ${attempt} of ${sources.length-1}…`);await new Promise(r=>setTimeout(r,600*attempt))}
|
|
124
|
+
loaded[i]=0;const attemptCtl=new AbortController();const stop=()=>attemptCtl.abort();
|
|
125
|
+
controller.signal.addEventListener('abort',stop);
|
|
126
|
+
let stall=setTimeout(stop,6000);const progress=()=>{clearTimeout(stall);stall=setTimeout(stop,15000)};
|
|
127
|
+
try{
|
|
128
|
+
const res=await fetch(sources[attempt],{signal:attemptCtl.signal});
|
|
129
|
+
if(!res.ok)throw new Error(`HTTP ${res.status}`);
|
|
130
|
+
progress();
|
|
131
|
+
if(!res.body){const b=await res.arrayBuffer();loaded[i]=b.byteLength;update();return[b]}
|
|
132
|
+
const reader=res.body.getReader(),chunks=[];
|
|
133
|
+
for(;;){const{done,value}=await reader.read();if(done)break;progress();chunks.push(value);loaded[i]+=value.byteLength;update()}
|
|
134
|
+
return chunks;
|
|
135
|
+
}catch(err){
|
|
136
|
+
if(controller.signal.aborted)throw new DOMException('Aborted','AbortError');
|
|
137
|
+
lastErr=err.name==='AbortError'?new Error('the download stalled'):err;
|
|
138
|
+
}finally{clearTimeout(stall);controller.signal.removeEventListener('abort',stop)}
|
|
139
|
+
}
|
|
140
|
+
throw lastErr;
|
|
141
|
+
}));
|
|
142
|
+
if(loadCtl?.id!==g.id)return;
|
|
143
|
+
setStatus('Starting…');setFill(100);
|
|
144
|
+
const blob=new Blob(pieces.flat());window.RUG.gameCache.put(urls[0],blob);
|
|
145
|
+
startHtml(g,await blob.text());
|
|
146
|
+
}catch(err){
|
|
147
|
+
if(err.name==='AbortError')return;
|
|
148
|
+
stopLoaderText();console.error(err);setStatus(`Couldn't load this game (${err.message}).`);setFill(100);
|
|
149
|
+
setTimeout(()=>unavail.classList.remove('hidden'),350);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function startHtml(g,html){
|
|
153
|
+
if(loadCtl?.id!==g.id)return;
|
|
154
|
+
stopLoaderText();$('#gpLoadName').textContent='Ready';
|
|
155
|
+
if(g.src==='gn')html=window.RUG.stripTracking(html);
|
|
156
|
+
html=window.RUG.guardHistory(window.RUG.pinCdn(html),window.RUG.base(g));
|
|
157
|
+
const f=freshFrame(),doc=f.contentDocument;doc.open();doc.write(html);doc.close();
|
|
158
|
+
loader.classList.add('done');
|
|
159
|
+
f.addEventListener('load',()=>setTimeout(()=>loader.classList.add('done'),400),{once:true});
|
|
160
|
+
setTimeout(()=>loader.classList.add('done'),12000);
|
|
161
|
+
try{f.contentWindow.focus()}catch(_){}
|
|
162
|
+
}
|
|
163
|
+
$('#gpBack').addEventListener('click',closePlayer);
|
|
164
|
+
$('#gpClose').addEventListener('click',closePlayer);
|
|
165
|
+
$('#guRetry').addEventListener('click',()=>current&&openGame(current.id));
|
|
166
|
+
$('#gpReload').addEventListener('click',()=>current&&openGame(current.id));
|
|
167
|
+
$('#gpFullscreen').addEventListener('click',()=>{
|
|
168
|
+
if(!document.fullscreenElement)$('#playerFrameWrap').requestFullscreen?.().catch(()=>{});
|
|
169
|
+
else document.exitFullscreen();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/* ---------- boot ---------- */
|
|
173
|
+
window.RUG.ready.then(init).catch(err=>{console.error(err);$('#gameGrid').innerHTML='<div class="empty-state">Catalog failed to load.</div>'});
|
package/home.html
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Games</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="snow" id="snow"></div>
|
|
11
|
+
<div class="achroma-shell">
|
|
12
|
+
<aside class="side-rail">
|
|
13
|
+
<a class="rail-logo" href="home.html" title="Home">ภ</a>
|
|
14
|
+
<a class="rail-btn active" href="home.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 11.5 12 4l9 7.5"/><path d="M5 10v10h14V10"/></svg><span>Home</span></a>
|
|
15
|
+
<a class="rail-btn" href="games.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="7" width="18" height="11" rx="5"/><path d="M8 11v3M6.5 12.5h3M15 12h.01M18 13h.01"/></svg><span>Games</span></a>
|
|
16
|
+
<a class="rail-btn" href="ai.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 3l1.8 4.7L18.5 9l-4.7 1.8L12 15.5l-1.8-4.7L5.5 9l4.7-1.3L12 3z"/><path d="M19 15l.8 2 2 .8-2 .8-.8 2-.8-2-2-.8 2-.8.8-2z"/></svg><span>AI</span></a>
|
|
17
|
+
<a class="rail-btn" href="settings.html"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19 12a7 7 0 0 0-.1-1l2-1.5-2-3.4-2.3 1a7 7 0 0 0-1.7-1L14.5 3h-5l-.4 2.6a7 7 0 0 0-1.7 1l-2.3-1-2 3.4 2 1.5a7 7 0 0 0 0 2l-2 1.5 2 3.4 2.3-1a7 7 0 0 0 1.7 1l.4 2.6h5l.4-2.6a7 7 0 0 0 1.7-1l2.3 1 2-3.4-2-1.5c.07-.33.1-.66.1-1z"/></svg><span>Settings</span></a>
|
|
18
|
+
<div class="rail-spacer"></div>
|
|
19
|
+
</aside>
|
|
20
|
+
|
|
21
|
+
<main class="main-pane">
|
|
22
|
+
<div class="top-shortcuts">
|
|
23
|
+
<a class="shortcut" href="https://www.youtube.com" target="_blank" rel="noopener" title="YouTube"><svg viewBox="0 0 24 24" fill="#ff0033"><path d="M23 12s0-3.8-.5-5.6a2.9 2.9 0 0 0-2-2C18.6 4 12 4 12 4s-6.6 0-8.5.4a2.9 2.9 0 0 0-2 2C1 8.2 1 12 1 12s0 3.8.5 5.6a2.9 2.9 0 0 0 2 2c1.9.4 8.5.4 8.5.4s6.6 0 8.5-.4a2.9 2.9 0 0 0 2-2c.5-1.8.5-5.6.5-5.6zM9.8 15.5v-7l6 3.5-6 3.5z"/></svg></a>
|
|
24
|
+
<a class="shortcut" href="https://discord.com" target="_blank" rel="noopener" title="Discord"><svg viewBox="0 0 24 24" fill="#5865f2"><path d="M20 4.5A18.5 18.5 0 0 0 15.6 3l-.6 1.2a17 17 0 0 0-6 0L8.4 3A18.5 18.5 0 0 0 4 4.5C1.4 8.6.8 12.6 1.1 16.6A18.7 18.7 0 0 0 6.6 19l1.3-2.1a12 12 0 0 1-1.9-.9l.4-.3a13.4 13.4 0 0 0 11.2 0l.4.3c-.6.4-1.2.7-1.9.9L17.4 19a18.7 18.7 0 0 0 5.5-2.4c.4-4.5-.7-8.5-2.9-12.1zM8.7 14.3c-1.1 0-2-1-2-2.2s.9-2.2 2-2.2 2 1 2 2.2-.9 2.2-2 2.2zm6.6 0c-1.1 0-2-1-2-2.2s.9-2.2 2-2.2 2 1 2 2.2-.9 2.2-2 2.2z"/></svg></a>
|
|
25
|
+
<a class="shortcut" href="https://open.spotify.com" target="_blank" rel="noopener" title="Spotify"><svg viewBox="0 0 24 24" fill="#1ed760"><path d="M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20zm4.6 14.4a.6.6 0 0 1-.8.2c-2.3-1.4-5.2-1.7-8.6-.9a.6.6 0 1 1-.3-1.2c3.7-.9 6.9-.5 9.5 1a.6.6 0 0 1 .2.9zm1.2-2.8a.75.75 0 0 1-1 .25c-2.6-1.6-6.6-2.1-9.7-1.1a.75.75 0 1 1-.4-1.4c3.5-1.1 8-.5 11 1.3.3.2.4.6.1 1zm.1-2.9C15.2 8.9 9.7 8.7 6.3 9.6a1 1 0 1 1-.6-1.9c3.9-1.2 9.9-1 13.7 1.3a1 1 0 0 1-1 1.7z"/></svg></a>
|
|
26
|
+
<a class="shortcut" href="https://www.instagram.com" target="_blank" rel="noopener" title="Instagram"><svg viewBox="0 0 24 24" fill="none" stroke="url(#ig)" stroke-width="2"><defs><linearGradient id="ig" x1="0" y1="1" x2="1" y2="0"><stop stop-color="#feda75"/><stop offset=".5" stop-color="#d62976"/><stop offset="1" stop-color="#4f5bd5"/></linearGradient></defs><rect x="3" y="3" width="18" height="18" rx="5"/><circle cx="12" cy="12" r="4"/><circle cx="17.5" cy="6.5" r="1" fill="url(#ig)" stroke="none"/></svg></a>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div class="pane-scroll">
|
|
30
|
+
<div class="home-hero">
|
|
31
|
+
<div class="pane-title">ภคՇђคภ's games</div>
|
|
32
|
+
<section class="achroma-search">
|
|
33
|
+
<div class="search-box">
|
|
34
|
+
<svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/></svg>
|
|
35
|
+
<input id="homeSearch" type="search" placeholder="Search games…" autocomplete="off" aria-label="Search games">
|
|
36
|
+
</div>
|
|
37
|
+
</section>
|
|
38
|
+
<div class="shortcut-grid" id="homeApps">
|
|
39
|
+
<a class="home-shortcut" href="games.html?play=baldis-basics"><span class="app-icon"><img src="https://cdn.jsdelivr.net/npm/@ywkrlerche/richardwho/logos/gn-466.webp" alt="" loading="lazy"></span><span class="app-label">Baldis Basics</span></a>
|
|
40
|
+
<a class="home-shortcut" href="games.html?play=crazy-motorcycle"><span class="app-icon"><img src="https://cdn.jsdelivr.net/npm/@ywkrlerche/richardwho/logos/crazy-motorcycle.webp" alt="" loading="lazy"></span><span class="app-label">Crazy Motorcycle</span></a>
|
|
41
|
+
<a class="home-shortcut" href="games.html?play=monkey-mart"><span class="app-icon"><img src="https://cdn.jsdelivr.net/npm/@ywkrlerche/richardwho/logos/monkey-mart.webp" alt="" loading="lazy"></span><span class="app-label">Monkey Mart</span></a>
|
|
42
|
+
<a class="home-shortcut" href="games.html?play=crazy-cars"><span class="app-icon"><img src="https://cdn.jsdelivr.net/npm/@ywkrlerche/richardwho/logos/crazy-cars.webp" alt="" loading="lazy"></span><span class="app-label">Crazy Cars</span></a>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</main>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<nav class="bottom-menu">
|
|
50
|
+
<a class="active" href="home.html">Home</a>
|
|
51
|
+
<a href="games.html">Games</a>
|
|
52
|
+
<a href="ai.html">AI</a>
|
|
53
|
+
<a href="settings.html">Settings</a>
|
|
54
|
+
</nav>
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
if(!sessionStorage.getItem('phk_secret'))location.replace('index.html');
|
|
58
|
+
const S=(()=>{try{return JSON.parse(localStorage.getItem('phk_settings')||'{}')}catch{return{}}})();
|
|
59
|
+
const titleEl=document.querySelector('.pane-title');if(S.homeTitle)titleEl.textContent=S.homeTitle;
|
|
60
|
+
const homeSearch=document.getElementById('homeSearch');if(S.homeSearchPlaceholder)homeSearch.placeholder=S.homeSearchPlaceholder;
|
|
61
|
+
if(S.homeApps==='none')document.getElementById('homeApps').style.display='none';
|
|
62
|
+
const snow=document.getElementById('snow'),frag=document.createDocumentFragment();
|
|
63
|
+
const snowOn=S.snowEnable!==false,count=snowOn?Math.max(0,S.snowCount??90):0;
|
|
64
|
+
const base=S.snowSize??3,bigSize=S.snowBigSize??14,op=(S.snowOpacity??55)/100,color=S.snowColor||'#fff',drift=S.snowDrift??90;
|
|
65
|
+
for(let i=0;i<count;i++){
|
|
66
|
+
const f=document.createElement('i'),big=Math.random()<.16;
|
|
67
|
+
f.className='flake'+(big?' big':'');
|
|
68
|
+
const size=big?bigSize*(0.7+Math.random()*0.6):base*(0.6+Math.random()*0.8);
|
|
69
|
+
f.style.width=f.style.height=size+'px';
|
|
70
|
+
f.style.background=color;
|
|
71
|
+
f.style.setProperty('--x',Math.random()*100+'%');
|
|
72
|
+
f.style.setProperty('--drift',(Math.random()*2-1)*drift+'px');
|
|
73
|
+
f.style.animationDuration=(big?24+Math.random()*18:14+Math.random()*16)+'s';
|
|
74
|
+
f.style.animationDelay=(-Math.random()*40)+'s';
|
|
75
|
+
f.style.opacity=(op*(0.4+Math.random()*0.6)).toFixed(2);
|
|
76
|
+
frag.appendChild(f);
|
|
77
|
+
}
|
|
78
|
+
snow.appendChild(frag);
|
|
79
|
+
homeSearch.addEventListener('keydown',e=>{if(e.key==='Enter'){const q=homeSearch.value.trim();location.href=q?`games.html?q=${encodeURIComponent(q)}`:'games.html'}});
|
|
80
|
+
homeSearch.addEventListener('search',()=>{const q=homeSearch.value.trim();if(q)location.href=`games.html?q=${encodeURIComponent(q)}`});
|
|
81
|
+
</script>
|
|
82
|
+
<script src="settings.js"></script>
|
|
83
|
+
</body>
|
|
84
|
+
</html>
|
package/index.html
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>Games</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<main class="login-wrap" style="min-height:100vh;display:grid;place-items:center;padding:20px">
|
|
11
|
+
<section class="card login-card" style="width:min(430px,100%)">
|
|
12
|
+
<div class="brand" style="justify-content:center;margin-bottom:18px"><span class="brand-mark">ภ</span><span>Games</span></div>
|
|
13
|
+
<h1 style="text-align:center;margin:0 0 8px">Enter password</h1>
|
|
14
|
+
<p style="text-align:center;color:var(--muted);margin:0 0 20px">Username + password required.</p>
|
|
15
|
+
<form id="gateForm" autocomplete="off">
|
|
16
|
+
<div class="field"><label for="gUser">Username</label><input id="gUser" type="text" placeholder="student" required></div>
|
|
17
|
+
<div class="field"><label for="gPass">Password</label><div class="pass-wrap"><input id="gPass" type="password" placeholder="••••••••" required><button type="button" class="pass-toggle" id="passToggle">Show</button></div></div>
|
|
18
|
+
<div class="err" id="gateErr"></div>
|
|
19
|
+
<button class="btn btn-primary" style="width:100%" type="submit">Enter</button>
|
|
20
|
+
</form>
|
|
21
|
+
</section>
|
|
22
|
+
</main>
|
|
23
|
+
<script>
|
|
24
|
+
document.getElementById('passToggle').addEventListener('click',function(){const i=document.getElementById('gPass');i.type=i.type==='password'?'text':'password';this.textContent=i.type==='text'?'Hide':'Show'});
|
|
25
|
+
document.getElementById('gateForm').addEventListener('submit',e=>{e.preventDefault();const u=document.getElementById('gUser').value.trim(),p=document.getElementById('gPass').value,er=document.getElementById('gateErr');er.textContent='';if(!u){er.textContent='Enter a username.';return}if(!p){er.textContent='Enter a password.';return}if(p==='nathanisgoat'){sessionStorage.setItem('phk_secret','1');location.href='home.html'}else{er.textContent='Incorrect password.'}});
|
|
26
|
+
</script>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "studyable-math",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "studyable-math",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Studyable math games site",
|
|
5
|
+
"main": "index.html",
|
|
6
|
+
"unpkg": "index.html",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.html",
|
|
10
|
+
"home.html",
|
|
11
|
+
"games.html",
|
|
12
|
+
"ai.html",
|
|
13
|
+
"settings.html",
|
|
14
|
+
"admin.html",
|
|
15
|
+
"settings.js",
|
|
16
|
+
"games.js",
|
|
17
|
+
"games-data.js",
|
|
18
|
+
"rug-catalog.js",
|
|
19
|
+
"style.css"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"start": "node server.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/rug-catalog.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/* ==========================================================================
|
|
2
|
+
RUG catalog + resilient game loader
|
|
3
|
+
--------------------------------------------------------------------------
|
|
4
|
+
Adapted from Richards Unblocked Games (@ywkrlerche/richardwho on npm,
|
|
5
|
+
rug.cl). jsDelivr serves .html as text/plain and caps files at ~20 MB,
|
|
6
|
+
so games are fetched as text (or .partN pieces), joined, and written
|
|
7
|
+
into a blank iframe. This module provides:
|
|
8
|
+
|
|
9
|
+
- games.json catalog fetch (jsDelivr npm -> unpkg fallback)
|
|
10
|
+
- game URL resolution (repo/path/parts, package-relative, absolute)
|
|
11
|
+
- mirror fallbacks + stall timeouts for flaky CDN downloads
|
|
12
|
+
- cdnPins: rewrite @branch -> @commit so big repos don't 403
|
|
13
|
+
- stripTracking: remove analytics from the "gn" collection
|
|
14
|
+
- guardHistory: <base> + history/network guards injected at top
|
|
15
|
+
- gameCache: Cache Storage so replays start instantly
|
|
16
|
+
========================================================================== */
|
|
17
|
+
(function () {
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const RUG_CDN = 'https://cdn.jsdelivr.net/npm/@ywkrlerche/richardwho';
|
|
21
|
+
const GH_USER = 'Kingston5390';
|
|
22
|
+
const GH_BRANCH = 'v1';
|
|
23
|
+
|
|
24
|
+
/* localStorage can throw (private mode) - never let that break the page */
|
|
25
|
+
const store = {
|
|
26
|
+
get(k, d){ try{ const v = localStorage.getItem(k); return v === null ? d : JSON.parse(v); }catch{ return d; } },
|
|
27
|
+
set(k, v){ try{ localStorage.setItem(k, JSON.stringify(v)); }catch{} }
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const fmtMB = (bytes) => {
|
|
31
|
+
const mb = bytes / 1048576;
|
|
32
|
+
return mb < 1 ? `${Math.max(1, Math.round(bytes / 1024))} KB` : `${mb < 10 ? mb.toFixed(1) : Math.round(mb)} MB`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/* ---- URL resolution ---------------------------------------------------- */
|
|
36
|
+
function absUrl(u){
|
|
37
|
+
return /^https?:/i.test(u) ? u : `${RUG_CDN}/${String(u).replace(/^\/+/, '')}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// The game's launch file(s). Multi-part games ship as <file>.part0..N-1.
|
|
41
|
+
function urls(r){
|
|
42
|
+
if(r.url){
|
|
43
|
+
const u = absUrl(r.url);
|
|
44
|
+
return r.parts > 0 ? Array.from({length: r.parts}, (_, i) => `${u}.part${i}`) : [u];
|
|
45
|
+
}
|
|
46
|
+
const file = `https://cdn.jsdelivr.net/gh/${GH_USER}/${r.repo}@${GH_BRANCH}/${r.path}`;
|
|
47
|
+
return r.parts > 0 ? Array.from({length: r.parts}, (_, i) => `${file}.part${i}`) : [file];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Folder the game's relative assets resolve against. Injected as <base>.
|
|
51
|
+
function base(r){
|
|
52
|
+
if(r.base) return absUrl(r.base).split('?')[0];
|
|
53
|
+
if(r.url){
|
|
54
|
+
const u = absUrl(r.url).split('?')[0].replace(/\.part\d+$/, '');
|
|
55
|
+
return u.slice(0, u.lastIndexOf('/') + 1);
|
|
56
|
+
}
|
|
57
|
+
const p = r.path || '';
|
|
58
|
+
const dir = p.includes('/') ? p.slice(0, p.lastIndexOf('/') + 1) : '';
|
|
59
|
+
return `https://cdn.jsdelivr.net/gh/${GH_USER}/${r.repo}@${GH_BRANCH}/${dir}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Cover/logo artwork. Package logos live under logos/<file> on the CDN.
|
|
63
|
+
function logo(r){
|
|
64
|
+
if(r.cover) return r.cover;
|
|
65
|
+
if(typeof r.logo === 'string') return `${RUG_CDN}/logos/${encodeURIComponent(r.logo)}`;
|
|
66
|
+
return r.logo ? `${RUG_CDN}/logos/${encodeURIComponent(r.id)}.webp` : null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* ---- Mirrors ------------------------------------------------------------
|
|
70
|
+
Backup sources for a jsDelivr GitHub link, in the order to try them:
|
|
71
|
+
the link itself, GitHub's own file server, jsDelivr's second network,
|
|
72
|
+
then the link once more. The "gn" collection is also mirrored at
|
|
73
|
+
gn-math/html at the same commit. */
|
|
74
|
+
function mirrors(u){
|
|
75
|
+
const m = u.match(/^https:\/\/cdn\.jsdelivr\.net\/gh\/([^/]+)\/([^@/]+)@([^/]+)\/(.+)$/);
|
|
76
|
+
if(m){
|
|
77
|
+
const [, user, repo, ref, path] = m;
|
|
78
|
+
const list = [u,
|
|
79
|
+
`https://raw.githubusercontent.com/${user}/${repo}/${ref}/${path}`,
|
|
80
|
+
`https://fastly.jsdelivr.net/gh/${user}/${repo}@${ref}/${path}`, u];
|
|
81
|
+
if(user === 'freebuisness' && repo === 'html'){
|
|
82
|
+
list.push(`https://cdn.jsdelivr.net/gh/gn-math/html@${ref}/${path}`,
|
|
83
|
+
`https://raw.githubusercontent.com/gn-math/html/${ref}/${path}`);
|
|
84
|
+
}
|
|
85
|
+
return list;
|
|
86
|
+
}
|
|
87
|
+
const n = u.match(/^https:\/\/cdn\.jsdelivr\.net\/npm\/(.+)$/);
|
|
88
|
+
if(n) return [u, `https://unpkg.com/${n[1]}`, u];
|
|
89
|
+
const un = u.match(/^https:\/\/unpkg\.com\/(.+)$/);
|
|
90
|
+
if(un) return [u, `https://cdn.jsdelivr.net/npm/${un[1]}`, u];
|
|
91
|
+
return [u, u];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ---- CDN pinning ---------------------------------------------------------
|
|
95
|
+
games.json's cdnPins maps "owner/repo@branch" -> fixed commit sha.
|
|
96
|
+
jsDelivr refuses branch links into repos over 50 MB unless the file
|
|
97
|
+
happens to be cached, so those games break at random. Rewriting the
|
|
98
|
+
branch to the pinned commit makes the links permanent. */
|
|
99
|
+
let cdnPins = {};
|
|
100
|
+
function pinCdn(html){
|
|
101
|
+
return html.replace(/(cdn|fastly)\.jsdelivr\.net\/gh\/([\w.-]+\/[\w.-]+?)(?:@([\w.-]+))?\//g,
|
|
102
|
+
(all, host, repo, ref) => {
|
|
103
|
+
const sha = cdnPins[`${repo}@${ref || ''}`];
|
|
104
|
+
return sha ? `${host}.jsdelivr.net/gh/${repo}@${sha}/` : all;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// The extra collection's launch files embed Google Analytics; remove it
|
|
109
|
+
// so players aren't tracked.
|
|
110
|
+
function stripTracking(html){
|
|
111
|
+
return html
|
|
112
|
+
.replace(/<script\b[^>]*googletagmanager\.com[^>]*>\s*<\/script>/gi, '')
|
|
113
|
+
.replace(/<script\b[^>]*>(?:(?!<\/script>)[\s\S])*?\bgtag\s*\((?:(?!<\/script>)[\s\S])*?<\/script>/gi, '');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* ---- Injected guards -----------------------------------------------------
|
|
117
|
+
A written-in game shares this page's address and session history, so a
|
|
118
|
+
game calling history.back() or pushState() would move the whole tab.
|
|
119
|
+
Give games no-op versions first. NET_GUARD also rescues big engine files
|
|
120
|
+
that jsDelivr hangs on, and wraps cross-origin Worker scripts. */
|
|
121
|
+
const HISTORY_GUARD =
|
|
122
|
+
'<script>(function(){try{var h=window.history,n=function(){};' +
|
|
123
|
+
'h.back=h.forward=h.go=h.pushState=h.replaceState=n;}catch(e){}})();<\/script>';
|
|
124
|
+
|
|
125
|
+
const NET_GUARD =
|
|
126
|
+
'<script>(function(){try{' +
|
|
127
|
+
'var re=/^https:\\/\\/(?:cdn|fastly)\\.jsdelivr\\.net\\/gh\\/([^\\/@]+)\\/([^\\/@]+)(?:@([^\\/]+))?\\/([^?#]+)/;' +
|
|
128
|
+
'var big=/\\.(wasm|data|unityweb|unity3d|pck|bin|br|gz|swf|mem|zip|obb|bundle)(\\?|#|$)/i;' +
|
|
129
|
+
'function abs(u){try{return new URL(u,document.baseURI).href}catch(e){return String(u)}}' +
|
|
130
|
+
'function gh(u){var m=re.exec(u);return m?\'https://raw.githubusercontent.com/\'+m[1]+\'/\'+m[2]+\'/\'+(m[3]||\'HEAD\')+\'/\'+m[4]:null}' +
|
|
131
|
+
'function good(r){if(!r.ok||/text\\/html/i.test(r.headers.get(\'content-type\')||\'\'))throw new Error(\'bad\');return r}' +
|
|
132
|
+
'var F=window.fetch;if(F)window.fetch=function(input,init){' +
|
|
133
|
+
'var u=abs(typeof input===\'string\'?input:input&&input.url),alt=gh(u);if(!alt)return F.apply(this,arguments);' +
|
|
134
|
+
'if(big.test(u))return F.call(window,alt,init).then(good).catch(function(){return F.call(window,u,init)});' +
|
|
135
|
+
'return new Promise(function(ok,no){var settled=false;function backup(){if(settled)return;settled=true;F.call(window,alt,init).then(ok,no)}' +
|
|
136
|
+
'var t=setTimeout(backup,6000);F.call(window,input,init).then(function(r){clearTimeout(t);if(settled)return;if(r.ok){settled=true;ok(r)}else backup()},function(){clearTimeout(t);backup()})})};' +
|
|
137
|
+
'var O=XMLHttpRequest.prototype.open;XMLHttpRequest.prototype.open=function(m,u){var a=abs(u),alt=gh(a);if(alt&&big.test(a))arguments[1]=alt;return O.apply(this,arguments)};' +
|
|
138
|
+
'var W=window.Worker;if(W)window.Worker=function(u,o){var a=abs(u);if(/^https?:/.test(a)&&new URL(a).origin!==location.origin){' +
|
|
139
|
+
'u=URL.createObjectURL(new Blob([\'importScripts(\'+JSON.stringify(a)+\')\'],{type:\'text/javascript\'}))}return new W(u,o)};window.Worker.prototype=W.prototype;' +
|
|
140
|
+
'}catch(e){}})();<\/script>';
|
|
141
|
+
|
|
142
|
+
// Insert only at the very top of the file (after an optional doctype and
|
|
143
|
+
// <html> tag). Searching for the first "<head>" anywhere is unsafe: many
|
|
144
|
+
// self-unpacking games keep their whole page inside a script string, and
|
|
145
|
+
// inserting there cuts that string in half.
|
|
146
|
+
function guardHistory(html, baseHref){
|
|
147
|
+
const top = html.match(/^(?\s*(?:<!--[\s\S]*?-->\s*)*(?:<!doctype[^>]*>)?\s*(?:<html\b[^>]*>)?)/i)[1];
|
|
148
|
+
const baseTag = baseHref ? `<base href="${baseHref.replace(/"/g, '"')}">` : '';
|
|
149
|
+
return top + baseTag + HISTORY_GUARD + NET_GUARD + html.slice(top.length);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* ---- Saved copies ---------------------------------------------------------
|
|
153
|
+
Recently played games kept in Cache Storage so replays start instantly.
|
|
154
|
+
Keyed by the game's first file URL (includes the version tag, so new
|
|
155
|
+
versions don't reuse old copies). */
|
|
156
|
+
const gameCache = {
|
|
157
|
+
NAME: 'gg-rug-games-v1',
|
|
158
|
+
KEEP: 12,
|
|
159
|
+
async get(key){
|
|
160
|
+
try{
|
|
161
|
+
if(!window.caches) return null;
|
|
162
|
+
const hit = await (await caches.open(this.NAME)).match(key);
|
|
163
|
+
if(hit) this.touch(key);
|
|
164
|
+
return hit || null;
|
|
165
|
+
}catch{ return null; }
|
|
166
|
+
},
|
|
167
|
+
async put(key, blob){
|
|
168
|
+
try{
|
|
169
|
+
if(!window.caches) return;
|
|
170
|
+
await (await caches.open(this.NAME)).put(key,
|
|
171
|
+
new Response(blob, { headers: { 'Content-Type': 'text/html' } }));
|
|
172
|
+
await this.touch(key);
|
|
173
|
+
}catch{ /* out of space or not allowed: just skip saving */ }
|
|
174
|
+
},
|
|
175
|
+
async touch(key){
|
|
176
|
+
const list = store.get('gg_rug_cache_list', []).filter(k => k !== key);
|
|
177
|
+
list.unshift(key);
|
|
178
|
+
const drop = list.splice(this.KEEP);
|
|
179
|
+
store.set('gg_rug_cache_list', list);
|
|
180
|
+
if(drop.length){
|
|
181
|
+
const c = await caches.open(this.NAME);
|
|
182
|
+
await Promise.all(drop.map(k => c.delete(k)));
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/* ---- Catalog --------------------------------------------------------------- */
|
|
188
|
+
const ready = (async () => {
|
|
189
|
+
if (window.GAMES_CATALOG && Array.isArray(window.GAMES_CATALOG.games)) {
|
|
190
|
+
cdnPins = window.GAMES_CATALOG.cdnPins || {};
|
|
191
|
+
return window.GAMES_CATALOG;
|
|
192
|
+
}
|
|
193
|
+
const candidates = [
|
|
194
|
+
'./games.json',
|
|
195
|
+
`${RUG_CDN}/games.json`,
|
|
196
|
+
'https://unpkg.com/@ywkrlerche/richardwho/games.json',
|
|
197
|
+
];
|
|
198
|
+
for(const u of candidates){
|
|
199
|
+
try{
|
|
200
|
+
const res = await fetch(u, { cache: 'no-store' });
|
|
201
|
+
if(res.ok){
|
|
202
|
+
const data = await res.json();
|
|
203
|
+
cdnPins = data.cdnPins || {};
|
|
204
|
+
return data;
|
|
205
|
+
}
|
|
206
|
+
}catch(_){ /* try next mirror */ }
|
|
207
|
+
}
|
|
208
|
+
return { games: [], cdnPins: {} };
|
|
209
|
+
})();
|
|
210
|
+
|
|
211
|
+
window.RUG = { ready, urls, base, logo, mirrors, pinCdn, stripTracking, guardHistory, gameCache, fmtMB };
|
|
212
|
+
})();
|