-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathexternal-script.js
More file actions
30 lines (23 loc) · 748 Bytes
/
external-script.js
File metadata and controls
30 lines (23 loc) · 748 Bytes
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
const window = /** @type {any} */ (globalThis);
function handleExternalScript() {
const container = Docsify.dom.getNode('#main');
const scripts = /** @type {HTMLScriptElement[]} */ (
Docsify.dom.findAll(container, 'script')
);
for (const script of scripts) {
if (script.src) {
const newScript = document.createElement('script');
Array.from(script.attributes).forEach(attribute => {
newScript[attribute.name] = attribute.value;
});
script.before(newScript);
script.remove();
}
}
}
const install = function (hook) {
hook.doneEach(handleExternalScript);
};
window.$docsify = window.$docsify || {};
window.$docsify.plugins = [install, ...(window.$docsify.plugins || [])];
export {};