feat(external-script): detect more than one script dom, fixed #146
This commit is contained in:
parent
920f624b5c
commit
94d6603c06
1 changed files with 12 additions and 8 deletions
|
|
@ -1,16 +1,20 @@
|
||||||
function handleExternalScript () {
|
function handleExternalScript () {
|
||||||
const container = Docsify.dom.getNode('#main')
|
const container = Docsify.dom.getNode('#main')
|
||||||
const script = Docsify.dom.find(container, 'script')
|
const scripts = Docsify.dom.findAll(container, 'script')
|
||||||
|
|
||||||
if (script && script.src) {
|
for (let i = scripts.length; i--;) {
|
||||||
const newScript = document.createElement('script')
|
const script = scripts[i]
|
||||||
|
|
||||||
;['src', 'async', 'defer'].forEach(attribute => {
|
if (script && script.src) {
|
||||||
newScript[attribute] = script[attribute]
|
const newScript = document.createElement('script')
|
||||||
})
|
|
||||||
|
|
||||||
script.parentNode.insertBefore(newScript, script)
|
;['src', 'async', 'defer'].forEach(attribute => {
|
||||||
script.parentNode.removeChild(script)
|
newScript[attribute] = script[attribute]
|
||||||
|
})
|
||||||
|
|
||||||
|
script.parentNode.insertBefore(newScript, script)
|
||||||
|
script.parentNode.removeChild(script)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue