window.addEventListener('popstate', function () {
if(document.getElementById("swimask")||document.getElementById("sresdiv")||document.getElementById("informmask").style.display=="block")
{try{document.body.removeChild(document.getElementById("swimask"))}catch(e){};try{document.body.removeChild(document.getElementById("sresdiv"))}catch(e){};backgamecode();
}
else
{
try{backclick()}catch(e){console.log(e)}
/*history.back()
msgbox("连按两次退出...")
setTimeout(function(){backgamecode();history.pushState(null, null, document.URL)},500)*/
}
})
var scrwaits=0
function scrget(url,gotname,mfun)
{
scrwaits=0
eval(gotname+"=\"\"")
var gscr=document.createElement("script")
gscr.src=url
$ele("dayxx").appendChild(gscr)
waitfor(gotname,mfun)
function waitfor(gname,mfun)
{
console.log("waiting...")
if(eval(gname)=="")
{scrwaits+=1
if(scrwaits<30)
{setTimeout(waitfor,100,gname,mfun)}
else
{console.log("获取失败!")}
}
else
{
mfun(eval(gname))
}
}
}
/*提示信息通用函数*/
var msgwait=0
function msgbox(tipinfo,ac1,ac2,sstr1,sstr2)
{
if(sstr1){}else{sstr1="是"}
if(sstr2){}else{sstr2="否"}
msgwait=0
mstr="
"+tipinfo+"
"
if(ac1)
{
mstr=mstr+"
| "+sstr1+" |
"
if(ac2)
{
mstr=mstr+" |
| "+sstr2+" |
"
}
mstr=mstr+"
"
}
else
{
mstr=mstr+""
}
tipsinfo(mstr+"",0)
history.pushState(null, null, document.URL)
console.log("historypushed")
setTimeout(function(){func(ac1,ac2)},10)
}
function func(ac1,ac2)
{
switch(msgwait)
{
case 0:
setTimeout("func(0)",10);break
default:
backgame()
break
}
}
function tipsinfo(tipinfo,lasttime)
{
document.getElementById("informmask").style.display="block";document.getElementById("topinfos").style.display="inline-table";
HTMLstr=" 帮登少年生活馆 中房F联邦1栋101门面 |
"
HTMLstr=HTMLstr+"| "+tipinfo+" |
"
document.getElementById("topinfos").innerHTML=HTMLstr;
document.getElementById("informmask").onclick="";document.getElementById("topinfos").onclick=""
}
function tipinfotimer()
{
tcous=tcous-1;
if (tcous<=0)
{
/*document.getElementById("informmask").onclick=function(){this.style.display="none";document.getElementById("topinfos").style.display="none";}
document.getElementById("topinfos").onclick=function(){this.style.display="none";document.getElementById("informmask").style.display="none";}*/
document.getElementById("lefttime").innerText="";
}
else
{
document.getElementById("lefttime").innerText=tcous/10;
tif=setTimeout("tipinfotimer()",100);
}
}
function backgame()
{
history.back()
}
function backgamecode()
{
document.getElementById("informmask").style.display="none";document.getElementById("topinfos").style.display="none";
document.getElementById("informmask").onclick=""
if(document.getElementById("sresdiv")){document.body.removeChild(document.getElementById("sresdiv"))}
}
/*提示信息通用函数*/
function jsonpost(URL,PARAMS,jsonres)
{
var xhr = new XMLHttpRequest();
xhr.open("POST", URL, true);
xhr.setRequestHeader("Content-type", "application/json");
//xhr.setRequestHeader("kbn-version", "5.3.0");
//Access-Control-Allow-Origin: *
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
jsonres(e)
}
}
};
xhr.send(JSON.stringify(PARAMS));
}
function httpget(url,myfun)
{
var HTTP=new XMLHttpRequest()
HTTP.onreadystatechange=function(e){
if(HTTP.readyState==4 && HTTP.status==200){
//json=e.currentTarget.response
myfun(e.currentTarget.response)
}
}
HTTP.open("GET",url);HTTP.send()
}
function US() {
var name, value;
var ds=new Array()
var str = decodeURI(location.href);
var num = str.indexOf("?");
str = str.substr(num + 1);
var arr = str.split("&");
for (var i = 0; i < arr.length; i++) {
num = arr[i].indexOf("=");
if (num > 0) {
name = arr[i].substring(0, num);
value = arr[i].substr(num + 1);
ds[i]=new Array();
ds[i]['name'] = name
ds[i]['value']=value
}
}
return(ds)
}
function httppost(url,paras,myfun)
{
var HTTP=new XMLHttpRequest()
HTTP.onreadystatechange=function(e){
if(HTTP.readyState==4 && HTTP.status==200){
myfun(e.currentTarget.response)
}
}
if(HTTP.upload){
HTTP.upload.addEventListener('progress',function(e)
{
try{
document.getElementById("uproshow").innerHTML=Math.floor(e.loaded/e.total*100)+"%"
}
catch(e){console.log(e)}
})
}
HTTP.open("POST",url);HTTP.send(paras)
}
var db
function getzt()
{
//var req = indexedDB.deleteDatabase("font") //删除旧残余
var request = window.indexedDB.open("font")
request.onsuccess = function (event) {
db = request.result;
console.log(db)
loadzt()
console.log('数据库打开成功');
};
request.onupgradeneeded = function(event) {
db = event.target.result;
var objectStore = db.createObjectStore('font', { keyPath: 'id' });
console.log("onupgradeneeded")
}
}
function loadzt()
{
try{
var transaction = db.transaction(['font']);
}
catch(e){
var objectStore = db.createObjectStore('font', { keyPath: 'id' });
}
//var req = indexedDB.deleteDatabase(databaseName)
try{var objectStore = transaction.objectStore('font');}
catch(e){
db = event.target.result;
var objectStore = db.createObjectStore('font', { keyPath: 'id' });
}
var request = objectStore.get(1);
request.onsuccess = function( event) {
if (request.result) {
nstyle=document.createElement("style")
nstyle.innerHTML=request.result.base64
document.body.appendChild(nstyle)
//msgbox("字体缓存了")
} else {
addzt()
}
};
}
function addzt()
{
console.log("刷新字体 ")
httpget("/stylesheet.css",function(e){
nstyle=document.createElement("style")
nstyle.innerHTML=e
document.body.appendChild(nstyle)
//msgbox("字体刷新了")
var request = db.transaction(['font'], 'readwrite')
.objectStore('font')
.add({ id:1,font: "xingkai", base64:e,});
request.onsuccess = function (event) {
console.log('数据写入成功');
};
request.onerror = function (event) {
console.log('数据写入失败');
}
})
}
function getztwebsql()
{
var db=openDatabase('dbname','1.0','this is a string',10*1024*1024);
//db.transaction(function (context) {context.executeSql('delete from testTable',[]);})
db.transaction(function (context) {
context.executeSql('SELECT * FROM testTable', [], function (context, results) {
var len = results.rows.length;
console.log('Got '+len+' rows.');
/*for (i = 0; i < len; i++){
console.log('id: '+results.rows.item(i).id);
console.log('name: '+results.rows.item(i).name);*/
if(len==0)
{
console.log("刷新中...")
httpget("/stylesheet.css",function(e){
db.transaction(function (context) {
context.executeSql('DROP TABLE IF EXISTS testTable');
context.executeSql('CREATE TABLE IF NOT EXISTS testTable (tkey,tvalue)');
context.executeSql('INSERT INTO testTable (tkey, tvalue) VALUES ("font", ?)',[e]);
nstyle=document.createElement("style")
nstyle.innerHTML=e
document.body.appendChild(nstyle)
console.log(e)
alert("字体刷新again")
});
})
}
else
{
console.log(results.rows.item(0).tvalue)
nstyle=document.createElement("style")
nstyle.innerHTML=results.rows.item(0).tvalue
document.body.appendChild(nstyle)
alert("字体缓存")
}
})
})
}
function xhzd(hz,zfun)
{
httppost("/xhzd.asp",hz,function(e){
console.log(e)
hz=JSON.parse(e).hz
zfun(hz)
})
}
function sypy(py)
{
if(pysy.py.length==0){setTimeout(sypy,200,py);return}
var elist=[]
var rl=[]
for(var i in pysy.py)
{
if(pysy.py[i].p==py){elist.push(i)}
}
for(var i in elist)
{
for(var j in pysy.py[elist[i]].l)
{rl.push(pysy.py[elist[i]].l[j])}
}
console.log(py)
console.log(pysy)
return rl
}
function getpysy(hz)
{
var tmp=localStorage.getItem("pysy")
if(tmp)
{initpysy(tmp);console.log("本地拼音索引")}
else
{httpget("/pysy.txt?r="+Math.random(),function(e){initpysy(e);localStorage.setItem("pysy",e);console.log("新下载拼音索引")})}
}
function getenwords()
{
var tmp=localStorage.getItem("enwords")
if(tmp)
{initen(tmp);console.log("本地单词")}
else
{httpget("/ensy.txt",function(e){initen(e);localStorage.setItem("enwords",e);console.log("新下载单词")})}
}
function initen(estr)
{
console.log(estr)
}
function initpysy(ostr)
{
pysy=JSON.parse("{\"py\":[],\"pinyin\":[]}")
var tj=JSON.parse(ostr)
console.log(tj)
for(var i in tj.py)
{
//var tmp={}
//tmp[tj.py[i]['p']]=tj.py[i]['l']
pysy.py[tj.py[i]['p']]=tj.py[i]['l']
}
for(var i in tj.pinyin)
{
var tmp=tj.pinyin[i]['p']
tmp=tj.pinyin[i]['p'].replace(/ɑ/,"ɑ")
tmp=tmp.replace(/a/,"ɑ")
var sd=0
if(tj.pinyin[i]['p'].indexOf("ā")>-1||tj.pinyin[i]['p'].indexOf("ō")>-1||tj.pinyin[i]['p'].indexOf("ē")>-1||tj.pinyin[i]['p'].indexOf("ī")>-1||tj.pinyin[i]['p'].indexOf("ū")>-1||tj.pinyin[i]['p'].indexOf("ǖ")>-1)
{
sd=1
tmp=tj.pinyin[i]['p'].replace(/ā/,"ɑ")
tmp=tmp.replace(/ō/,"o")
tmp=tmp.replace(/ē/,"e")
tmp=tmp.replace(/ī/,"i")
tmp=tmp.replace(/ū/,"u")
tmp=tmp.replace(/ǖ/,"ü")
}
if(tj.pinyin[i]['p'].indexOf("á")>-1||tj.pinyin[i]['p'].indexOf("ó")>-1||tj.pinyin[i]['p'].indexOf("é")>-1||tj.pinyin[i]['p'].indexOf("í")>-1||tj.pinyin[i]['p'].indexOf("ú")>-1||tj.pinyin[i]['p'].indexOf("ǘ")>-1)
{
sd=2
tmp=tj.pinyin[i]['p'].replace(/á/,"ɑ")
tmp=tmp.replace(/ó/,"o")
tmp=tmp.replace(/é/,"e")
tmp=tmp.replace(/í/,"i")
tmp=tmp.replace(/ú/,"u")
tmp=tmp.replace(/ǘ/,"ü")
}
if(tj.pinyin[i]['p'].indexOf("ǎ")>-1||tj.pinyin[i]['p'].indexOf("ǒ")>-1||tj.pinyin[i]['p'].indexOf("ě")>-1||tj.pinyin[i]['p'].indexOf("ǐ")>-1||tj.pinyin[i]['p'].indexOf("ǔ")>-1||tj.pinyin[i]['p'].indexOf("ǚ")>-1)
{
sd=3
tmp=tj.pinyin[i]['p'].replace(/ǎ/,"ɑ")
tmp=tmp.replace(/ǒ/,"o")
tmp=tmp.replace(/ě/,"e")
tmp=tmp.replace(/ǐ/,"i")
tmp=tmp.replace(/ǔ/,"u")
tmp=tmp.replace(/ǚ/,"ü")
}
if(tj.pinyin[i]['p'].indexOf("à")>-1||tj.pinyin[i]['p'].indexOf("ò")>-1||tj.pinyin[i]['p'].indexOf("è")>-1||tj.pinyin[i]['p'].indexOf("ì")>-1||tj.pinyin[i]['p'].indexOf("ù")>-1||tj.pinyin[i]['p'].indexOf("ǜ")>-1)
{
sd=4
tmp=tj.pinyin[i]['p'].replace(/à/,"ɑ")
tmp=tmp.replace(/ò/,"o")
tmp=tmp.replace(/è/,"e")
tmp=tmp.replace(/ì/,"i")
tmp=tmp.replace(/ù/,"u")
tmp=tmp.replace(/ǜ/,"ü")
}
if(!pysy.pinyin[tmp])
{pysy.pinyin[tmp]={}}
pysy.pinyin[tmp][sd]={py:tj.pinyin[i]['p'],zl:tj.pinyin[i]['l']}
}
}
var db
function opendb()
{
var request = window.indexedDB.open("baby")
request.onsuccess = function () {
db = request.result;
console.log('数据库打开成功');
};
request.onupgradeneeded = function(event) {
db = event.target.result;
var objectStore = db.createObjectStore('baby', { keyPath: 'id' });
console.log("onupgradeneeded")
}
}
function adddb(fname,fvalue)
{
if(!db){console.log("db no ready.");setTimeout(adddb,100,fname,fvalue);return}
var tmp={id:fname,v:fvalue}
console.log(tmp)
var adb = db.transaction(['baby'], 'readwrite')
.objectStore('baby')
.add(tmp);
adb.onsuccess = function (event) {
console.log('数据写入成功');
};
adb.onerror = function (event) {
var adb = db.transaction(['baby'], 'readwrite')
.objectStore('baby')
.put(tmp);
adb.onsuccess = function (event) {
console.log('数据修改成功');getdb(fname,function(res){console.log("gotdata:");console.log(res)})
};
adb.onerror = function (event) {
console.log('数据修改失败');
}
}
}
function getdb(fname,callback)
{
var adb = db.transaction(['baby'], 'readwrite')
.objectStore('baby')
.get(fname)
adb.onsuccess = function (event) {callback(adb.result)}
}
function FormatDate(sdate)
{
var RadT=new Date(sdate);
Y=RadT.getFullYear()
M=RadT.getMonth()
M+=1
if(M<10){M="0"+M}
D=RadT.getDate()
if(D<10){D="0"+D}
return(Y+"-"+M+"-"+D)
}
function fmttime(sdate)
{
fstr=FormatDate(sdate)
hstr=sdate.getHours()
if(hstr<10){hstr="0"+hstr}
mstr=sdate.getMinutes()
if(mstr<10){mstr="0"+mstr}
sstr=sdate.getSeconds()
if(sstr<10){sstr="0"+sstr}
tstr=fstr+" "+hstr+":"+mstr+":"+sstr
return(tstr)
}
function FormatMoney(moneys)
{
pre=""
if(moneys<0){moneys=-1*moneys;pre="-"}
var Mstr=Math.floor(moneys);
if (Mstr==0){Mstr="0";}
var xsbf=moneys-Mstr;
xsbf=100*xsbf;
xsbf=Math.round(xsbf);
if (xsbf<10) {Mstr=Mstr+"."+"0"+xsbf}else{Mstr=Mstr+"."+xsbf}
return(pre+Mstr);
}
function dateadd(alx,adii,odate)
{
var od=new Date(odate)
switch(alx)
{
case "y":
case "Y":
AY=1*od.getFullYear()+adii*1
nd=AY+"-"+(od.getMonth()+1)+"-"+od.getDate()
break
case "d":
case "D":
ad=od.getTime()
ad+=adii*1000*60*60*24
nd=new Date(ad)
break
default:
if(adii>=0)
{
AY=Math.floor(adii/12);
AM=adii-12*AY
AY=od.getFullYear()+AY;AM=od.getMonth()+AM
if(AM>11)
{
AY+=1;AM=AM-12
}
nd=AY+"-"+(1+AM)+"-"+od.getDate()
}
else
{
AY=Math.floor(-1*adii/12)
AM=-1*adii-12*AY
AY=od.getFullYear()-AY;AM=od.getMonth()-AM
if(AM<0)
{
AY-=1;AM=AM+12
}
nd=AY+"-"+(1+AM)+"-"+od.getDate()
}
break
}
nd=new Date(nd)
nd=nd.getTime()+1000-1000
nd=new Date(nd)
return(nd)
}
function setstyle(sid,stlist){if(!stlist){return};let stmp;
switch(typeof sid){
case "string":stmp=$ele(sid).style;
break;
default:stmp=sid.style;break}
switch(typeof stlist){case "string":
let stys=stlist.split(";");
for(let s in stys)
{let asty=stys[s].split(":");stmp[asty[0]]=asty[1]}
;break;default:for(let sst in stlist){stmp[sst]=stlist[sst]}}}
function tmove(Cid,e,actfun)
{
e.preventDefault();
let mgot=tmvdata(Cid,e)
actfun(mgot.md,mgot.ma,Cid)
}
function tmvdata(Cid,e)
{
EX=e.changedTouches[0].clientX
EY=e.changedTouches[0].clientY
let ele=$ele(Cid)
let tmppos=getElePos(Cid)
mx=tmppos.left
my=tmppos.top
ax=mx+Number(ele.style.width.replace(/px/,""))
ay=my+Number(ele.style.height.replace(/px/,""))
let md=-1;let ma=0
if(EX>mx&&EY>my&&EXmy&&EYax&&EY>my&&EYmx&&EXay&&EX>mx&&EX