loadScript.js
1.87 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
64
65
66
67
68
69
70
71
; (function () {
/**
* Synchronously adds scripts to the page.
*/
function loadScript(src, onLoad) {
const script = document.createElement('script')
script.setAttribute('type', 'text/javascript');
script.setAttribute('defer', 'true');
script.setAttribute('src', src);
const top = document.getElementsByTagName('script')[0];
if (onLoad != null) {
var ready = false;
script.onload = script.onreadystatechange = function () {
if (!ready && (!this.readyState || this.readyState == 'complete')) {
ready = true;
onLoad();
}
};
}
if (top != null) {
top.parentNode.insertBefore(script, top);
}
};
function loadStyleLink(href) {
const link = document.createElement('link')
link.setAttribute('href', href)
link.setAttribute('rel', 'stylesheet')
const top = document.getElementsByTagName('link')[0];
if (top != null) {
top.parentNode.insertBefore(link, top);
}
}
let loadScriptList = [
{ path: './js/plugin/echarts/echarts.js' },
{ path: './js/plugin/video/video.min.js' },
{ path: './js/plugin/video/flv.min.js' },
{ path: './js/plugin/video/videojs-flvjs.min.js' },
{ path: './js/plugin/fingerprint/fingerprint.js' },
{ path: './js/plugin/ace/ace.js' },
]
let loadStyleList = [
{ path: './js/plugin/video/video-js.min.css' }
]
const getFileNameFromPath = (path) => {
const reg = /.*\/(.*)/g
return path.replace(reg, '$1')
}
if (Enable_OSS) {
loadScriptList = loadScriptList.map((item) => ({ ...item, path: OSS_Prefix + getFileNameFromPath(item.path) }))
loadStyleList = loadStyleList.map((item) => ({ ...item, path: OSS_Prefix + getFileNameFromPath(item.path) }))
}
for (const { path } of loadStyleList) {
loadStyleLink(path)
}
for (const { path } of loadScriptList) {
loadScript(path)
}
})();