-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·119 lines (100 loc) · 3.13 KB
/
index.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
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
function loadScript(script, dependentName) {
var bodyTag = document.getElementsByTagName('body')[0];
var appendScript = document.createElement('script');
var dependentScripts;
var i;
var totalLength;
if (typeof script === 'object') {
if (script.url) {
appendScript.src = script.url;
if (script.async) {
appendScript.async = true;
}
if (script.referrerPolicy) {
appendScript.referrerPolicy = script.referrerPolicy;
}
} else if (script.inline) {
appendScript.innerHTML = script.inline;
} else {
return;
}
if (script.id) {
appendScript.id = script.id;
}
if (script.nomodule) {
appendScript.noModule = true;
}
} else {
appendScript.src = script;
}
if (dependentName !== '') {
document.getElementById(dependentName).addEventListener('load', function() {
bodyTag.appendChild(appendScript);
if (typeof script === 'object' && script.dependentScripts && script.dependentScripts.length > 0) {
dependentName = '';
if (appendScript.id) {
dependentName = appendScript.id;
}
dependentScripts = script.dependentScripts;
totalLength = dependentScripts.length;
for (i = 0; i < totalLength; i += 1) {
loadScript(dependentScripts[i], dependentName);
}
}
});
} else {
bodyTag.appendChild(appendScript);
if (typeof script === 'object' && script.dependentScripts && script.dependentScripts.length > 0) {
dependentName = '';
if (appendScript.id) {
dependentName = appendScript.id;
}
dependentScripts = script.dependentScripts;
totalLength = dependentScripts.length;
for (i = 0; i < totalLength; i += 1) {
loadScript(dependentScripts[i], dependentName);
}
}
}
return;
}
function addStylesheets(stylePaths) {
var headerTag = document.getElementsByTagName('head')[0];
var appendStyle;
var i;
var totalLength;
if (stylePaths.length > 0) {
totalLength = stylePaths.length;
for (i = 0; i < totalLength; i++) {
if (typeof stylePaths[i] === 'object') {
if (stylePaths[i].href) {
appendStyle = document.createElement('link');
appendStyle.rel = 'stylesheet';
appendStyle.type = 'text/css';
appendStyle.href = stylePaths[i].href;
} else {
appendStyle = document.createElement('style');
appendStyle.innerHTML = stylePaths[i].inline;
}
} else {
appendStyle = document.createElement('link');
appendStyle.rel = 'stylesheet';
appendStyle.type = 'text/css';
appendStyle.href = stylePaths[i];
}
headerTag.appendChild(appendStyle);
}
}
}
function addScripts(scriptPaths) {
var i;
var totalLength;
if (scriptPaths.length > 0) {
totalLength = scriptPaths.length;
for (i = 0; i < totalLength; i += 1) {
loadScript(scriptPaths[i], '');
}
}
}
exports.appendStylesheets = addStylesheets;
exports.appendScripts = addScripts;