javascript:(async()=>{ 'use strict'; if(location.origin!=='https://rbc27.pages.dev'){alert('Open RBC27 in Chrome first.');return;} const W=window,D=document,KEY='__dynastyHubV1',P='dynasty-hub-v1:',MAX=1500000,BUILTIN={"schema":1,"modules":[{"id":"atlas-studio","name":"Atlas Studio","description":"Engine encyclopedia, diagnostics and save inspection.","latest":"3.0.0","releases":[{"version":"3.0.0","path":"module-atlas-studio-3.0.0.txt","bytes":413020,"sha256":"cd9b5b841cba9a91acd919a35d6491e586848d00aa673f977e700ddd77d3cae6"},{"version":"2.9.0","path":"module-atlas-studio-2.9.0.txt","bytes":382141,"sha256":"4f7e0043e3d09f542e61c18e9fbdb35e10d9b9791f4fdc3102599f3b0b8203cc"}]},{"id":"dynasty-gameplay","name":"Dynasty Lab Gameplay","description":"Runtime gameplay customization for local single-player play.","latest":"5.4.0","releases":[{"version":"5.4.0","path":"module-dynasty-gameplay-5.4.0.txt","bytes":58604,"sha256":"1d018841a2cac8f46c8c05bdfc12a8f669ff61ea7878f6cdd24c61f4c9bb2d63"},{"version":"5.3.0","path":"module-dynasty-gameplay-5.3.0.txt","bytes":45645,"sha256":"fb4d48181f89819487dd17f737a150e20e350a9eee756c158faac2b3e88a0f66"},{"version":"5.2.4","path":"module-dynasty-gameplay-5.2.4.txt","bytes":40033,"sha256":"e7e83eea8737a0bac1cdabcff6405ea506532589d7be3481e6cf38bf7e3da8ef"}]},{"id":"save-editor","name":"Dynasty Save Editor","description":"Local save tools; back up your dynasty before making changes.","latest":"4.0.0","releases":[{"version":"4.0.0","path":"module-save-editor-4.0.0.txt","bytes":29524,"sha256":"692051fe94aea71fba7576b4ff59aedb802f170b9859181a971b67c9503effab"}]},{"id":"hub-check","name":"Hub connection test","description":"Harmless test module. Does not inspect or change game data.","latest":"1.0.0","releases":[{"version":"1.0.0","path":"module-hub-check-1.0.0.txt","bytes":126,"sha256":"df430d768517694cb4db9c061a10c96cfd0e7302babd85170074261782cbe2b6"}]}]}; if(W[KEY]){W[KEY].show();return;} const el=(tag,text,cls)=>{const e=D.createElement(tag);if(text!==undefined)e.textContent=text;if(cls)e.className=cls;return e;}; const get=k=>{try{return localStorage.getItem(P+k)}catch{return null}}, put=(k,v)=>{try{localStorage.setItem(P+k,v);return true}catch{return false}}, del=k=>{try{localStorage.removeItem(P+k)}catch{}}; const state={host:get('host')||'',manifest:BUILTIN,source:'Built-in catalog',busy:false,errors:[],checks:0,launches:0,cacheHits:0}; const root=el('div');root.style.cssText='position:fixed;inset:0;z-index:2147483647;pointer-events:none;display:flex;justify-content:center;align-items:center;';const shadow=root.attachShadow({mode:'open'});const style=el('style');style.textContent=`*{box-sizing:border-box} .panel{pointer-events:auto;width:min(96vw,680px);max-height:90vh;max-height:90dvh;overflow:auto;background:#14161e;color:#edf0f7;font:14px system-ui,sans-serif;border:1px solid #3a4152;border-radius:16px;padding:14px;box-shadow:0 16px 60px #000a} .top,.line,.actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap} .top{justify-content:space-between} h2,h3,p{margin:0} h2{font-size:21px} h3{font-size:16px} small,.muted{color:#a7afc0} .sub{font-size:12px;margin-top:3px} .card{border:1px solid #353b4b;background:#1c202b;padding:12px;border-radius:11px;margin-top:10px} button,select,input{font:inherit;color:#edf0f7;background:#252a38;border:1px solid #414a60;border-radius:8px;padding:9px;min-height:40px} button{cursor:pointer} button:disabled{opacity:.5;cursor:default} .primary{background:#6844b0;border-color:#a48ada} .grow{flex:1;min-width:130px} .status{background:#202434;border-radius:8px;padding:9px;margin-top:10px;overflow-wrap:anywhere} .actions{margin-top:9px} input{width:100%} label{display:block;margin:8px 0 5px} .danger{color:#ffc0c0} .good{color:#b3e6b8} .meta{font-size:12px;margin-top:6px} .small{font-size:12px;padding:6px;min-height:33px} @media(max-height:450px){.panel{max-height:96dvh;padding:9px}.card{padding:9px;margin-top:6px}}`; shadow.append(style);const panel=el('section',undefined,'panel');panel.setAttribute('role','dialog');panel.setAttribute('aria-label','Dynasty Hub');shadow.append(panel);(D.body||D.documentElement).append(root); const status=el('div','Ready. Choose a module.','status');const btn=(t,fn,c)=>{const b=el('button',t,c);b.type='button';b.addEventListener('click',fn);return b;};const msg=(s,err=false)=>{status.textContent=s;status.className='status '+(err?'danger':'');if(err){state.errors.push(String(s).slice(0,300));if(state.errors.length>20)state.errors.shift();}}; const validHost=s=>{const u=new URL(s);if(u.protocol!=='https:'||!/^([a-z0-9-]+\.)+pages\.dev$/.test(u.hostname)||u.username||u.password||u.port||u.pathname!=='/'||u.search||u.hash||u.origin===location.origin)throw Error('Enter your separate https://PROJECT.pages.dev address only.');return u.origin;}; const slug=/^[a-z0-9][a-z0-9-]{0,35}$/,ver=/^\d{1,3}\.\d{1,3}\.\d{1,3}$/;function validate(m){if(!m||m.schema!==1||!Array.isArray(m.modules)||m.modules.length>20)throw Error('Unsupported manifest');let ids=new Set();for(const mod of m.modules){if(!slug.test(mod.id)||ids.has(mod.id)||typeof mod.name!=='string'||mod.name.length>80||!Array.isArray(mod.releases)||mod.releases.length<1||mod.releases.length>30)throw Error('Invalid module');ids.add(mod.id);let vs=new Set();for(const r of mod.releases){if(!ver.test(r.version)||vs.has(r.version)||r.path!==`module-${mod.id}-${r.version}.txt`||!/^[a-f0-9]{64}$/.test(r.sha256)||!Number.isSafeInteger(r.bytes)||r.bytes<1||r.bytes>MAX)throw Error('Invalid release');const pinned=BUILTIN.modules.find(a=>a.id===mod.id)?.releases.find(a=>a.version===r.version);if(pinned&&(pinned.sha256!==r.sha256||pinned.bytes!==r.bytes))throw Error('Catalog changed a pinned release; publish a new version instead.');vs.add(r.version);}if(!vs.has(mod.latest))throw Error('Latest version missing');}return m;} const hex=async b=>Array.from(new Uint8Array(await crypto.subtle.digest('SHA-256',b))).map(n=>n.toString(16).padStart(2,'0')).join(''); const enc=s=>new TextEncoder().encode(s);const decode=b=>new TextDecoder('utf-8',{fatal:true}).decode(b);const cacheKey=r=>'code:'+r.sha256;const known=(m,r)=>BUILTIN.modules.some(a=>a.id===m.id&&a.releases.some(b=>b.version===r.version&&b.sha256===r.sha256)); async function verify(b,r){if(b.byteLength!==r.bytes)throw Error('File size mismatch');if(await hex(b)!==r.sha256)throw Error('SHA-256 mismatch. Nothing executed.');const s=decode(b);if(!s.startsWith('javascript:'))throw Error('Expected bookmarklet file');state.checks++;return s;} async function request(url,max){const c=new AbortController(),t=setTimeout(()=>c.abort(),12000);try{const res=await fetch(url,{mode:'cors',credentials:'omit',redirect:'error',referrerPolicy:'no-referrer',cache:'no-store',signal:c.signal});if(!res.ok)throw Error('HTTP '+res.status);const n=Number(res.headers.get('content-length'));if(n>max)throw Error('Download too large');if(!res.body){const b=await res.arrayBuffer();if(b.byteLength>max)throw Error('Download too large');return new Uint8Array(b);}const rd=res.body.getReader(),chunks=[];let len=0;while(true){const a=await rd.read();if(a.done)break;len+=a.value.length;if(len>max){await rd.cancel();throw Error('Download too large');}chunks.push(a.value);}const out=new Uint8Array(len);let off=0;for(const ch of chunks){out.set(ch,off);off+=ch.length;}return out;}finally{clearTimeout(t);}} const savedManifest=()=>{try{return validate(JSON.parse(get('manifest:'+state.host)))}catch{return null}};if(state.host){try{state.host=validHost(state.host);const m=savedManifest();if(m){state.manifest=m;state.source='Cached catalog';}}catch{state.host='';}} const cards=el('div');const info=el('div',undefined,'muted sub');const hostInput=el('input');hostInput.type='url';hostInput.placeholder='https://your-project.pages.dev';hostInput.value=state.host;const selected={}; function refresh(){info.textContent=state.source+' · '+state.manifest.modules.length+' modules';cards.replaceChildren();for(const mod of state.manifest.modules){const card=el('article',undefined,'card');card.append(el('h3',mod.name));if(mod.description)card.append(el('p',String(mod.description).slice(0,180),'muted meta'));const line=el('div',undefined,'actions');const sel=el('select',undefined,'grow');sel.setAttribute('aria-label',mod.name+' version');for(const r of mod.releases){const opt=el('option',r.version+(r.version===mod.latest?' · Latest':''));opt.value=r.version;sel.append(opt);}sel.value=mod.releases.some(r=>r.version===selected[mod.id])?selected[mod.id]:mod.latest;const meta=el('p',undefined,'muted meta');const rel=()=>mod.releases.find(r=>r.version===sel.value);const update=()=>{selected[mod.id]=sel.value;const r=rel();meta.textContent=Math.round(r.bytes/1024)+' KB · '+(get(cacheKey(r))?'Cached · rechecked at launch':known(mod,r)?'Bundled hash':'Remote catalog hash');};sel.onchange=update;line.append(sel,btn('Launch',()=>run(mod,rel(),false),'primary'),btn('Cache',()=>run(mod,rel(),true)));card.append(line,meta);update();cards.append(card);}} async function busy(fn){if(state.busy){msg('Another operation is running.');return;}state.busy=true;try{await fn()}catch(e){msg(e.message||String(e),true)}finally{state.busy=false;refresh();}} async function sync(){await busy(async()=>{if(!state.host)throw Error('Set your hosting address first.');msg('Checking catalog…');const b=await request(state.host+'/manifest.json',250000);const m=validate(JSON.parse(decode(b)));state.manifest=m;state.source='Remote catalog';const ok=put('manifest:'+state.host,JSON.stringify(m));msg('Catalog updated'+(ok?' and saved locally.':'; browser storage unavailable.'));});} async function obtain(r){const old=get(cacheKey(r));if(old){try{const s=await verify(enc(old),r);state.cacheHits++;return s;}catch{del(cacheKey(r));}}if(!state.host)throw Error('Hosting not configured. Import a matching local module first.');msg('Downloading '+r.version+'…');return await verify(await request(state.host+'/'+r.path,r.bytes),r);} function launch(s){root.style.display='none';try{const result=(0,eval)(s.replace(/^javascript:/i,''));state.launches++;return Promise.resolve(result).catch(e=>{root.style.display='flex';throw e;});}catch(e){root.style.display='flex';throw e;}} async function run(mod,r,cacheOnly){await busy(async()=>{const s=await obtain(r);const cached=put(cacheKey(r),s);if(cacheOnly){msg(cached?'Verified and cached '+mod.name+' '+r.version+'.':'Verified; cache storage unavailable.');return;}if(!confirm('Launch '+mod.name+' '+r.version+'? This executes code in RBC27. '+(known(mod,r)?'Matches the built-in release hash.':'Matches the configured host catalog hash; only proceed if you trust that host.')))return;msg('Verified '+mod.name+' '+r.version+(cached?' · cached.':'.'));await launch(s);});} const file=el('input');file.type='file';file.accept='.txt,.js';file.style.display='none';file.onchange=()=>{const f=file.files[0];file.value='';if(!f)return;busy(async()=>{if(f.size>MAX)throw Error('File too large');const b=new Uint8Array(await f.arrayBuffer()),h=await hex(b);const all=[...state.manifest.modules,...BUILTIN.modules];let match=null;for(const m of all){const r=m.releases.find(a=>a.sha256===h&&a.bytes===b.byteLength);if(r){match={m,r};break;}}if(!match)throw Error('Unknown file hash. Update your trusted catalog first.');const s=await verify(b,match.r);if(!put(cacheKey(match.r),s))throw Error('Verified file but cache storage unavailable.');msg('Imported and cached '+match.m.name+' '+match.r.version+'. Select Launch.');});}; function report(){const data={version:'1.0',host:state.host,source:state.source,modules:state.manifest.modules.map(m=>({id:m.id,latest:m.latest,releases:m.releases.map(r=>({version:r.version,cached:!!get(cacheKey(r))}))})),checks:state.checks,launches:state.launches,cacheHits:state.cacheHits,errors:state.errors,viewport:{width:innerWidth,height:innerHeight},testMarker:W.__dynastyHubTest||null};const url=URL.createObjectURL(new Blob([JSON.stringify(data,null,2)],{type:'application/json'}));const a=el('a');a.href=url;a.download='Dynasty-Hub-v1-report.json';a.click();setTimeout(()=>URL.revokeObjectURL(url),1000);} const top=el('div',undefined,'top'),title=el('div');title.append(el('h2','Dynasty Hub'),el('p','Version 1.0 · Module manager','muted sub'));top.append(title,btn('Hide',()=>root.style.display='none','small'));const settings=el('section',undefined,'card');settings.append(el('h3','Release host'),el('p','Only connect a Pages site you control. Downloads never send your save or login credentials.','muted meta'));const lab=el('label','Cloudflare Pages address');lab.append(hostInput);settings.append(lab);const controls=el('div',undefined,'actions');controls.append(btn('Connect',()=>{if(state.busy)return;try{const h=validHost(hostInput.value.trim());if(h!==state.host&&!confirm('Trust release catalog from '+h+'? Only connect your own site.'))return;state.host=h;put('host',h);state.manifest=savedManifest()||BUILTIN;state.source=savedManifest()?'Cached catalog':'Built-in catalog';refresh();sync();}catch(e){msg(e.message,true)}},'primary'),btn('Check updates',sync),btn('Disconnect',()=>{if(state.busy)return;state.host='';hostInput.value='';del('host');state.manifest=BUILTIN;state.source='Built-in catalog';refresh();msg('Disconnected. Cached modules are retained.');}));settings.append(controls);const bottom=el('div',undefined,'actions');bottom.append(btn('Import local module',()=>file.click()),btn('Export report',report),btn('Clear Hub cache',()=>{if(state.busy)return;if(!confirm('Clear Dynasty Hub cache only? Game saves are unaffected.'))return;try{for(let i=localStorage.length-1;i>=0;i--){const k=localStorage.key(i);if(k?.startsWith(P+'code:')||k?.startsWith(P+'manifest:'))localStorage.removeItem(k);}}catch{}state.manifest=BUILTIN;state.source='Built-in catalog';refresh();msg('Hub cache cleared.');}),btn('Remove Hub',()=>{if(state.busy)return;root.remove();delete W[KEY];}));panel.append(top,info,status,settings,cards,bottom,file);W[KEY]={show:()=>{root.style.display='flex';refresh();}};refresh();if(state.host){msg('Saved host loaded. Checking updates…');sync();} })()