diff --git a/bg/monitor.js b/bg/monitor.js index 6fd4a7b..a1c1c9f 100644 --- a/bg/monitor.js +++ b/bg/monitor.js @@ -16,6 +16,7 @@ browser.storage.onChanged.addListener((changes, area) => { options[key] = changes[key].newValue } } + updateTimer() } }) @@ -63,14 +64,22 @@ function checkClipboard() { } function updateTimer() { + function stop() { + clearInterval(timer.id) + timer = null + } + function start() { + const id = setInterval(checkClipboard, options.monitorInterval) + timer = { id, interval: options.monitorInterval } + } if(listeningTabs.length > 0) { if(timer === null) { - const id = setInterval(checkClipboard, 1000) - timer = { id } + start() + } else if(timer.interval !== options.monitorInterval) { + stop() + start() } } else { - if(timer !== null) { - clearInterval(timer.id) - } + stop() } } diff --git a/default-options.js b/default-options.js index 6190c42..90584c4 100644 --- a/default-options.js +++ b/default-options.js @@ -1,4 +1,5 @@ const defaultOptions = { elemName: 'p', - containerSelector: 'body' + containerSelector: 'body', + monitorInterval: 300 } diff --git a/options.html b/options.html index 376d64f..e5cb3a9 100644 --- a/options.html +++ b/options.html @@ -16,6 +16,10 @@ +