scripts now loading in order as specified
one after another so they can depend on each other
This commit is contained in:
+30
-49
@@ -1,55 +1,34 @@
|
|||||||
// function clone_script_node(node){
|
function load_script(o_script, callback) {
|
||||||
// // console.log("\n\n\nnew script!")
|
|
||||||
// var script = document.createElement("script");
|
|
||||||
// script.text = node.innerHTML;
|
|
||||||
// // console.log("text: " + script.text)
|
|
||||||
// var i = -1, attrs = node.attributes, attr;
|
|
||||||
// while (++i < attrs.length) {
|
|
||||||
// script.setAttribute((attr = attrs[i]).name, attr.value);
|
|
||||||
// if (attr.name === "src")
|
|
||||||
// console.log(attr.value)
|
|
||||||
// }
|
|
||||||
// return script;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
let script = document.createElement('script');
|
||||||
|
script.type = o_script.type || 'text/javascript';
|
||||||
|
|
||||||
// function replace_all_script_nodes(node) {
|
if(o_script.hasAttribute('src')) {
|
||||||
// if (node.tagName === 'SCRIPT') {
|
script.src = o_script.src;
|
||||||
// node.parentNode.replaceChild(clone_script_node(node), node);
|
script.onload = callback
|
||||||
// } else {
|
}
|
||||||
// var i = -1, children = node.childNodes;
|
|
||||||
// while (++i < children.length) {
|
script.innerHTML = o_script.innerHTML;
|
||||||
// replace_all_script_nodes(children[i]);
|
document.head.appendChild(script);
|
||||||
// }
|
|
||||||
// }
|
if(o_script.src === "") {
|
||||||
|
// NOTE(Felix): it seems the onload is not called on script nodes that
|
||||||
// return node;
|
// define the js inline instead of through a src attribute, so for
|
||||||
// }
|
// them we call the callback manually and hope for the best.
|
||||||
|
callback();
|
||||||
function insertHTML(html){
|
|
||||||
// if no append is requested, clear the target element
|
|
||||||
// if(!append) dest.innerHTML = '';
|
|
||||||
// create a temporary container and insert provided HTML code
|
|
||||||
let container = document.createElement('div');
|
|
||||||
container.innerHTML = html;
|
|
||||||
// cache a reference to all the scripts in the container
|
|
||||||
let scripts = container.querySelectorAll('script');
|
|
||||||
// get all child elements and clone them in the target element
|
|
||||||
let nodes = container.childNodes;
|
|
||||||
// for( let i=0; i< nodes.length; i++) dest.appendChild( nodes[i].cloneNode(true) );
|
|
||||||
// force the found scripts to execute...
|
|
||||||
for( let i=0; i< scripts.length; i++){
|
|
||||||
let script = document.createElement('script');
|
|
||||||
script.type = scripts[i].type || 'text/javascript';
|
|
||||||
if( scripts[i].hasAttribute('src') ) script.src = scripts[i].src;
|
|
||||||
script.innerHTML = scripts[i].innerHTML;
|
|
||||||
document.head.appendChild(script);
|
|
||||||
document.head.removeChild(script);
|
|
||||||
}
|
}
|
||||||
// done!
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var next_script_index = 0
|
||||||
|
var deferred_scripts = []
|
||||||
|
|
||||||
|
function load_next_deferred_script() {
|
||||||
|
console.log("recurse!")
|
||||||
|
if (next_script_index >= deferred_scripts.length)
|
||||||
|
return
|
||||||
|
|
||||||
|
load_script(deferred_scripts[next_script_index++], () => load_next_deferred_script())
|
||||||
|
}
|
||||||
|
|
||||||
function decrypt_page() {
|
function decrypt_page() {
|
||||||
var key_str = ""
|
var key_str = ""
|
||||||
@@ -115,8 +94,10 @@ function decrypt_page() {
|
|||||||
var dec_text = new TextDecoder().decode(dec_bytes)
|
var dec_text = new TextDecoder().decode(dec_bytes)
|
||||||
document.body.outerHTML = "<body" + dec_text + "</body>"
|
document.body.outerHTML = "<body" + dec_text + "</body>"
|
||||||
|
|
||||||
// insertHTML(document.body.innerHTML)
|
|
||||||
// replace_all_script_nodes(document.getElementsByTagName("body")[0]);
|
deferred_scripts = document.body.querySelectorAll('script');
|
||||||
|
load_next_deferred_script()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.onload = decrypt_page
|
window.onload = decrypt_page
|
||||||
|
|||||||
Reference in New Issue
Block a user