first
This commit is contained in:
36
wp-content/plugins/debloat/inc/delay-load/js/defer-load.js
Normal file
36
wp-content/plugins/debloat/inc/delay-load/js/defer-load.js
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Debloat plugin's defer load.
|
||||
* @preserve
|
||||
* @copyright asadkn 2021
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
(() => {
|
||||
const n = true;
|
||||
const e = [ ...document.querySelectorAll("script[defer]") ];
|
||||
if (e.length && document.readyState !== "complete") {
|
||||
let t = document.readyState;
|
||||
Object.defineProperty(document, "readyState", {
|
||||
configurable: true,
|
||||
get() {
|
||||
return t;
|
||||
},
|
||||
set(e) {
|
||||
return t = e;
|
||||
}
|
||||
});
|
||||
let e = false;
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
t = "interactive";
|
||||
n && console.log("DCL Ready.");
|
||||
e = true;
|
||||
document.dispatchEvent(new Event("readystatechange"));
|
||||
e = false;
|
||||
});
|
||||
document.addEventListener("readystatechange", () => {
|
||||
if (!e && t === "interactive") {
|
||||
t = "complete";
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
1
wp-content/plugins/debloat/inc/delay-load/js/defer-load.min.js
vendored
Normal file
1
wp-content/plugins/debloat/inc/delay-load/js/defer-load.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
"use strict";(()=>{if([...document.querySelectorAll("script[defer]")].length&&"complete"!==document.readyState){let t=document.readyState;Object.defineProperty(document,"readyState",{configurable:!0,get(){return t},set(e){return t=e}});let e=!1;document.addEventListener("DOMContentLoaded",()=>{t="interactive",e=!0,document.dispatchEvent(new Event("readystatechange")),e=!1}),document.addEventListener("readystatechange",()=>{e||"interactive"!==t||(t="complete")})}})();
|
254
wp-content/plugins/debloat/inc/delay-load/js/delay-load.js
Normal file
254
wp-content/plugins/debloat/inc/delay-load/js/delay-load.js
Normal file
@ -0,0 +1,254 @@
|
||||
/**
|
||||
* Delay load functionality of debloat plugin.
|
||||
* @preserve
|
||||
* @copyright asadkn 2021
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
(() => {
|
||||
const r = window.debloatConfig || {};
|
||||
const s = true;
|
||||
let c = [];
|
||||
const d = {
|
||||
HTMLDocument: document.addEventListener.bind(document),
|
||||
Window: window.addEventListener.bind(window)
|
||||
};
|
||||
const n = {};
|
||||
let a;
|
||||
let o = false;
|
||||
let i = false;
|
||||
let l = false;
|
||||
let u = false;
|
||||
let e = false;
|
||||
let f = [];
|
||||
let t = [];
|
||||
function m() {
|
||||
h();
|
||||
w();
|
||||
document.addEventListener("debloat-load-css", () => w(true));
|
||||
document.addEventListener("debloat-load-js", () => h(true));
|
||||
}
|
||||
function h(e) {
|
||||
f = [ ...document.querySelectorAll("script[data-debloat-delay]") ];
|
||||
if (f.length) {
|
||||
E();
|
||||
y("js", e);
|
||||
}
|
||||
}
|
||||
function w(e) {
|
||||
t = [ ...document.querySelectorAll("link[data-debloat-delay]") ];
|
||||
if (t.length) {
|
||||
y("css", e);
|
||||
}
|
||||
}
|
||||
function y(t, n) {
|
||||
t = t || "js";
|
||||
const o = n ? "onload" : r[t + "DelayType"] || "onload";
|
||||
const a = t === "js" ? p : g;
|
||||
if (t === "js") {
|
||||
n || o === "onload" ? v() : D(v);
|
||||
}
|
||||
switch (o) {
|
||||
case "onload":
|
||||
D(() => a(n));
|
||||
break;
|
||||
|
||||
case "interact":
|
||||
let e = false;
|
||||
const s = [ "mousemove", "mousedown", "keydown", "touchstart", "wheel" ];
|
||||
const c = () => {
|
||||
if (e) {
|
||||
return;
|
||||
}
|
||||
e = true;
|
||||
t === "js" ? O(() => setTimeout(a, 2)) : a();
|
||||
};
|
||||
s.forEach(e => {
|
||||
document.addEventListener(e, c, {
|
||||
passive: true,
|
||||
once: true
|
||||
});
|
||||
});
|
||||
if (t === "js" && r.jsDelayMax) {
|
||||
O(() => setTimeout(c, r.jsDelayMax * 1e3));
|
||||
}
|
||||
break;
|
||||
|
||||
case "custom-delay":
|
||||
D(() => {
|
||||
const e = parseInt(element.dataset.customDelay) * 1e3;
|
||||
setTimeout(a, e);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
function g() {
|
||||
t.forEach(e => b(e));
|
||||
}
|
||||
function p(e) {
|
||||
v();
|
||||
if (!e) {
|
||||
l = true;
|
||||
a = document.readyState;
|
||||
let t = "loading";
|
||||
Object.defineProperty(document, "readyState", {
|
||||
configurable: true,
|
||||
get() {
|
||||
return t;
|
||||
},
|
||||
set(e) {
|
||||
return t = e;
|
||||
}
|
||||
});
|
||||
}
|
||||
let t;
|
||||
const n = new Promise(e => t = e);
|
||||
const o = () => {
|
||||
if (!f.length) {
|
||||
t();
|
||||
return;
|
||||
}
|
||||
const e = b(f.shift());
|
||||
e.then(o);
|
||||
};
|
||||
o();
|
||||
n.then(j).catch(e => {
|
||||
console.error(e);
|
||||
j();
|
||||
});
|
||||
setTimeout(() => !c.length || j(), 45e3);
|
||||
}
|
||||
function v(o) {
|
||||
if (e) {
|
||||
return;
|
||||
}
|
||||
e = true;
|
||||
f.forEach(e => {
|
||||
const t = e.src || e.dataset.src;
|
||||
if (!t) {
|
||||
return;
|
||||
}
|
||||
const n = document.createElement("link");
|
||||
Object.assign(n, {
|
||||
rel: o || "preload",
|
||||
as: "script",
|
||||
href: t,
|
||||
...e.crossOrigin && {
|
||||
crossOrigin: e.crossOrigin
|
||||
}
|
||||
});
|
||||
document.head.append(n);
|
||||
});
|
||||
}
|
||||
function b(t) {
|
||||
let e;
|
||||
const n = t.dataset.src;
|
||||
const o = t => {
|
||||
return new Promise(e => {
|
||||
t.addEventListener("load", e);
|
||||
t.addEventListener("error", e);
|
||||
});
|
||||
};
|
||||
if (n) {
|
||||
const s = document.createElement("script");
|
||||
e = o(s);
|
||||
t.getAttributeNames().forEach(e => {
|
||||
e === "src" || (s[e] = t[e]);
|
||||
});
|
||||
s.async = false;
|
||||
s.src = n;
|
||||
t.parentNode.replaceChild(s, t);
|
||||
} else if (t.type && t.type === "text/debloat-script") {
|
||||
t.type = t.dataset.type || "text/javascript";
|
||||
t.text += " ";
|
||||
}
|
||||
const a = t.dataset.href;
|
||||
if (a) {
|
||||
e = o(t);
|
||||
t.href = a;
|
||||
}
|
||||
[ "debloatDelay", "src" ].forEach(e => {
|
||||
t.dataset[e] = "";
|
||||
delete t.dataset[e];
|
||||
});
|
||||
return e || Promise.resolve();
|
||||
}
|
||||
function E() {
|
||||
if (o) {
|
||||
return;
|
||||
}
|
||||
o = true;
|
||||
const e = (t, e) => {
|
||||
e.addEventListener(t, e => n[t] = e);
|
||||
};
|
||||
e("DOMContentLoaded", document);
|
||||
e("load", window);
|
||||
e("readystatechange", document);
|
||||
e("pageshow", window);
|
||||
const t = function(e, t, ...n) {
|
||||
const o = [ "readystatechange", "DOMContentLoaded", "load", "pageshow" ];
|
||||
if (l && !i && o.includes(e)) {
|
||||
s && console.log("Adding: ", e, t, n);
|
||||
const a = {
|
||||
event: e,
|
||||
cb: t,
|
||||
context: this,
|
||||
args: n
|
||||
};
|
||||
c.push(a);
|
||||
return;
|
||||
}
|
||||
if (d[this.constructor.name]) {
|
||||
d[this.constructor.name].call(this, e, t, ...n);
|
||||
}
|
||||
};
|
||||
document.addEventListener = t.bind(document);
|
||||
window.addEventListener = t.bind(window);
|
||||
Object.defineProperty(window, "onload", {
|
||||
set(e) {
|
||||
window.addEventListener("load", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
function L(e) {
|
||||
try {
|
||||
e.cb.call(e.context, n[e.event], ...e.args);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
function j() {
|
||||
if (u) {
|
||||
return;
|
||||
}
|
||||
s && console.log("Firing Load Events", c);
|
||||
u = true;
|
||||
const e = c.filter(e => e.event === "readystatechange");
|
||||
document.readyState = "interactive";
|
||||
e.forEach(e => L(e));
|
||||
for (const t of c) {
|
||||
t.event === "DOMContentLoaded" && L(t);
|
||||
}
|
||||
for (const t of c) {
|
||||
t.event === "load" && L(t);
|
||||
}
|
||||
c = [];
|
||||
u = false;
|
||||
i = true;
|
||||
l = false;
|
||||
D(() => {
|
||||
document.readyState = "complete";
|
||||
setTimeout(() => {
|
||||
e.forEach(e => L(e));
|
||||
}, 2);
|
||||
});
|
||||
}
|
||||
function D(e) {
|
||||
const t = a || document.readyState;
|
||||
t === "complete" ? e() : d.Window("load", () => e());
|
||||
}
|
||||
function O(e) {
|
||||
document.readyState !== "loading" ? e() : d.Window("DOMContentLoaded", () => e());
|
||||
}
|
||||
m();
|
||||
})();
|
1
wp-content/plugins/debloat/inc/delay-load/js/delay-load.min.js
vendored
Normal file
1
wp-content/plugins/debloat/inc/delay-load/js/delay-load.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
"use strict";(()=>{const s=window.debloatConfig||{},a=!0;let d=[];const c={HTMLDocument:document.addEventListener.bind(document),Window:window.addEventListener.bind(window)},n={};let r,o=!1,i=!1,l=!1,u=!1,e=!1,m=[],t=[];function f(e){var t;m=[...document.querySelectorAll("script[data-debloat-delay]")],m.length&&(o||(o=!0,(t=(t,e)=>{e.addEventListener(t,e=>n[t]=e)})("DOMContentLoaded",document),t("load",window),t("readystatechange",document),t("pageshow",window),t=function(e,t,...n){var o;l&&!i&&["readystatechange","DOMContentLoaded","load","pageshow"].includes(e)?(a,o={event:e,cb:t,context:this,args:n},d.push(o)):c[this.constructor.name]&&c[this.constructor.name].call(this,e,t,...n)},document.addEventListener=t.bind(document),window.addEventListener=t.bind(window),Object.defineProperty(window,"onload",{set(e){window.addEventListener("load",e)}})),w("js",e))}function h(e){t=[...document.querySelectorAll("link[data-debloat-delay]")],t.length&&w("css",e)}function w(t,n){t=t||"js";var o=!n&&s[t+"DelayType"]||"onload";const a="js"===t?v:y;switch("js"===t&&(n||"onload"===o?p():L(p)),o){case"onload":L(()=>a(n));break;case"interact":let e=!1;const d=["mousemove","mousedown","keydown","touchstart","wheel"],c=()=>{e||(e=!0,"js"===t?j(()=>setTimeout(a,2)):a())};d.forEach(e=>{document.addEventListener(e,c,{passive:!0,once:!0})}),"js"===t&&s.jsDelayMax&&j(()=>setTimeout(c,1e3*s.jsDelayMax));break;case"custom-delay":L(()=>{var e=1e3*parseInt(element.dataset.customDelay);setTimeout(a,e)})}}function y(){t.forEach(e=>g(e))}function v(e){if(p(),!e){l=!0,r=document.readyState;let t="loading";Object.defineProperty(document,"readyState",{configurable:!0,get(){return t},set(e){return t=e}})}let t;const n=new Promise(e=>t=e),o=()=>{if(m.length){const e=g(m.shift());e.then(o)}else t()};o(),n.then(E).catch(e=>{E()}),setTimeout(()=>!d.length||E(),45e3)}function p(o){e||(e=!0,m.forEach(e=>{var t,n=e.src||e.dataset.src;n&&(t=document.createElement("link"),Object.assign(t,{rel:o||"preload",as:"script",href:n,...e.crossOrigin&&{crossOrigin:e.crossOrigin}}),document.head.append(t))}))}function g(t){let e;var n=t.dataset.src,o=t=>new Promise(e=>{t.addEventListener("load",e),t.addEventListener("error",e)});if(n){const a=document.createElement("script");e=o(a),t.getAttributeNames().forEach(e=>{"src"===e||(a[e]=t[e])}),a.async=!1,a.src=n,t.parentNode.replaceChild(a,t)}else t.type&&"text/debloat-script"===t.type&&(t.type=t.dataset.type||"text/javascript",t.text+=" ");n=t.dataset.href;return n&&(e=o(t),t.href=n),["debloatDelay","src"].forEach(e=>{t.dataset[e]="",delete t.dataset[e]}),e||Promise.resolve()}function b(e){try{e.cb.call(e.context,n[e.event],...e.args)}catch(e){}}function E(){if(!u){a,u=!0;const e=d.filter(e=>"readystatechange"===e.event);document.readyState="interactive",e.forEach(e=>b(e));for(const t of d)"DOMContentLoaded"===t.event&&b(t);for(const n of d)"load"===n.event&&b(n);d=[],u=!1,i=!0,l=!1,L(()=>{document.readyState="complete",setTimeout(()=>{e.forEach(e=>b(e))},2)})}}function L(e){"complete"===(r||document.readyState)?e():c.Window("load",()=>e())}function j(e){"loading"!==document.readyState?e():c.Window("DOMContentLoaded",()=>e())}f(),h(),document.addEventListener("debloat-load-css",()=>h(!0)),document.addEventListener("debloat-load-js",()=>f(!0))})();
|
Reference in New Issue
Block a user