-
Notifications
You must be signed in to change notification settings - Fork 2
/
preload.js
83 lines (79 loc) · 1.9 KB
/
preload.js
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
class Preload {
loads = [{
type: "script",
url: "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.8.2-dev.20210831.0/dist/ort.min.js"
}, {
type: "script",
url: "https://docs.opencv.org/4.5.3/opencv.js"
}, {
type: "script",
url: "https://cdn.jsdelivr.net/npm/clipper-lib@6.4.2/clipper.js"
},
{
type: "model",
url: "./models/angle_net.onnx"
}, {
type: "model",
url: "./models/crnn_lite_lstm.onnx"
}, {
type: "model",
url: "./models/dbnet.onnx"
},
{
type: "fetch",
url: "./models/keys.txt"
},
]
constructor() {
this.init();
}
init() {
this.count = this.loads.length;
this.done = 0;
this.loads.map(it => this["pre_" + it.type](it).then(r=>{
this.done++;
document.querySelector("#loadding-box p ").innerHTML = `加载中... (${this.done}/${this.count})`;
if(this.done >= this.count){
document.querySelector("#loadding-box").remove();
this.pre_module({url:"main.js"})
}
}));
}
pre_module(it){
return new Promise(function(resolve) {
const script = document.createElement("script");
script.type = "module";
script.async = true;
script.onload = function() {
resolve()
};
script.onerror = function(error){
reject(error)
}
script.src = it.url;
document.body.appendChild(script)
})
}
pre_script(it) {
return new Promise(function(resolve) {
const script = document.createElement("script");
script.type = "text/javascript";
script.async = true;
script.onload = function() {
resolve()
};
script.onerror = function(error){
reject(error)
}
script.src = it.url;
document.body.appendChild(script)
})
}
pre_model(it){
return fetch(it.url)
}
pre_fetch(it){
return fetch(it.url)
}
}
new Preload();