Persist countdown inputs and show completion bell in tab title
Some checks failed
/ publish (push) Failing after 2m20s
Some checks failed
/ publish (push) Failing after 2m20s
Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
parent
ebfd6e4ce1
commit
a42f897248
3 changed files with 90 additions and 1 deletions
26
site/countdown/settings.mjs
Normal file
26
site/countdown/settings.mjs
Normal 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' };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue