|
|
@@ -34,9 +34,9 @@ this.lazyLoader = this.lazyLoader || (() => {
|
|
|
function process(options) {
|
|
|
return new Promise(async resolve => {
|
|
|
let timeoutId, srcAttributeChanged;
|
|
|
- const maxTimeoutId = await setTimeout(() => {
|
|
|
+ setTimeout(() => {
|
|
|
clearTimeout(timeoutId);
|
|
|
- lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
+ lazyLoadEnd(idleTimeoutId, observer, resolve);
|
|
|
}, options.maxLazyLoadImagesIdleTime * 5);
|
|
|
const observer = new MutationObserver(async mutations => {
|
|
|
mutations = mutations.filter(mutation => mutation.type == ATTRIBUTES_MUTATION_TYPE);
|
|
|
@@ -51,27 +51,27 @@ this.lazyLoader = this.lazyLoader || (() => {
|
|
|
});
|
|
|
if (updated.length) {
|
|
|
srcAttributeChanged = true;
|
|
|
- timeoutId = await deferLazyLoadEnd(timeoutId, maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
+ timeoutId = await deferLazyLoadEnd(timeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
observer.observe(document, { subtree: true, childList: true, attributes: true });
|
|
|
- const idleTimeoutId = await setTimeout(async () => {
|
|
|
+ const idleTimeoutId = await setTimeout(() => {
|
|
|
if (!srcAttributeChanged) {
|
|
|
- await clearTimeout(timeoutId);
|
|
|
- lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve);
|
|
|
+ clearTimeout(timeoutId);
|
|
|
+ lazyLoadEnd(idleTimeoutId, observer, resolve);
|
|
|
}
|
|
|
}, options.maxLazyLoadImagesIdleTime * 1.2);
|
|
|
injectScript(SCRIPT_BEFORE_PATH);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- async function deferLazyLoadEnd(timeoutId, maxTimeoutId, idleTimeoutId, observer, options, resolve) {
|
|
|
+ async function deferLazyLoadEnd(timeoutId, idleTimeoutId, observer, options, resolve) {
|
|
|
await clearTimeout(timeoutId);
|
|
|
- return await setTimeout(async () => await lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve), options.maxLazyLoadImagesIdleTime);
|
|
|
+ return await setTimeout(async () => await lazyLoadEnd(idleTimeoutId, observer, resolve), options.maxLazyLoadImagesIdleTime);
|
|
|
}
|
|
|
|
|
|
- async function lazyLoadEnd(maxTimeoutId, idleTimeoutId, observer, options, resolve) {
|
|
|
+ function lazyLoadEnd(idleTimeoutId, observer, resolve) {
|
|
|
clearTimeout(idleTimeoutId);
|
|
|
injectScript(SCRIPT_AFTER_PATH);
|
|
|
setTimeout(resolve, 100);
|