-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
150 lines (141 loc) · 5.55 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta id="meta-theme-color" name="theme-color" content="">
<link rel="manifest" href="resources/manifest.json">
<link rel="icon" href="resources/app_icon.svg" type="image/svg+xml">
<title>Music Cloud</title>
<!-- Preload style -->
<style>
* {
box-sizing: border-box;
}
#preload-overlay {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
z-index: 1000;
text-align: center;
background: white;
color: black;
font-family: sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
}
.dark #preload-overlay {
background: black;
color: #ccc;
}
#preload-overlay h1 {
margin: 10px 5px;
}
#preload-overlay p {
margin: 10px 5px;
}
</style>
<!-- Preload script which waits for main script loading and displays status -->
<script>
(function () {
var preload = window.preload = {
domLoaded: false,
jsLoaded: false,
jsError: false,
preLoginTask: null,
inputToken: null,
jsOk() {
this.jsLoaded = true
this.update();
},
onJsLoad() {
setTimeout(function (thiz) {
if (!thiz.jsLoaded) {
console.error('js loaded without calling callback');
thiz.jsError = true;
thiz.update();
}
}, 1000, this);
},
update() {
if (!this.domLoaded) return;
document.getElementById('js-ok').hidden = !preload.jsLoaded;
document.getElementById('js-error').hidden = !preload.jsError;
document.getElementById('js-error-msg').hidden = !preload.jsError;
if (this.jsLoaded) this.end();
},
end() {
app.ui.endPreload();
window.removeEventListener('error', onerror);
},
preLogin() {
// Try to prefetch the user info even before we can run the main script.
// Make it about 1 RTT + 50 ms (script download + execution time) faster.
var strLogin = localStorage.getItem('mcloud-login');
if (!strLogin) return;
var login = JSON.parse(strLogin);
if (!login || !login.token || !login.lastBaseUrl) return;
preload.preLoginTask = fetch(login.lastBaseUrl + 'users/me', {
credentials: 'same-origin',
headers: {
'Authorization': 'Bearer ' + login.token,
'Cache-Control': 'no-store'
}
}).then(function (resp) {
if (!resp.ok) {
throw new Error('HTTP status ' + resp.status);
}
return resp.json()
});
}
};
window.addEventListener('DOMContentLoaded', function () {
preload.domLoaded = true;
preload.update();
// Set the theme ASAP to avoid blinking
if (['dark', 'dark-rounded'].indexOf(localStorage.getItem('mcloud-theme')) >= 0) {
document.body.classList.add('dark');
document.getElementById('meta-theme-color').content = 'black';
}
});
var onerror = function (e) {
preload.jsError = true;
document.getElementById('js-error-msg').textContent = "" + e.error;
preload.update();
};
var handleToken = function () {
var splits = window.location.href.split('#token=');
if (splits.length > 1) {
preload.inputToken = splits[1];
window.history.replaceState(null, null, splits[0]);
}
};
window.addEventListener('error', onerror);
handleToken();
preload.preLogin();
})();
</script>
<!-- End of preload style and script -->
<script src="bundle.js?v=1.0.11-4" onload="window.preload && preload.onJsLoad()" defer async></script>
</head>
<body>
<div id="preload-overlay" lang="en">
<h1>MusicCloud</h1>
<div style="min-height: 6em;">
<p>Loading...</p>
<p hidden style="color: gray;" id="js-ok">JavaScript OK</p>
<p hidden style="color: red;" id="js-error">JavaScript Error</p>
<p hidden id="js-error-msg"></p>
</div>
<noscript>
<p>JavaScript is required to run this application.</p>
</noscript>
</div>
</body>
</html>