bendidiihab commited on
Commit
de1155d
·
verified ·
1 Parent(s): a07428e

Publish encrypted Codenames league

Browse files
Files changed (4) hide show
  1. README.md +6 -6
  2. index.html +18 -18
  3. payload.json +0 -0
  4. style.css +0 -28
README.md CHANGED
@@ -1,11 +1,11 @@
1
  ---
2
- title: Elo Code
3
- emoji: ⚡
4
- colorFrom: yellow
5
- colorTo: gray
6
  sdk: static
 
7
  pinned: false
8
- short_description: Password-encrypted Codenames rankings and match history
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: The Code Club
3
+ emoji: 🃏
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: static
7
+ app_file: index.html
8
  pinned: false
 
9
  ---
10
 
11
+ Password-encrypted private league. Demonstration build with placeholder data.
index.html CHANGED
@@ -1,19 +1,19 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
1
  <!doctype html>
2
+ <html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="theme-color" content="#f4f1e9"><meta name="robots" content="noindex,nofollow"><title>The Code Club — Unlock</title>
3
+ <style>*{box-sizing:border-box}body{margin:0;background:#f4f1e9;color:#282d2a;font:14px/1.6 Arial,sans-serif}.gate{min-height:100dvh;display:grid;place-items:center;padding:30px 20px}.card{width:100%;max-width:440px;background:#fcfbf7;border:1px solid #dedfd5;border-radius:8px;padding:38px}.mark{display:flex;gap:5px;margin-bottom:24px}.mark i{width:21px;height:28px;border-radius:3px;background:#ad392f;transform:rotate(-8deg)}.mark i:nth-child(2){background:#365e78;transform:rotate(5deg)}.mark i:nth-child(3){background:#282d2a;transform:rotate(-3deg)}.eyebrow{font-size:10px;font-weight:700;letter-spacing:2px;color:#6a7169}h1{font:40px/1.15 Georgia,serif;letter-spacing:-1px;margin:12px 0 18px}p{font-size:13px;color:#646d60;margin:0 0 24px}label{display:block;font-size:12px;margin-bottom:8px}.field{display:flex;border:1px solid #bfc5b7;background:#fff;border-radius:4px;overflow:hidden}input{width:100%;min-width:0;border:0;font:16px Arial;padding:13px}button{font:12px Arial;cursor:pointer;min-height:44px}.show{background:white;border:0;padding:0 13px;color:#52604b}.field:focus-within{outline:3px solid #365e78;outline-offset:3px}input:focus{outline:none}button:focus-visible,a:focus-visible{outline:3px solid #365e78;outline-offset:4px}.remember{display:flex;gap:9px;align-items:center;margin:16px 0 2px;font-size:12px}.remember input{width:17px;height:17px;accent-color:#365e78}.hint{font-size:11px;margin:0 0 21px 26px;color:#6a7169}.submit{width:100%;background:#282d2a;color:white;border:0;border-radius:4px;font-size:13px;letter-spacing:.2px;padding:14px}.submit:hover{background:#414b3e}.submit:disabled{opacity:.6;cursor:wait}.error{min-height:24px;margin:14px 0 0;color:#ad392f;font-size:12px}.privacy{border-top:1px solid #dedfd5;padding-top:20px;margin-top:20px;font-size:11px}.direct[hidden]{display:none}.direct{display:block;margin-top:12px;color:#365e78;text-decoration:underline}iframe{display:block;border:0;width:100%;height:100dvh;background:#f4f1e9}.loading{font:16px Georgia;position:fixed;inset:0;display:grid;place-items:center;background:#f4f1e9;z-index:2}.loading[hidden],.gate[hidden],iframe[hidden]{display:none}@media(max-width:440px){.card{padding:28px 24px}h1{font-size:36px}}@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto}}</style></head>
4
+ <body><main class="gate" id="gate"><div class="card"><div class="mark" aria-hidden="true"><i></i><i></i><i></i></div><span class="eyebrow">THE CODE CLUB</span><h1>A seat at<br>the table.</h1><p>Enter the shared password to open your league’s rankings and game history.</p><form id="unlock"><label for="password">League password</label><div class="field"><input id="password" type="password" autocomplete="current-password" required aria-describedby="error"><button class="show" type="button" id="show" aria-label="Show password" aria-pressed="false">Show</button></div><label class="remember"><input id="remember" type="checkbox" checked>Remember this browser</label><p class="hint">Only on a device you trust. Use Lock to forget access.</p><button class="submit" type="submit" id="submit">Unlock the clubhouse <span aria-hidden="true">→</span></button><p class="error" id="error" role="status" aria-live="polite"></p></form><div class="privacy">Your league is encrypted. Decryption happens in your browser. The password is never sent to a server.<a class="direct" id="direct" hidden>Open the site directly ↗</a></div></div></main><div class="loading" id="loading" role="status" hidden>Opening the clubhouse…</div><iframe id="club" title="The Code Club league" sandbox="allow-scripts" hidden></iframe>
5
+ <script>
6
+ (()=>{'use strict';const storageKey='codeclub:remembered:v1',gate=document.querySelector('#gate'),frame=document.querySelector('#club'),error=document.querySelector('#error'),submit=document.querySelector('#submit'),loading=document.querySelector('#loading'),input=document.querySelector('#password');let envelope,payloadPromise,currentHash=location.hash||'#/players';const bytes=s=>Uint8Array.from(atob(s),c=>c.charCodeAt(0)),b64=b=>btoa(String.fromCharCode(...new Uint8Array(b))),aad=new TextEncoder().encode('codeclub:v1');
7
+ const forget=()=>{try{localStorage.removeItem(storageKey)}catch{}};
8
+ const getPayload=()=>payloadPromise||(payloadPromise=fetch('./payload.json',{cache:'no-store'}).then(r=>{if(!r.ok)throw Error('fetch');return r.json()}).then(e=>{if(e.version!==1||e.iterations!==600000||bytes(e.salt).length!==16||bytes(e.iv).length!==12)throw Error('format');envelope=e;return e}).catch(e=>{payloadPromise=null;throw e}));
9
+ const decrypt=async key=>{await getPayload();return new TextDecoder().decode(await crypto.subtle.decrypt({name:'AES-GCM',iv:bytes(envelope.iv),additionalData:aad},key,bytes(envelope.ciphertext)))};
10
+ const showApp=html=>{frame.srcdoc=html;frame.hidden=false;gate.hidden=true;loading.hidden=false;input.value='';frame.onload=()=>{if(frame.hidden)return;document.title='The Code Club';loading.hidden=true;frame.contentWindow.postMessage({type:'codeclub:navigate',hash:currentHash},'*');frame.focus()};};
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
+ window.addEventListener('hashchange',()=>{currentHash=location.hash||'#/players';if(!frame.hidden)frame.contentWindow.postMessage({type:'codeclub:navigate',hash:currentHash},'*')});
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
+ })();
19
+ </script></body></html>
payload.json ADDED
The diff for this file is too large to render. See raw diff
 
style.css DELETED
@@ -1,28 +0,0 @@
1
- body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
- }
5
-
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
- }
10
-
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
- }
17
-
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
- }
25
-
26
- .card p:last-child {
27
- margin-bottom: 0;
28
- }