From 720e11574874fcdc06f489d4fdb9d2ac672b67b1 Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Mon, 3 Aug 2026 00:31:19 +0300 Subject: [PATCH] Add configurable minimum time threshold for timer pauses If a timer is paused within the configured duration, it will revert to its previous state instead of saving the pause. This prevents accidental pauses during brief interruptions. The threshold can now be customized in the settings. Closes #19 --- css/style.css | 1 + js/options.js | 8 ++++++-- js/tasks.js | 8 ++++++-- options.html | 8 ++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/css/style.css b/css/style.css index 593edf1..d95f7ad 100644 --- a/css/style.css +++ b/css/style.css @@ -154,6 +154,7 @@ p.buttons { ----------------------------------------------------------------------------- */ input[type=text], +input[type=number], select, textarea { border: solid 1px #D6D6BE; diff --git a/js/options.js b/js/options.js index b58ff18..a3efdff 100644 --- a/js/options.js +++ b/js/options.js @@ -3,12 +3,14 @@ const saveOptions = () => { const dynamic_tasks = document.getElementById('dynamic_tasks').checked; const sort_by = document.getElementById('sort_by').value ?? 'id'; const sort_direction = document.getElementById('sort_direction').value ?? 'asc'; + const min_timer_seconds = parseInt(document.getElementById('min_timer_seconds').value) || 0; chrome.storage.local.set( { dynamic_tasks: dynamic_tasks, sort_by: sort_by, - sort_direction: sort_direction + sort_direction: sort_direction, + min_timer_seconds: min_timer_seconds }, () => { // Update status to let user know options were saved. @@ -28,12 +30,14 @@ const restoreOptions = () => { { dynamic_tasks: false, sort_by: 'id', - sort_direction: 'asc' + sort_direction: 'asc', + min_timer_seconds: 0 }, (items) => { document.getElementById('dynamic_tasks').checked = items.dynamic_tasks; document.getElementById('sort_by').value = items.sort_by; document.getElementById('sort_direction').value = items.sort_direction; + document.getElementById('min_timer_seconds').value = items.min_timer_seconds; } ); }; diff --git a/js/tasks.js b/js/tasks.js index 2b30328..57d58ff 100644 --- a/js/tasks.js +++ b/js/tasks.js @@ -578,13 +578,17 @@ let taskInterface = { start = new Date(task.start); // read from DB stop = new Date(); // now dif = Number(task.time) + Math.floor((stop.getTime() - start.getTime()) / 1000); // time diff in seconds - $('#item' + task.id + ' .timer').text(taskInterface.hms(dif)); + + let elapsed = Math.floor((stop.getTime() - start.getTime()) / 1000); + let min_seconds = taskInterface.options?.min_timer_seconds || 0; + let final_time = (elapsed < min_seconds) ? task.time : Number(dif); + $('#item' + task.id + ' .timer').text(taskInterface.hms(final_time)); // update record await tasks.update( { running: 0, - time: Number(dif) + time: final_time }, { id: task.id diff --git a/options.html b/options.html index ae13b6a..0ec3b6c 100644 --- a/options.html +++ b/options.html @@ -40,6 +40,14 @@ +
+ + + Reverts timer if stopped before this threshold +
+