Spaces:
Running
Running
Publish encrypted Codenames league
Browse files- index.html +2 -2
- payload.json +0 -0
index.html
CHANGED
|
@@ -11,8 +11,8 @@ const showApp=html=>{frame.srcdoc=html;frame.hidden=false;gate.hidden=true;loadi
|
|
| 11 |
const busy=value=>{submit.disabled=value;submit.textContent=value?'Decrypting…':'Unlock the clubhouse →';};
|
| 12 |
document.querySelector('#show').onclick=e=>{const show=input.type==='password';input.type=show?'text':'password';e.target.textContent=show?'Hide':'Show';e.target.setAttribute('aria-label',show?'Hide password':'Show password');e.target.setAttribute('aria-pressed',String(show));};
|
| 13 |
document.querySelector('#unlock').onsubmit=async e=>{e.preventDefault();busy(true);error.textContent='';if(!globalThis.crypto?.subtle){error.textContent='This browser needs HTTPS and Web Crypto to open the league.';busy(false);return}try{await getPayload();const material=await crypto.subtle.importKey('raw',new TextEncoder().encode(input.value),'PBKDF2',false,['deriveKey']),key=await crypto.subtle.deriveKey({name:'PBKDF2',salt:bytes(envelope.salt),iterations:envelope.iterations,hash:'SHA-256'},material,{name:'AES-GCM',length:256},true,['decrypt']);const html=await decrypt(key);forget();if(document.querySelector('#remember').checked){try{localStorage.setItem(storageKey,JSON.stringify({salt:envelope.salt,key:b64(await crypto.subtle.exportKey('raw',key))}))}catch{error.textContent='Browser storage is unavailable. Unlock again on your next visit.'}}showApp(html)}catch(e){error.textContent=e.name==='OperationError'?'That password did not unlock the league, or the encrypted file is damaged. Check the password and retry.':'Could not load the encrypted league. Check your connection and retry.';input.focus()}finally{busy(false)}};
|
| 14 |
-
window.addEventListener('message',e=>{if(e.source!==frame.contentWindow)return;if(e.data?.type==='codeclub:lock'){forget();frame.onload=null;frame.remove();frame.removeAttribute('srcdoc');frame.hidden=true;document.body.append(frame);gate.hidden=false;loading.hidden=true;document.title='The Code Club — Unlock';error.textContent='Locked. Remembered access has been removed.';input.focus()}else if(e.data?.type==='codeclub:route'&&typeof e.data.hash==='string'&&/^#\/[a-z0-9/~\-]*$/.test(e.data.hash)){if(!loading.hidden)return;currentHash=e.data.hash;history.replaceState(null,'',currentHash);if(typeof e.data.title==='string')document.title=e.data.title.slice(0,150)}});
|
| 15 |
-
|
| 16 |
if(window.parent!==window){const direct=document.querySelector('#direct');direct.hidden=false;direct.href=location.href;direct.target='_blank';direct.rel='noopener noreferrer'}
|
| 17 |
(async()=>{try{const saved=JSON.parse(localStorage.getItem(storageKey)||'null');if(!saved)return;loading.hidden=false;await getPayload();if(saved.salt!==envelope.salt){forget();return}const key=await crypto.subtle.importKey('raw',bytes(saved.key),'AES-GCM',false,['decrypt']);showApp(await decrypt(key))}catch{forget()}finally{if(frame.hidden)loading.hidden=true}})();
|
| 18 |
})();
|
|
|
|
| 11 |
const busy=value=>{submit.disabled=value;submit.textContent=value?'Decrypting…':'Unlock the clubhouse →';};
|
| 12 |
document.querySelector('#show').onclick=e=>{const show=input.type==='password';input.type=show?'text':'password';e.target.textContent=show?'Hide':'Show';e.target.setAttribute('aria-label',show?'Hide password':'Show password');e.target.setAttribute('aria-pressed',String(show));};
|
| 13 |
document.querySelector('#unlock').onsubmit=async e=>{e.preventDefault();busy(true);error.textContent='';if(!globalThis.crypto?.subtle){error.textContent='This browser needs HTTPS and Web Crypto to open the league.';busy(false);return}try{await getPayload();const material=await crypto.subtle.importKey('raw',new TextEncoder().encode(input.value),'PBKDF2',false,['deriveKey']),key=await crypto.subtle.deriveKey({name:'PBKDF2',salt:bytes(envelope.salt),iterations:envelope.iterations,hash:'SHA-256'},material,{name:'AES-GCM',length:256},true,['decrypt']);const html=await decrypt(key);forget();if(document.querySelector('#remember').checked){try{localStorage.setItem(storageKey,JSON.stringify({salt:envelope.salt,key:b64(await crypto.subtle.exportKey('raw',key))}))}catch{error.textContent='Browser storage is unavailable. Unlock again on your next visit.'}}showApp(html)}catch(e){error.textContent=e.name==='OperationError'?'That password did not unlock the league, or the encrypted file is damaged. Check the password and retry.':'Could not load the encrypted league. Check your connection and retry.';input.focus()}finally{busy(false)}};
|
| 14 |
+
window.addEventListener('message',e=>{if(e.source!==frame.contentWindow)return;if(e.data?.type==='codeclub:lock'){forget();frame.onload=null;frame.remove();frame.removeAttribute('srcdoc');frame.hidden=true;document.body.append(frame);gate.hidden=false;loading.hidden=true;document.title='The Code Club — Unlock';error.textContent='Locked. Remembered access has been removed.';input.focus()}else if(e.data?.type==='codeclub:route'&&typeof e.data.hash==='string'&&/^#\/[a-z0-9/~\-]*$/.test(e.data.hash)){if(!loading.hidden)return;currentHash=e.data.hash;if(e.data.history==='push'&¤tHash!==location.hash)history.pushState(null,'',currentHash);else history.replaceState(null,'',currentHash);if(typeof e.data.title==='string')document.title=e.data.title.slice(0,150)}});
|
| 15 |
+
const syncRoute=()=>{const next=location.hash||'#/players';if(next===currentHash)return;currentHash=next;if(!frame.hidden)frame.contentWindow.postMessage({type:'codeclub:navigate',hash:currentHash},'*')};window.addEventListener('hashchange',syncRoute);window.addEventListener('popstate',syncRoute);
|
| 16 |
if(window.parent!==window){const direct=document.querySelector('#direct');direct.hidden=false;direct.href=location.href;direct.target='_blank';direct.rel='noopener noreferrer'}
|
| 17 |
(async()=>{try{const saved=JSON.parse(localStorage.getItem(storageKey)||'null');if(!saved)return;loading.hidden=false;await getPayload();if(saved.salt!==envelope.salt){forget();return}const key=await crypto.subtle.importKey('raw',bytes(saved.key),'AES-GCM',false,['decrypt']);showApp(await decrypt(key))}catch{forget()}finally{if(frame.hidden)loading.hidden=true}})();
|
| 18 |
})();
|
payload.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|