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