Remove sentinel script node after load

This commit is contained in:
toasted-nutbread 2020-04-22 17:48:42 -04:00
parent d05a5f3c46
commit 749b747728

View File

@ -48,12 +48,14 @@ const dynamicLoader = (() => {
} }
function loadScriptSentinel(resolve, reject) { function loadScriptSentinel(resolve, reject) {
const parent = document.body;
const script = document.createElement('script'); const script = document.createElement('script');
const sentinelEventName = 'dynamicLoaderSentinel'; const sentinelEventName = 'dynamicLoaderSentinel';
const sentinelEventCallback = (e) => { const sentinelEventCallback = (e) => {
if (e.script !== script) { return; } if (e.script !== script) { return; }
yomichan.off(sentinelEventName, sentinelEventCallback); yomichan.off(sentinelEventName, sentinelEventCallback);
parent.removeChild(script);
resolve(); resolve();
}; };
yomichan.on(sentinelEventName, sentinelEventCallback); yomichan.on(sentinelEventName, sentinelEventCallback);
@ -61,7 +63,7 @@ const dynamicLoader = (() => {
try { try {
script.async = false; script.async = false;
script.src = '/mixed/js/dynamic-loader-sentinel.js'; script.src = '/mixed/js/dynamic-loader-sentinel.js';
document.body.appendChild(script); parent.appendChild(script);
} catch (e) { } catch (e) {
yomichan.off(sentinelEventName, sentinelEventCallback); yomichan.off(sentinelEventName, sentinelEventCallback);
reject(e); reject(e);