master
Travis Evans 2025-05-17 19:19:55 -05:00
parent 5724b0d8e3
commit cb7204d700
1 changed files with 32 additions and 13 deletions

View File

@ -186,6 +186,13 @@
return maxId + 1; return maxId + 1;
} }
function splitHMS(hms) {
let h = Math.floor(hms / 3600);
let m = Math.floor((hms % 3600) / 60);
let s = Math.floor(hms % 60);
return [h, m, s];
}
function updateTimerBlocks() { function updateTimerBlocks() {
// Track the currently focused element // Track the currently focused element
const activeElement = document.activeElement; const activeElement = document.activeElement;
@ -235,9 +242,7 @@
console.error('Unsupported timer rate'); console.error('Unsupported timer rate');
continue; continue;
} }
let h = Math.floor(timer.origin / 3600); let [h, m, s] = splitHMS(timer.origin);
let m = Math.floor((timer.origin % 3600) / 60);
let s = Math.floor(timer.origin % 60);
let atEndTimer = timer.chain_id ? getTimerById(timers, timer.chain_id) : null; let atEndTimer = timer.chain_id ? getTimerById(timers, timer.chain_id) : null;
let atEndSelected = atEndTimer ? atEndTimer.id : 'null'; let atEndSelected = atEndTimer ? atEndTimer.id : 'null';
@ -308,16 +313,28 @@
// Update only the At End dropdowns // Update only the At End dropdowns
updateAtEndDropdowns(); updateAtEndDropdowns();
} else if (type === 'hours' || type === 'minutes' || type === 'seconds') { } else if (type === 'hours' || type === 'minutes' || type === 'seconds') {
let h = parseInt(document.getElementById(`hours-${index}`).value) || 0; let hInput = document.getElementById(`hours-${index}`);
let m = parseInt(document.getElementById(`minutes-${index}`).value) || 0; let mInput = document.getElementById(`minutes-${index}`);
let s = parseInt(document.getElementById(`seconds-${index}`).value) || 0; let sInput = document.getElementById(`seconds-${index}`);
userTimers[index].origin = h * 3600 + m * 60 + s; let h = parseInt(hInput.value) || 0;
let m = parseInt(mInput.value) || 0;
let s = parseInt(sInput.value) || 0;
userTimers[index].origin = Math.max(
Math.min(h * 3600 + m * 60 + s, 99 * 3600 + 59 * 60 + 59),
0);
// Normalize the values in case minutes/seconds >59
[h, m, s] = splitHMS(userTimers[index].origin);
hInput.value = h;
mInput.value = m;
sInput.value = s;
} else if (type === 'atend') { } else if (type === 'atend') {
userTimers[index].chain_id = value == 'null' ? null : parseInt(value); userTimers[index].chain_id = value == 'null' ? null : parseInt(value);
} else if (type === 'vibrate') { } else if (type === 'vibrate') {
userTimers[index].vibrate_pattern = value; userTimers[index].vibrate_pattern = value;
} else if (type === 'buzz') { } else if (type === 'buzz') {
userTimers[index].buzz_count = parseInt(value); userTimers[index].buzz_count =
Math.max(Math.min(MAX_BUZZ_COUNT, parseInt(value)), 0);
event.target.value = userTimers[index].buzz_count;
} }
}); });
}); });
@ -406,11 +423,13 @@
} }
function saveTimers() { function saveTimers() {
// Save the timers to storage if (userTimers.length) {
console.log(userTimers); // (Guard in case the user manages to click Save before
// Util.writeStorageJSON('tevtimer.timers.json', userTimers, () => { // the timers are loaded, or something like that)
// console.log('Timers saved successfully'); Util.writeStorage(TIMERS_FILE, JSON.stringify(userTimers), () => {
// }); alert('Timers saved successfully.');
});
};
} }
function reloadTimers() { function reloadTimers() {