From e87468900c9ab3701ebabd96fa2eb1454170e806 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 24 Nov 2022 16:16:03 +0700 Subject: [PATCH] throttle block for observer --- extension/script.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extension/script.js b/extension/script.js index a9b95c8..b482e2a 100644 --- a/extension/script.js +++ b/extension/script.js @@ -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 => { if (list.some(i => i.type === 'childList' && i.addedNodes.length > 0)) { - console.log("observer hit") - ensureTALinks(); + throttle(ensureTALinks, 700); } });