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 @@ +
+ + +
diff --git a/options.js b/options.js index a271384..f8dcd68 100644 --- a/options.js +++ b/options.js @@ -1,13 +1,21 @@ document.addEventListener("DOMContentLoaded", () => { const elemName = document.querySelector("#elem-name"), - containerSelector = document.querySelector("#container-selector") + containerSelector = document.querySelector("#container-selector"), + monitorInterval = document.querySelector("#monitor-interval") const storage = browser.storage.local storage.get(defaultOptions).then(o => { elemName.value = o.elemName containerSelector.value = o.containerSelector + monitorInterval.value = o.monitorInterval }) elemName.onchange = () => storage.set({ elemName: elemName.value }) containerSelector.onchange = () => storage.set({ containerSelector: containerSelector.value }) + monitorInterval.onchange = () => { + const newVal = monitorInterval.value + if(newVal >= 100) { + storage.set({ monitorInterval: monitorInterval.value }) + } + } })