mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Revert "Guarantee execution order of <script> elements (#1574)"
This reverts commit36e20fd110
. Reverting until this can be investigated:36e20fd110 (commitcomment-62861929)
This commit is contained in:
parent
36e20fd110
commit
349d5d0862
1 changed files with 8 additions and 14 deletions
|
@ -59,16 +59,7 @@ export function _queueAction(action: Callback): void {
|
||||||
_updatingQueue = _updatingQueue.then(action);
|
_updatingQueue = _updatingQueue.then(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceScriptPromise(script: HTMLScriptElement): Promise<void> {
|
function setInnerHTML(element: Element, html: string): void {
|
||||||
return new Promise((resolve) => {
|
|
||||||
const newScript = script.cloneNode(true);
|
|
||||||
newScript.addEventListener("load", () => resolve());
|
|
||||||
newScript.addEventListener("error", () => resolve());
|
|
||||||
script.replaceWith(newScript);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setInnerHTML(element: Element, html: string): Promise<void> {
|
|
||||||
for (const oldVideo of element.getElementsByTagName("video")) {
|
for (const oldVideo of element.getElementsByTagName("video")) {
|
||||||
oldVideo.pause();
|
oldVideo.pause();
|
||||||
|
|
||||||
|
@ -82,11 +73,14 @@ async function setInnerHTML(element: Element, html: string): Promise<void> {
|
||||||
element.innerHTML = html;
|
element.innerHTML = html;
|
||||||
|
|
||||||
for (const oldScript of element.getElementsByTagName("script")) {
|
for (const oldScript of element.getElementsByTagName("script")) {
|
||||||
if (oldScript.src) {
|
const newScript = document.createElement("script");
|
||||||
await replaceScriptPromise(oldScript);
|
|
||||||
} else {
|
for (const attribute of oldScript.attributes) {
|
||||||
oldScript.replaceWith(oldScript.cloneNode(true));
|
newScript.setAttribute(attribute.name, attribute.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newScript.appendChild(document.createTextNode(oldScript.innerHTML));
|
||||||
|
oldScript.parentNode!.replaceChild(newScript, oldScript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue