1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
|
const litespeed_ui_events=["mouseover","click","keydown","wheel","touchmove","touchstart"];var litespeed_delay_i=0,urlCreator=window.URL||window.webkitURL;function litespeed_load_delayed_js_forced(){console.log("[LiteSpeed] Start Load JS Delayed"),litespeed_ui_events.forEach(function(e){window.removeEventListener(e,litespeed_load_delayed_js_forced,{passive:!0})}),litespeed_load_delayed_js(!0),document.querySelectorAll("iframe[data-litespeed-src]").forEach(function(e){e.setAttribute("src",e.getAttribute("data-litespeed-src"))})}function litespeed_load_delayed_js(e){e&&console.log("[LiteSpeed] Force running delayed JS"),litespeed_load_one()}function litespeed_inline2src(t){try{var d=urlCreator.createObjectURL(new Blob([t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1")],{type:"text/javascript"}))}catch(e){d="data:text/javascript;base64,"+btoa(t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1"))}return d}function litespeed_load_one(){litespeed_delay_i++;var t,d=document.querySelector('script[type="litespeed/javascript"][data-i="'+litespeed_delay_i+'"]');d?(console.log("[LiteSpeed] Load i="+d.getAttribute("data-i"),"-----",d),(t=document.createElement("script")).addEventListener("load",function(){console.log("[LiteSpeed] loaded --- "+t.getAttribute("data-i")),litespeed_load_one()},{passive:!0}),t.addEventListener("error",function(){console.log("[LiteSpeed] loaded error! --- "+t.getAttribute("data-i")),litespeed_load_one()},{passive:!0}),d.getAttributeNames().forEach(function(e){"type"!=e&&t.setAttribute("data-src"==e?"src":e,d.getAttribute(e))}),t.type="text/javascript",!t.src&&d.textContent&&(t.src=litespeed_inline2src(d.textContent)),d.after(t),d.remove()):console.log("[LiteSpeed] All loaded!")}litespeed_ui_events.forEach(function(e){window.addEventListener(e,litespeed_load_delayed_js_forced,{passive:!0})});
|