mirror of
https://gitee.com/docsifyjs/docsify.git
synced 2024-12-03 04:31:20 +08:00
feat(external-script): detect more than one script dom, fixed #146
This commit is contained in:
parent
920f624b5c
commit
94d6603c06
@ -1,16 +1,20 @@
|
||||
function handleExternalScript () {
|
||||
const container = Docsify.dom.getNode('#main')
|
||||
const script = Docsify.dom.find(container, 'script')
|
||||
const scripts = Docsify.dom.findAll(container, 'script')
|
||||
|
||||
if (script && script.src) {
|
||||
const newScript = document.createElement('script')
|
||||
for (let i = scripts.length; i--;) {
|
||||
const script = scripts[i]
|
||||
|
||||
;['src', 'async', 'defer'].forEach(attribute => {
|
||||
newScript[attribute] = script[attribute]
|
||||
})
|
||||
if (script && script.src) {
|
||||
const newScript = document.createElement('script')
|
||||
|
||||
script.parentNode.insertBefore(newScript, script)
|
||||
script.parentNode.removeChild(script)
|
||||
;['src', 'async', 'defer'].forEach(attribute => {
|
||||
newScript[attribute] = script[attribute]
|
||||
})
|
||||
|
||||
script.parentNode.insertBefore(newScript, script)
|
||||
script.parentNode.removeChild(script)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user