Persist countdown inputs and show completion bell in tab title
Some checks failed
/ publish (push) Failing after 2m20s

Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
Leon Mika 2026-10-10 06:56:14 +00:00
parent ebfd6e4ce1
commit a42f897248
3 changed files with 90 additions and 1 deletions

View file

@ -0,0 +1,26 @@
import { integer } from './timer.mjs';
export const SETTINGS_KEY = 'countdown-settings';
export function serializeSettings(minutes, seconds) {
return JSON.stringify({
minutes: String(integer(minutes)),
seconds: String(integer(seconds)),
});
}
export function parseSettings(json) {
try {
const settings = JSON.parse(json);
if (typeof settings?.minutes === 'string' && /^\d+$/.test(settings.minutes) &&
typeof settings?.seconds === 'string' && /^\d+$/.test(settings.seconds)) {
return {
minutes: String(integer(settings.minutes)),
seconds: String(integer(settings.seconds)).padStart(2, '0'),
};
}
} catch {
// Missing or invalid storage is equivalent to a fresh countdown.
}
return { minutes: '0', seconds: '00' };
}