1
0
Fork 0

Add workaround .innerHTML stripping <script> tags

This commit is contained in:
Carlos Mogas da Silva 2021-06-26 01:50:00 +01:00
parent e5ac232d3e
commit f708d7ff7e

View file

@ -64,7 +64,23 @@ window.onload = () => {
let parent = elements[index];
let encrypted = parent.querySelector(".hugo-enc-cipher-text").innerText.trim();
let decrypted = _do_decrypt(encrypted, password);
// Workaround .innerHTML stripping <script> tags
// First we save all the script tags
re = /<script.*?<\/script>/;
script_tags = re.exec(decrypted);
elements[index].innerHTML = decrypted;
// Now we add all script tags back into the html element
html_element = document.getElementsByTagName("html")[0];
range = document.createRange();
range.setStart(html_element, 0);
script_tags.forEach(tag => {
html_element.appendChild(range.createContextualFragment(tag));
});
}
}
};