-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 1.67 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 1.67 KB
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
// Loading bar
document.addEventListener('DOMContentLoaded', function() {
let states = {
'INIT_BEFORE_MAP_LOADED': {
weight: 0.1,
count: 0,
done: 0
},
'MAP': {
weight: 0.4,
count: 0,
done: 0
},
'INIT_AFTER_MAP_LOADED': {
weight: 0.3,
count: 0,
done: 0
},
'INIT_SESSION': {
weight: 0.2,
count: 0,
done: 0
}
};
const handlers = {
startInitFunctionOrder: (data) => {
if (data.type == 'INIT_SESSION' && states['INIT_BEFORE_MAP_LOADED'].count < 1) {
states['INIT_BEFORE_MAP_LOADED'].count = 1;
states['INIT_BEFORE_MAP_LOADED'].done = 1;
states['MAP'].count = 1;
states['MAP'].done = 1;
states['INIT_AFTER_MAP_LOADED'].count = 1;
states['INIT_AFTER_MAP_LOADED'].done = 1;
}
states[data.type].count += data.count;
},
initFunctionInvoked: (data) => states[data.type].done++,
startDataFileEntries: (data) => states['MAP'].count = data.count,
performMapLoadFunction: (data) => states['MAP'].done++
};
let last = 0;
window.addEventListener('message', (e) => (handlers[e.data.eventName] || (() => {}))(e.data));
setInterval(() => {
let progress = 0;
for (let type in states) {
const state = states[type];
if (state.done < 1 || state.count < 1) continue;
progress += (state.done / state.count) * state.weight;
}
let total = Math.min(Math.round(progress * 100), 100);
if (total < last) total = last;
last = total;
document.getElementById('progress').value = total;
}, 100);});