prts-moonlit 1.0.2 → 1.0.4
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/gacha.html +24 -20
- package/index.html +24 -20
- package/ledger.html +24 -20
- package/package.json +1 -1
package/gacha.html
CHANGED
|
@@ -1053,7 +1053,7 @@ document.addEventListener('pointerdown',function(){ac()},{once:true});
|
|
|
1053
1053
|
var BASE='https://textdb.dev/api/data/prts-acct-';
|
|
1054
1054
|
var LS='whale.acct',LT='whale.sync.t';
|
|
1055
1055
|
var acct=null;try{acct=JSON.parse(localStorage.getItem(LS)||'null')}catch(e){}
|
|
1056
|
-
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0;
|
|
1056
|
+
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0,lastSnap=null;
|
|
1057
1057
|
|
|
1058
1058
|
function sha(msg){
|
|
1059
1059
|
function r(v,n){return (v>>>n)|(v<<(32-n));}
|
|
@@ -1083,33 +1083,34 @@ document.addEventListener('pointerdown',function(){ac()},{once:true});
|
|
|
1083
1083
|
}
|
|
1084
1084
|
function snap(){var d={};for(var i=0;i<TK.length;i++){var v=localStorage.getItem(TK[i]);if(v!==null)d[TK[i]]=v;}return d;}
|
|
1085
1085
|
function url(){return BASE+acct.k;}
|
|
1086
|
+
function wxhr(u,b,cb){try{var x=new XMLHttpRequest();x.open('POST',u,true);x.setRequestHeader('Content-Type','text/plain');x.onload=x.onerror=x.ontimeout=function(){if(cb)cb()};x.send(b);}catch(e){if(cb)cb();}}
|
|
1087
|
+
function canon(){var a=[];for(var i=0;i<TK.length;i++)a.push(TK[i]+'='+localStorage.getItem(TK[i]));return a.join('|');}
|
|
1086
1088
|
function st(m){if(box&&box.st)box.st.textContent=m;}
|
|
1087
|
-
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes());}
|
|
1089
|
+
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes())+':'+p(d.getSeconds());}
|
|
1088
1090
|
function apply(rb){
|
|
1089
1091
|
_app=1;try{for(var k in rb.data){_si(k,rb.data[k]);}}finally{_app=0;}
|
|
1090
|
-
_si(LT,String(rb.t||Date.now()));
|
|
1092
|
+
_si(LT,String(rb.t||Date.now()));lastSnap=canon();
|
|
1091
1093
|
st('✔ 已从云端同步 '+clock()+',即将刷新…');
|
|
1092
|
-
setTimeout(function(){location.reload();},
|
|
1094
|
+
setTimeout(function(){location.reload();},350);
|
|
1093
1095
|
}
|
|
1094
|
-
function push(){
|
|
1096
|
+
function push(ry){
|
|
1095
1097
|
if(!acct||!acct.k)return;
|
|
1096
|
-
|
|
1098
|
+
if(!ry)window.__pv=0;
|
|
1099
|
+
_dirty=0;var t=Date.now();_si(LT,String(t));lastSnap=canon();
|
|
1097
1100
|
st('↻ 同步中…');
|
|
1098
|
-
|
|
1099
|
-
.then(function(){setTimeout(function(){verify(t)},1800);})
|
|
1100
|
-
.catch(function(){st('⚠ 云同步暂不可用(可用存档码手动搬)');});
|
|
1101
|
+
wxhr(url(),JSON.stringify({v:1,u:acct.u,t:t,data:snap()}),function(){st('✔ 已上传 · 后台校验…');setTimeout(function(){verify(t)},600);});
|
|
1101
1102
|
}
|
|
1102
1103
|
function verify(t){
|
|
1103
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1104
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1104
1105
|
x=(x||'').replace(/=$/,'');
|
|
1105
1106
|
try{var rb=JSON.parse(x);if(rb.t===t){st('✔ 已同步 '+clock());return;}}catch(e){}
|
|
1106
|
-
if(!window.__pv){window.__pv=1;setTimeout(function(){
|
|
1107
|
-
else{st('⚠
|
|
1107
|
+
if(!window.__pv){window.__pv=1;setTimeout(function(){push(1);},800);}
|
|
1108
|
+
else{window.__pv=0;st('⚠ 上传好像没送达(此浏览器限制跨域)——数据还在本机,可换 Safari 或用存档码');}
|
|
1108
1109
|
}).catch(function(){st('⚠ 校验失败(可能网络受限)');});
|
|
1109
1110
|
}
|
|
1110
1111
|
function pull(manual){
|
|
1111
1112
|
if(!acct||!acct.k)return;
|
|
1112
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1113
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1113
1114
|
x=(x||'').replace(/=$/,'');
|
|
1114
1115
|
if(!x){if(manual)st('☁ 云端暂时没有存档——点「立即同步」上传本机数据');return;}
|
|
1115
1116
|
var rb;try{rb=JSON.parse(x)}catch(e){st('⚠ 云端数据格式异常');return;}
|
|
@@ -1169,11 +1170,11 @@ document.addEventListener('pointerdown',function(){ac()},{once:true});
|
|
|
1169
1170
|
st('✦ 仓库已创建,正在上传本机数据…');render();push();return;
|
|
1170
1171
|
}
|
|
1171
1172
|
st('↻ 查找云端仓库…');
|
|
1172
|
-
fetch(BASE+k+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1173
|
+
fetch(BASE+k+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1173
1174
|
x=(x||'').replace(/=$/,'');
|
|
1174
1175
|
if(x&&x.length>2){
|
|
1175
1176
|
acct={u:u,k:k};_si(LS,JSON.stringify(acct));
|
|
1176
|
-
var rb=null;try{rb=JSON.parse(x)}catch(e){}
|
|
1177
|
+
var rb=null;try{rb=JSON.parse(x)}catch(e){}if(!rb){acct=null;localStorage.removeItem(LS);st('⚠ 云端数据异常(可能被误写入过)——没敢覆盖,联系鲸鲸');return;}
|
|
1177
1178
|
if(rb&&(rb.t||0)>Number(localStorage.getItem(LT)||0)){apply(rb);}
|
|
1178
1179
|
else{_si(LT,String((rb&&rb.t)||Date.now()));st('✔ 已登录,云端仓库已连接 '+clock());render();}
|
|
1179
1180
|
}else{
|
|
@@ -1206,21 +1207,24 @@ document.addEventListener('pointerdown',function(){ac()},{once:true});
|
|
|
1206
1207
|
}
|
|
1207
1208
|
function open(){render();wrap.classList.add('on')}
|
|
1208
1209
|
var _orig=localStorage.setItem;
|
|
1209
|
-
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,
|
|
1210
|
+
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,900);}};
|
|
1210
1211
|
window.addEventListener('pagehide',function(){
|
|
1211
1212
|
if(acct&&acct.k&&_dirty){try{_dirty=0;_si(LT,String(Date.now()));
|
|
1212
|
-
|
|
1213
|
+
var x=new XMLHttpRequest();x.open('POST',url(),false);x.setRequestHeader('Content-Type','text/plain');x.send(JSON.stringify({v:1,u:acct.u,t:Date.now(),data:snap()}));}catch(e){}}
|
|
1213
1214
|
});
|
|
1214
|
-
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k)
|
|
1215
|
+
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);});
|
|
1216
|
+
setInterval(function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);},15000);
|
|
1215
1217
|
var btn=document.createElement('div');
|
|
1216
1218
|
var ci=document.querySelector('.corner-ics');
|
|
1217
1219
|
if(ci){btn.className='ci';btn.textContent='@';ci.appendChild(btn);}
|
|
1218
1220
|
else{btn.textContent='@';btn.style.cssText='position:fixed;right:14px;bottom:60px;z-index:120;width:38px;height:38px;display:flex;align-items:center;justify-content:center;border:2px solid #4cc9ff;background:rgba(7,12,24,.92);color:#4cc9ff;font-size:17px;cursor:pointer;user-select:none;box-shadow:3px 3px 0 rgba(0,0,0,.45)';document.body.appendChild(btn);}
|
|
1219
1221
|
btn.id='acctBtn';btn.title='云存档';
|
|
1220
1222
|
if(acct)btn.style.background='rgba(76,201,255,.28)';
|
|
1223
|
+
lastSnap=canon();
|
|
1221
1224
|
btn.addEventListener('click',open);
|
|
1222
|
-
if(acct&&acct.k){
|
|
1223
|
-
|
|
1225
|
+
setInterval(function(){if(acct&&acct.k){var c=canon();if(c!==lastSnap){lastSnap=c;clearTimeout(pq);pq=setTimeout(push,900);}}},2000);
|
|
1226
|
+
if(acct&&acct.k){setTimeout(function(){pull(false);},250);}
|
|
1227
|
+
window.__shaT=sha;window.__pushT=push;window.__pullT=pull;window.__canonT=canon;
|
|
1224
1228
|
})();
|
|
1225
1229
|
</script>
|
|
1226
1230
|
</body>
|
package/index.html
CHANGED
|
@@ -2767,7 +2767,7 @@ boot();
|
|
|
2767
2767
|
var BASE='https://textdb.dev/api/data/prts-acct-';
|
|
2768
2768
|
var LS='whale.acct',LT='whale.sync.t';
|
|
2769
2769
|
var acct=null;try{acct=JSON.parse(localStorage.getItem(LS)||'null')}catch(e){}
|
|
2770
|
-
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0;
|
|
2770
|
+
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0,lastSnap=null;
|
|
2771
2771
|
|
|
2772
2772
|
function sha(msg){
|
|
2773
2773
|
function r(v,n){return (v>>>n)|(v<<(32-n));}
|
|
@@ -2797,33 +2797,34 @@ boot();
|
|
|
2797
2797
|
}
|
|
2798
2798
|
function snap(){var d={};for(var i=0;i<TK.length;i++){var v=localStorage.getItem(TK[i]);if(v!==null)d[TK[i]]=v;}return d;}
|
|
2799
2799
|
function url(){return BASE+acct.k;}
|
|
2800
|
+
function wxhr(u,b,cb){try{var x=new XMLHttpRequest();x.open('POST',u,true);x.setRequestHeader('Content-Type','text/plain');x.onload=x.onerror=x.ontimeout=function(){if(cb)cb()};x.send(b);}catch(e){if(cb)cb();}}
|
|
2801
|
+
function canon(){var a=[];for(var i=0;i<TK.length;i++)a.push(TK[i]+'='+localStorage.getItem(TK[i]));return a.join('|');}
|
|
2800
2802
|
function st(m){if(box&&box.st)box.st.textContent=m;}
|
|
2801
|
-
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes());}
|
|
2803
|
+
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes())+':'+p(d.getSeconds());}
|
|
2802
2804
|
function apply(rb){
|
|
2803
2805
|
_app=1;try{for(var k in rb.data){_si(k,rb.data[k]);}}finally{_app=0;}
|
|
2804
|
-
_si(LT,String(rb.t||Date.now()));
|
|
2806
|
+
_si(LT,String(rb.t||Date.now()));lastSnap=canon();
|
|
2805
2807
|
st('✔ 已从云端同步 '+clock()+',即将刷新…');
|
|
2806
|
-
setTimeout(function(){location.reload();},
|
|
2808
|
+
setTimeout(function(){location.reload();},350);
|
|
2807
2809
|
}
|
|
2808
|
-
function push(){
|
|
2810
|
+
function push(ry){
|
|
2809
2811
|
if(!acct||!acct.k)return;
|
|
2810
|
-
|
|
2812
|
+
if(!ry)window.__pv=0;
|
|
2813
|
+
_dirty=0;var t=Date.now();_si(LT,String(t));lastSnap=canon();
|
|
2811
2814
|
st('↻ 同步中…');
|
|
2812
|
-
|
|
2813
|
-
.then(function(){setTimeout(function(){verify(t)},1800);})
|
|
2814
|
-
.catch(function(){st('⚠ 云同步暂不可用(可用存档码手动搬)');});
|
|
2815
|
+
wxhr(url(),JSON.stringify({v:1,u:acct.u,t:t,data:snap()}),function(){st('✔ 已上传 · 后台校验…');setTimeout(function(){verify(t)},600);});
|
|
2815
2816
|
}
|
|
2816
2817
|
function verify(t){
|
|
2817
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
2818
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
2818
2819
|
x=(x||'').replace(/=$/,'');
|
|
2819
2820
|
try{var rb=JSON.parse(x);if(rb.t===t){st('✔ 已同步 '+clock());return;}}catch(e){}
|
|
2820
|
-
if(!window.__pv){window.__pv=1;setTimeout(function(){
|
|
2821
|
-
else{st('⚠
|
|
2821
|
+
if(!window.__pv){window.__pv=1;setTimeout(function(){push(1);},800);}
|
|
2822
|
+
else{window.__pv=0;st('⚠ 上传好像没送达(此浏览器限制跨域)——数据还在本机,可换 Safari 或用存档码');}
|
|
2822
2823
|
}).catch(function(){st('⚠ 校验失败(可能网络受限)');});
|
|
2823
2824
|
}
|
|
2824
2825
|
function pull(manual){
|
|
2825
2826
|
if(!acct||!acct.k)return;
|
|
2826
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
2827
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
2827
2828
|
x=(x||'').replace(/=$/,'');
|
|
2828
2829
|
if(!x){if(manual)st('☁ 云端暂时没有存档——点「立即同步」上传本机数据');return;}
|
|
2829
2830
|
var rb;try{rb=JSON.parse(x)}catch(e){st('⚠ 云端数据格式异常');return;}
|
|
@@ -2883,11 +2884,11 @@ boot();
|
|
|
2883
2884
|
st('✦ 仓库已创建,正在上传本机数据…');render();push();return;
|
|
2884
2885
|
}
|
|
2885
2886
|
st('↻ 查找云端仓库…');
|
|
2886
|
-
fetch(BASE+k+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
2887
|
+
fetch(BASE+k+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
2887
2888
|
x=(x||'').replace(/=$/,'');
|
|
2888
2889
|
if(x&&x.length>2){
|
|
2889
2890
|
acct={u:u,k:k};_si(LS,JSON.stringify(acct));
|
|
2890
|
-
var rb=null;try{rb=JSON.parse(x)}catch(e){}
|
|
2891
|
+
var rb=null;try{rb=JSON.parse(x)}catch(e){}if(!rb){acct=null;localStorage.removeItem(LS);st('⚠ 云端数据异常(可能被误写入过)——没敢覆盖,联系鲸鲸');return;}
|
|
2891
2892
|
if(rb&&(rb.t||0)>Number(localStorage.getItem(LT)||0)){apply(rb);}
|
|
2892
2893
|
else{_si(LT,String((rb&&rb.t)||Date.now()));st('✔ 已登录,云端仓库已连接 '+clock());render();}
|
|
2893
2894
|
}else{
|
|
@@ -2920,21 +2921,24 @@ boot();
|
|
|
2920
2921
|
}
|
|
2921
2922
|
function open(){render();wrap.classList.add('on')}
|
|
2922
2923
|
var _orig=localStorage.setItem;
|
|
2923
|
-
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,
|
|
2924
|
+
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,900);}};
|
|
2924
2925
|
window.addEventListener('pagehide',function(){
|
|
2925
2926
|
if(acct&&acct.k&&_dirty){try{_dirty=0;_si(LT,String(Date.now()));
|
|
2926
|
-
|
|
2927
|
+
var x=new XMLHttpRequest();x.open('POST',url(),false);x.setRequestHeader('Content-Type','text/plain');x.send(JSON.stringify({v:1,u:acct.u,t:Date.now(),data:snap()}));}catch(e){}}
|
|
2927
2928
|
});
|
|
2928
|
-
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k)
|
|
2929
|
+
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);});
|
|
2930
|
+
setInterval(function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);},15000);
|
|
2929
2931
|
var btn=document.createElement('div');
|
|
2930
2932
|
var ci=document.querySelector('.corner-ics');
|
|
2931
2933
|
if(ci){btn.className='ci';btn.textContent='@';ci.appendChild(btn);}
|
|
2932
2934
|
else{btn.textContent='@';btn.style.cssText='position:fixed;right:14px;bottom:60px;z-index:120;width:38px;height:38px;display:flex;align-items:center;justify-content:center;border:2px solid #4cc9ff;background:rgba(7,12,24,.92);color:#4cc9ff;font-size:17px;cursor:pointer;user-select:none;box-shadow:3px 3px 0 rgba(0,0,0,.45)';document.body.appendChild(btn);}
|
|
2933
2935
|
btn.id='acctBtn';btn.title='云存档';
|
|
2934
2936
|
if(acct)btn.style.background='rgba(76,201,255,.28)';
|
|
2937
|
+
lastSnap=canon();
|
|
2935
2938
|
btn.addEventListener('click',open);
|
|
2936
|
-
if(acct&&acct.k){
|
|
2937
|
-
|
|
2939
|
+
setInterval(function(){if(acct&&acct.k){var c=canon();if(c!==lastSnap){lastSnap=c;clearTimeout(pq);pq=setTimeout(push,900);}}},2000);
|
|
2940
|
+
if(acct&&acct.k){setTimeout(function(){pull(false);},250);}
|
|
2941
|
+
window.__shaT=sha;window.__pushT=push;window.__pullT=pull;window.__canonT=canon;
|
|
2938
2942
|
})();
|
|
2939
2943
|
</script>
|
|
2940
2944
|
</body>
|
package/ledger.html
CHANGED
|
@@ -1013,7 +1013,7 @@ window.LEDGER_BACKUP = [];
|
|
|
1013
1013
|
var BASE='https://textdb.dev/api/data/prts-acct-';
|
|
1014
1014
|
var LS='whale.acct',LT='whale.sync.t';
|
|
1015
1015
|
var acct=null;try{acct=JSON.parse(localStorage.getItem(LS)||'null')}catch(e){}
|
|
1016
|
-
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0;
|
|
1016
|
+
var _si=localStorage.setItem.bind(localStorage),_app=0,pq=0,box=null,_dirty=0,lastSnap=null;
|
|
1017
1017
|
|
|
1018
1018
|
function sha(msg){
|
|
1019
1019
|
function r(v,n){return (v>>>n)|(v<<(32-n));}
|
|
@@ -1043,33 +1043,34 @@ window.LEDGER_BACKUP = [];
|
|
|
1043
1043
|
}
|
|
1044
1044
|
function snap(){var d={};for(var i=0;i<TK.length;i++){var v=localStorage.getItem(TK[i]);if(v!==null)d[TK[i]]=v;}return d;}
|
|
1045
1045
|
function url(){return BASE+acct.k;}
|
|
1046
|
+
function wxhr(u,b,cb){try{var x=new XMLHttpRequest();x.open('POST',u,true);x.setRequestHeader('Content-Type','text/plain');x.onload=x.onerror=x.ontimeout=function(){if(cb)cb()};x.send(b);}catch(e){if(cb)cb();}}
|
|
1047
|
+
function canon(){var a=[];for(var i=0;i<TK.length;i++)a.push(TK[i]+'='+localStorage.getItem(TK[i]));return a.join('|');}
|
|
1046
1048
|
function st(m){if(box&&box.st)box.st.textContent=m;}
|
|
1047
|
-
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes());}
|
|
1049
|
+
function clock(){var d=new Date();function p(n){return(n<10?'0':'')+n}return p(d.getHours())+':'+p(d.getMinutes())+':'+p(d.getSeconds());}
|
|
1048
1050
|
function apply(rb){
|
|
1049
1051
|
_app=1;try{for(var k in rb.data){_si(k,rb.data[k]);}}finally{_app=0;}
|
|
1050
|
-
_si(LT,String(rb.t||Date.now()));
|
|
1052
|
+
_si(LT,String(rb.t||Date.now()));lastSnap=canon();
|
|
1051
1053
|
st('✔ 已从云端同步 '+clock()+',即将刷新…');
|
|
1052
|
-
setTimeout(function(){location.reload();},
|
|
1054
|
+
setTimeout(function(){location.reload();},350);
|
|
1053
1055
|
}
|
|
1054
|
-
function push(){
|
|
1056
|
+
function push(ry){
|
|
1055
1057
|
if(!acct||!acct.k)return;
|
|
1056
|
-
|
|
1058
|
+
if(!ry)window.__pv=0;
|
|
1059
|
+
_dirty=0;var t=Date.now();_si(LT,String(t));lastSnap=canon();
|
|
1057
1060
|
st('↻ 同步中…');
|
|
1058
|
-
|
|
1059
|
-
.then(function(){setTimeout(function(){verify(t)},1800);})
|
|
1060
|
-
.catch(function(){st('⚠ 云同步暂不可用(可用存档码手动搬)');});
|
|
1061
|
+
wxhr(url(),JSON.stringify({v:1,u:acct.u,t:t,data:snap()}),function(){st('✔ 已上传 · 后台校验…');setTimeout(function(){verify(t)},600);});
|
|
1061
1062
|
}
|
|
1062
1063
|
function verify(t){
|
|
1063
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1064
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1064
1065
|
x=(x||'').replace(/=$/,'');
|
|
1065
1066
|
try{var rb=JSON.parse(x);if(rb.t===t){st('✔ 已同步 '+clock());return;}}catch(e){}
|
|
1066
|
-
if(!window.__pv){window.__pv=1;setTimeout(function(){
|
|
1067
|
-
else{st('⚠
|
|
1067
|
+
if(!window.__pv){window.__pv=1;setTimeout(function(){push(1);},800);}
|
|
1068
|
+
else{window.__pv=0;st('⚠ 上传好像没送达(此浏览器限制跨域)——数据还在本机,可换 Safari 或用存档码');}
|
|
1068
1069
|
}).catch(function(){st('⚠ 校验失败(可能网络受限)');});
|
|
1069
1070
|
}
|
|
1070
1071
|
function pull(manual){
|
|
1071
1072
|
if(!acct||!acct.k)return;
|
|
1072
|
-
fetch(url()+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1073
|
+
fetch(url()+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1073
1074
|
x=(x||'').replace(/=$/,'');
|
|
1074
1075
|
if(!x){if(manual)st('☁ 云端暂时没有存档——点「立即同步」上传本机数据');return;}
|
|
1075
1076
|
var rb;try{rb=JSON.parse(x)}catch(e){st('⚠ 云端数据格式异常');return;}
|
|
@@ -1129,11 +1130,11 @@ window.LEDGER_BACKUP = [];
|
|
|
1129
1130
|
st('✦ 仓库已创建,正在上传本机数据…');render();push();return;
|
|
1130
1131
|
}
|
|
1131
1132
|
st('↻ 查找云端仓库…');
|
|
1132
|
-
fetch(BASE+k+'?ts='+Date.now()).then(function(r){return r.text()}).then(function(x){
|
|
1133
|
+
fetch(BASE+k+'?ts='+Date.now(),{cache:'no-store'}).then(function(r){return r.text()}).then(function(x){
|
|
1133
1134
|
x=(x||'').replace(/=$/,'');
|
|
1134
1135
|
if(x&&x.length>2){
|
|
1135
1136
|
acct={u:u,k:k};_si(LS,JSON.stringify(acct));
|
|
1136
|
-
var rb=null;try{rb=JSON.parse(x)}catch(e){}
|
|
1137
|
+
var rb=null;try{rb=JSON.parse(x)}catch(e){}if(!rb){acct=null;localStorage.removeItem(LS);st('⚠ 云端数据异常(可能被误写入过)——没敢覆盖,联系鲸鲸');return;}
|
|
1137
1138
|
if(rb&&(rb.t||0)>Number(localStorage.getItem(LT)||0)){apply(rb);}
|
|
1138
1139
|
else{_si(LT,String((rb&&rb.t)||Date.now()));st('✔ 已登录,云端仓库已连接 '+clock());render();}
|
|
1139
1140
|
}else{
|
|
@@ -1166,21 +1167,24 @@ window.LEDGER_BACKUP = [];
|
|
|
1166
1167
|
}
|
|
1167
1168
|
function open(){render();wrap.classList.add('on')}
|
|
1168
1169
|
var _orig=localStorage.setItem;
|
|
1169
|
-
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,
|
|
1170
|
+
localStorage.setItem=function(k,v){_orig.call(localStorage,k,v);if(!_app&&acct&&acct.k&&TK.indexOf(k)>=0&&k!==LT){_dirty=1;clearTimeout(pq);pq=setTimeout(push,900);}};
|
|
1170
1171
|
window.addEventListener('pagehide',function(){
|
|
1171
1172
|
if(acct&&acct.k&&_dirty){try{_dirty=0;_si(LT,String(Date.now()));
|
|
1172
|
-
|
|
1173
|
+
var x=new XMLHttpRequest();x.open('POST',url(),false);x.setRequestHeader('Content-Type','text/plain');x.send(JSON.stringify({v:1,u:acct.u,t:Date.now(),data:snap()}));}catch(e){}}
|
|
1173
1174
|
});
|
|
1174
|
-
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k)
|
|
1175
|
+
document.addEventListener('visibilitychange',function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);});
|
|
1176
|
+
setInterval(function(){if(!document.hidden&&acct&&acct.k&&!wrap.classList.contains('on'))pull(false);},15000);
|
|
1175
1177
|
var btn=document.createElement('div');
|
|
1176
1178
|
var ci=document.querySelector('.corner-ics');
|
|
1177
1179
|
if(ci){btn.className='ci';btn.textContent='@';ci.appendChild(btn);}
|
|
1178
1180
|
else{btn.textContent='@';btn.style.cssText='position:fixed;right:14px;bottom:60px;z-index:120;width:38px;height:38px;display:flex;align-items:center;justify-content:center;border:2px solid #4cc9ff;background:rgba(7,12,24,.92);color:#4cc9ff;font-size:17px;cursor:pointer;user-select:none;box-shadow:3px 3px 0 rgba(0,0,0,.45)';document.body.appendChild(btn);}
|
|
1179
1181
|
btn.id='acctBtn';btn.title='云存档';
|
|
1180
1182
|
if(acct)btn.style.background='rgba(76,201,255,.28)';
|
|
1183
|
+
lastSnap=canon();
|
|
1181
1184
|
btn.addEventListener('click',open);
|
|
1182
|
-
if(acct&&acct.k){
|
|
1183
|
-
|
|
1185
|
+
setInterval(function(){if(acct&&acct.k){var c=canon();if(c!==lastSnap){lastSnap=c;clearTimeout(pq);pq=setTimeout(push,900);}}},2000);
|
|
1186
|
+
if(acct&&acct.k){setTimeout(function(){pull(false);},250);}
|
|
1187
|
+
window.__shaT=sha;window.__pushT=push;window.__pullT=pull;window.__canonT=canon;
|
|
1184
1188
|
})();
|
|
1185
1189
|
</script>
|
|
1186
1190
|
</body>
|