| 1 |
const loadScriptsTimer = setTimeout(loadScripts, 5000); |
| 2 |
const userInteractionEvents = [ |
| 3 |
"mouseover", |
| 4 |
"scroll", |
| 5 |
"keydown", |
| 6 |
"touchmove", |
| 7 |
"touchstart" |
| 8 |
]; |
| 9 |
userInteractionEvents.forEach(function(event) { |
| 10 |
window.addEventListener(event, triggerScriptLoader, { passive: true }); |
| 11 |
}); |
| 12 |
|
| 13 |
function triggerScriptLoader() { |
| 14 |
loadScripts(); |
| 15 |
clearTimeout(loadScriptsTimer); |
| 16 |
userInteractionEvents.forEach(function(event) { |
| 17 |
window.removeEventListener(event, triggerScriptLoader, { passive: true }); |
| 18 |
}); |
| 19 |
} |
| 20 |
|
| 21 |
function loadScripts() { |
| 22 |
document.querySelectorAll("script[type='lazy']").forEach(function(elem) { |
| 23 |
elem.setAttribute("type", "text/javascript"); |
| 24 |
elem.setAttribute("src", elem.getAttribute("data-src")); |
| 25 |
}); |
| 26 |
} |
| 27 |
|