Skip to content

Commit 94d6603

Browse files
committed
feat(external-script): detect more than one script dom, fixed #146
1 parent 920f624 commit 94d6603

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/plugins/external-script.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
function handleExternalScript () {
22
const container = Docsify.dom.getNode('#main')
3-
const script = Docsify.dom.find(container, 'script')
3+
const scripts = Docsify.dom.findAll(container, 'script')
44

5-
if (script && script.src) {
6-
const newScript = document.createElement('script')
5+
for (let i = scripts.length; i--;) {
6+
const script = scripts[i]
77

8-
;['src', 'async', 'defer'].forEach(attribute => {
9-
newScript[attribute] = script[attribute]
10-
})
8+
if (script && script.src) {
9+
const newScript = document.createElement('script')
1110

12-
script.parentNode.insertBefore(newScript, script)
13-
script.parentNode.removeChild(script)
11+
;['src', 'async', 'defer'].forEach(attribute => {
12+
newScript[attribute] = script[attribute]
13+
})
14+
15+
script.parentNode.insertBefore(newScript, script)
16+
script.parentNode.removeChild(script)
17+
}
1418
}
1519
}
1620

0 commit comments

Comments
 (0)