diff --git a/waitless.min.js b/waitless.min.js index c8cbbbf..ab2b2af 100644 --- a/waitless.min.js +++ b/waitless.min.js @@ -1 +1 @@ -!function(t){let e={scripts:[],functions:[],isLibraryAvailable:function t(e){return void 0!==window[e]}},n=["keydown","mousemove","wheel","touchmove","touchstart","touchend"],o=!1;function r(t,e){n.forEach(t=>{document.removeEventListener(t,c)});let o=0,r=t.length;t.forEach(function(t){let{src:n,location:i="body",callback:c}=t,a=document.createElement("script");a.src=n;let s=!1;a.onload=function(){if(!s){var t;s=!0,t=c,++o===r&&"function"==typeof e&&e(),"function"==typeof t&&t()}},a.onerror=function(){s||(s=!0,function t(n,i){let c=Error(`Failed to load script: ${n}`);o++,"function"==typeof i&&i(c),o===r&&"function"==typeof e&&e(c)}(n,c))},"head"===i?document.head.appendChild(a):"body"===i&&document.body.appendChild(a)});let i=document.querySelectorAll("script[waitless]"),a=/^(?:https?:\/\/)?(?:[a-zA-Z0-9-]+\.)?[a-zA-Z0-9-]+\.[a-zA-Z0-9]+(?:\/(?:[^\/.]+\/)*[^\/.]+\.[a-zA-Z0-9]+)?\/?$/;i.forEach(t=>{let e=t.getAttribute("waitless");a.test(e)?(t.src=e,t.removeAttribute("waitless")):console.error(`Invalid URL: ${e}`)})}let i=setTimeout(()=>{o||r(e.scripts,a)},1e4);function c(){o||r(e.scripts,a),o=!0,clearTimeout(i)}function a(){e.functions.forEach(t=>{"function"==typeof t&&t()})}document.addEventListener("DOMContentLoaded",function(){!function t(){var n=document.querySelectorAll("iframe[waitless]");if(n.length>0){var o=function(t){var e=t.getAttribute("waitless");try{t.setAttribute("src",e),t.removeAttribute("waitless")}catch(n){return}},r=new IntersectionObserver(function(t,e){t.forEach(function(t){t.isIntersecting&&(o(t.target),e.unobserve(t.target))})},{root:null,rootMargin:"0px",threshold:0});n.forEach(function(t){r.observe(t)}),e.triggerLoad=function(){n.forEach(function(t){o(t)})}}}()}),n.forEach(t=>{document.addEventListener(t,c)}),t.waitless=e,console.log("waitless 1.0.5")}(this); +!function(t){let e={scripts:[],functions:[],isLibraryAvailable:function t(e){return void 0!==window[e]}},n=["keydown","mousemove","wheel","touchmove","touchstart","touchend"],o=!1;function r(t,e){n.forEach(t=>{document.removeEventListener(t,c)});let o=0,r=t.length;t.forEach(function(t){let{src:n,location:i="body",callback:c}=t,a=document.createElement("script");a.src=n;let s=!1;a.onload=function(){if(!s){var t;s=!0,t=c,++o===r&&"function"==typeof e&&e(),"function"==typeof t&&t()}},a.onerror=function(){s||(s=!0,function t(n,i){let c=Error(`Failed to load script: ${n}`);o++,"function"==typeof i&&i(c),o===r&&"function"==typeof e&&e(c)}(n,c))},"head"===i?document.head.appendChild(a):"body"===i&&document.body.appendChild(a)});let i=document.querySelectorAll("script[waitless]"),a=/^(?:https?:\/\/)?(?:[a-zA-Z0-9-]+\.)?[a-zA-Z0-9-]+\.[a-zA-Z0-9]+(?:\/(?:[^\/.]+\/)*[^\/.]+\.[a-zA-Z0-9]+)?\/?$/;i.forEach(t=>{let e=t.getAttribute("waitless");a.test(e)?(t.src=e,t.removeAttribute("waitless")):console.error(`Invalid URL: ${e}`)})}let i=setTimeout(()=>{o||r(e.scripts,a)},1e4);function c(){o||r(e.scripts,a),o=!0,clearTimeout(i)}function a(){e.functions.forEach(t=>{"function"==typeof t&&t()})}document.addEventListener("DOMContentLoaded",function(){!function t(){var n=document.querySelectorAll("iframe[waitless]");if(n.length>0){var o=function(t){var e=t.getAttribute("waitless");try{t.setAttribute("src",e),t.removeAttribute("waitless")}catch(n){return}},r=new IntersectionObserver(function(t,e){t.forEach(function(t){t.isIntersecting&&(o(t.target),e.unobserve(t.target))})},{root:null,rootMargin:"0px",threshold:0});n.forEach(function(t){r.observe(t)}),e.triggerLoad=function(){document.querySelectorAll("iframe[waitless]").forEach(function(t){o(t)})}}}()}),n.forEach(t=>{document.addEventListener(t,c)}),t.waitless=e}(this);