throttle block for observer

This commit is contained in:
simon 2022-11-24 16:16:03 +07:00
parent 30f80ca01a
commit e87468900c
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -355,10 +355,20 @@ function sendUrl(url, action, button) {
}; };
let throttleBlock;
const throttle = (callback, time) => {
if (throttleBlock) return;
throttleBlock = true;
setTimeout(() => {
console.log("observer hit");
callback();
throttleBlock = false;
}, time);
};
let observer = new MutationObserver(list => { let observer = new MutationObserver(list => {
if (list.some(i => i.type === 'childList' && i.addedNodes.length > 0)) { if (list.some(i => i.type === 'childList' && i.addedNodes.length > 0)) {
console.log("observer hit") throttle(ensureTALinks, 700);
ensureTALinks();
} }
}); });