-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
133 lines (133 loc) · 3.95 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<link rel="shortcut icon" type="image/ico" href="./favicon.ico"/>
<title>膜拜 Siyuan</title>
</head>
<body>
<style>
#global{
position: fixed;
left:0;
top:0;
width: 100%;
height: 100%;
pointer-events:none;
z-index: 1;
}
</style>
<div id="global" class="global"></div>
<div id="app"></div>
<script>
{
'use strict';
const VERSION='0.6.4.2';
const LOCAL=window.location.hostname.includes('localhost');
Object.defineProperty(window,'LOCAL',{get:()=>LOCAL});
function toAbsLoc(loc){
let a=document.createElement('a');
a.href=loc;
return a.href;
}
function loadTag(url){
let qaq=document.createElement('div');
qaq.innerHTML=`Loading <code>${url.split('/').slice(-1)[0]}</code>...`;
let element=document.getElementById('global');
element.appendChild(qaq);
return {
get text(){
return qaq.innerHTML;
},
set text(newText){
qaq.innerHTML=newText;
},
done(){
qaq.innerHTML+=` <span style="color:green;">Done.</span><br>`;
},
failed(){
qaq.innerHTML+=` <span style="color:red;">Failed.</span><br>`;
},
remove(){
element.removeChild(qaq);
},
};
}
function urlScore(url){
return url.includes('cdn')^LOCAL?1:0;
}
async function loadByElement(tagName,defaultAttr,attrName,urls){
urls=urls.map(toAbsLoc);
urls.sort((x,y)=>urlScore(y)-urlScore(x));
for(let url of urls){
let element=document.createElement(tagName);
for(let name in defaultAttr){
element.setAttribute(name,defaultAttr[name]);
}
element.setAttribute(attrName,url);
let handler=loadTag(url);
try{
await new Promise((resolve,reject)=>{
element.addEventListener('load',resolve);
element.addEventListener('error',reject);
document.body.appendChild(element);
});
handler.done();
return url;
}
catch(_){
handler.failed();
document.body.removeChild(element);
}
first=false;
}
throw `load failed:\n${urls.join('\n')}`;
}
function loadScript(urls){
return loadByElement('script',{},'src',urls);
}
function loadCSS(urls){
return loadByElement('link',{rel:'stylesheet'},'href',urls);
}
async function loadText(urls){
urls=urls.map(toAbsLoc);
urls.sort((x,y)=>urlScore(y)-urlScore(x));
for(let url of urls){
let handler=loadTag(url);
try{
let result=(await axios.get(url)).data;
handler.done();
return result;
}
catch(e){
handler.failed();
continue;
}
}
throw `load failed:\n${urls.join('\n')}`;
}
Promise.all([
Promise.all([
LOCAL
?loadScript(['https://cdn.jsdelivr.net/npm/vue/dist/vue.js','../vue.dev.js'])
:loadScript(['https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js','../vue.js']),
loadScript(['https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js','../axios.js'])
.then(
()=>Promise.all([
loadText([`https://cdn.jsdelivr.net/gh/LMOliver/mosiyuan@${VERSION}/ui.html`,'./ui.html']).then((result)=>{window.GAME_UI=result;}),
])
),
])
.then(()=>loadScript([`https://cdn.jsdelivr.net/gh/LMOliver/mosiyuan@${VERSION}/mosiyuan.min.js`,'./mosiyuan.js'])),
loadCSS(['https://cdn.jsdelivr.net/npm/[email protected]/normalize.min.css','../normalize.css']),
loadCSS(['https://cdn.jsdelivr.net/gh/LMOliver/lmoliver.github.io@master/default.min.css','../default.css']),
loadCSS([`https://cdn.jsdelivr.net/gh/LMOliver/mosiyuan@${VERSION}/mosiyuan.min.css`,'./mosiyuan.css']),
])
.then(()=>{
document.getElementById('global').innerHTML='';
});
}
</script>
</body>
</html>