merge main
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
(() => {
|
||||
document.addEventListener('DOMContentLoaded', (event) => {
|
||||
document.addEventListener("DOMContentLoaded", (event) => {
|
||||
initIdleMutationObserver();
|
||||
});
|
||||
|
||||
|
||||
function initIdleMutationObserver() {
|
||||
let debounceTimer;
|
||||
const debounceDelay = 500; // adjust the delay as needed
|
||||
|
||||
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
// Clear the previous timer and set a new one
|
||||
clearTimeout(debounceTimer);
|
||||
@@ -15,13 +15,14 @@
|
||||
observer.disconnect(); // Disconnect after first execution
|
||||
}, debounceDelay);
|
||||
});
|
||||
|
||||
|
||||
const config = { attributes: false, childList: true, subtree: true };
|
||||
observer.observe(document.body, config);
|
||||
}
|
||||
|
||||
|
||||
function execute() {
|
||||
'SCRIPT_CONTENT_PARAM'
|
||||
"{{AFTER_DOM_IDLE_SCRIPT}}";
|
||||
//console.log('DOM is now idle. Executing...');
|
||||
}
|
||||
})();
|
||||
})();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func (r *ScriptInjectorRewriter) ModifyToken(token *html.Token) (string, string)
|
||||
return "", fmt.Sprintf("\n<script>\ndocument.addEventListener('DOMContentLoaded', () => { %s });\n</script>", r.script)
|
||||
|
||||
case r.execTime == AfterDOMIdle:
|
||||
s := strings.Replace(afterDomIdleScriptInjector, `'SCRIPT_CONTENT_PARAM'`, r.script, 1)
|
||||
s := strings.Replace(afterDomIdleScriptInjector, `'{{AFTER_DOM_IDLE_SCRIPT}}'`, r.script, 1)
|
||||
return "", fmt.Sprintf("\n<script>\n%s\n</script>\n", s)
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user