fix: 缓存命中在head同步document.write避免双重渲染+JS丢失

This commit is contained in:
LukeMackin
2026-07-21 18:57:27 +08:00
parent 123824a734
commit 96d88a9601
4 changed files with 15 additions and 17 deletions

View File

@@ -1,2 +1,2 @@
#Tue Jul 21 14:41:17 CST 2026
#Tue Jul 21 15:13:59 CST 2026
gradle.version=8.13

View File

@@ -1,5 +1,12 @@
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width">
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><script>
(function(){
var b=localStorage.getItem('gca_html'),v=localStorage.getItem('gca_ver');
if(b&&v&&v!==document.getElementById('ver')?.innerText){
document.open();document.write(b);document.close();return
}
})();
</script>
<style>
body{font-family:monospace;background:#0f172a;color:#e2e8f0;padding:16px;margin:0}
h1{font-size:18px;color:#38bdf8}
@@ -8,7 +15,7 @@ h1{font-size:18px;color:#38bdf8}
.btn-download{background:#15803d;color:#fff}
.log{background:#1e293b;padding:12px;border-radius:8px;margin-top:12px;max-height:300px;overflow-y:auto;font-size:12px;white-space:pre-wrap}
.info{color:#94a3b8;font-size:12px;margin:4px 0}
.badge{display:inline-block;background:#f59e0b;color:#000;padding:2px 8px;border-radius:4px;font-size:11px;margin-left:8px}
.badge{display:inline-block;background:#22c55e;color:#000;padding:2px 8px;border-radius:4px;font-size:11px;margin-left:8px}
</style></head><body>
<h1>Yuzu GCA</h1>
<div class="info">version <span id="ver">v0.1.0-dav-android-5</span></div>
@@ -20,32 +27,23 @@ var dlUrl='',dlVer='';
var BASE='https://git.childish-ghost.com/LukeMackin/Yuzu-GCA/raw/branch/main/ota';
function log(m){document.getElementById('log').innerText+=m+'\n'}
function checkUpdate(){
log('checking '+BASE+'/version.txt ...');
log('checking...');
fetch(BASE+'/version.txt?t='+Date.now(),{cache:'no-store'})
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
.then(t=>{t=t.trim();log('remote: '+t);
var local=document.getElementById('ver').innerText;
if(t!==local&&t!=='v'+local&&'v'+t!==local){dlVer=t;dlUrl=BASE+'/h5/index-v6.html';
log('*** NEW VERSION: '+dlVer+' ***');document.getElementById('btnApply').disabled=false}
log('*** NEW VERSION ***');document.getElementById('btnApply').disabled=false}
else log('up to date')})
.catch(e=>log('ERR: '+e.message))
}
function applyUpdate(){
log('downloading '+dlUrl+' ...');
fetch(dlUrl,{cache:'no-store'})
log('downloading...');
fetch(dlUrl+'?t='+Date.now(),{cache:'no-store'})
.then(r=>{if(!r.ok)throw Error('HTTP '+r.status);return r.text()})
.then(t=>{localStorage.setItem('gca_html',t);localStorage.setItem('gca_ver',dlVer);
log('OK reloading...');setTimeout(function(){location.reload()},400)})
log('OK reloading...');setTimeout(function(){location.reload()},300)})
.catch(e=>log('ERR: '+e.message))
}
(function(){
var b=localStorage.getItem('gca_html'),v=localStorage.getItem('gca_ver');
if(b&&v&&v!==document.getElementById('ver').innerText){
location.replace('data:text/html;charset=utf-8,'+encodeURIComponent(b))
}
})();
</script></body></html>