amicookedyet 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/dist/index.js +1462 -0
- package/dist/sounds/bruh.wav +0 -0
- package/dist/ui/index.html +1083 -0
- package/package.json +38 -10
- package/index.js +0 -2
|
@@ -0,0 +1,1083 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="referrer" content="no-referrer">
|
|
7
|
+
<meta name="color-scheme" content="light dark">
|
|
8
|
+
<title>Settings</title>
|
|
9
|
+
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M16 3C9.4 3 5 7.6 5 13.5c0 3.6 1.7 6.3 4 7.8V25a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3.7c2.3-1.5 4-4.2 4-7.8C27 7.6 22.6 3 16 3Z' fill='%23ea580c'/%3E%3Ccircle cx='11.5' cy='14' r='3' fill='%231c1917'/%3E%3Ccircle cx='20.5' cy='14' r='3' fill='%231c1917'/%3E%3Cpath d='M16 17.6l-1.7 2.9h3.4Z' fill='%231c1917'/%3E%3C/svg%3E">
|
|
10
|
+
<style>
|
|
11
|
+
/* Same tokens as the landing page, so this feels like the same product. */
|
|
12
|
+
:root {
|
|
13
|
+
--bg: #fbfaf7; --surface: #ffffff; --surface-2: #f2efe8; --text: #1c1b18; --muted: #5d5a52;
|
|
14
|
+
--border: #e3dfd5; --accent: #c2410c; --accent-text: #ffffff; --ok: #166534; --danger: #b91c1c;
|
|
15
|
+
--focus: #2563eb; --term-bg: #1d1c1a; --term-text: #e8e6e1; --term-dim: #a19d94;
|
|
16
|
+
--term-rare: #fda4af; --term-medium: #fdba74; --term-well: #fcd34d; --term-cooked: #f87171;
|
|
17
|
+
--radius: 14px; --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.06);
|
|
18
|
+
--rare: #e11d48; --medium: #ea580c; --well: #a16207; --cooked: #1c1917;
|
|
19
|
+
color-scheme: light;
|
|
20
|
+
}
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
:root:not([data-theme="light"]) {
|
|
23
|
+
--bg: #141413; --surface: #1e1d1b; --surface-2: #262522; --text: #f1efe9; --muted: #b0aca3;
|
|
24
|
+
--border: #34322e; --accent: #fb923c; --accent-text: #1a1206; --ok: #4ade80; --danger: #f87171;
|
|
25
|
+
--focus: #93c5fd; --term-bg: #0d0d0c; --cooked: #f87171;
|
|
26
|
+
--shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35); color-scheme: dark;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
:root[data-theme="dark"] {
|
|
30
|
+
--bg: #141413; --surface: #1e1d1b; --surface-2: #262522; --text: #f1efe9; --muted: #b0aca3;
|
|
31
|
+
--border: #34322e; --accent: #fb923c; --accent-text: #1a1206; --ok: #4ade80; --danger: #f87171;
|
|
32
|
+
--focus: #93c5fd; --term-bg: #0d0d0c; --cooked: #f87171;
|
|
33
|
+
--shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.35); color-scheme: dark;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
37
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-wrap: break-word; }
|
|
38
|
+
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; margin: 0; }
|
|
39
|
+
h2 { font-size: 1.25rem; }
|
|
40
|
+
h3 { font-size: 1rem; }
|
|
41
|
+
p { margin: 0; }
|
|
42
|
+
a { color: inherit; }
|
|
43
|
+
button, input, select { font: inherit; color: inherit; }
|
|
44
|
+
svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
|
|
45
|
+
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
|
|
46
|
+
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
|
|
47
|
+
.hidden { display: none !important; }
|
|
48
|
+
.muted { color: var(--muted); }
|
|
49
|
+
.small { font-size: 0.875rem; }
|
|
50
|
+
.wrap { max-width: 920px; margin-inline: auto; padding-inline: 16px; }
|
|
51
|
+
@media (min-width: 640px) { .wrap { padding-inline: 28px; } }
|
|
52
|
+
|
|
53
|
+
/* Header */
|
|
54
|
+
.top { display: flex; align-items: center; gap: 12px; padding-block: 18px; }
|
|
55
|
+
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
|
|
56
|
+
.brand > div { min-width: 0; }
|
|
57
|
+
.brand svg.logo { width: 34px; height: 34px; stroke: none; }
|
|
58
|
+
.brand strong { display: block; font-size: 1.05rem; white-space: nowrap; }
|
|
59
|
+
.brand span { display: block; font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
60
|
+
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer; }
|
|
61
|
+
.i-sun { display: none; }
|
|
62
|
+
:root[data-theme="dark"] .i-sun { display: block; }
|
|
63
|
+
:root[data-theme="dark"] .i-moon { display: none; }
|
|
64
|
+
@media (prefers-color-scheme: dark) {
|
|
65
|
+
:root:not([data-theme="light"]) .i-sun { display: block; }
|
|
66
|
+
:root:not([data-theme="light"]) .i-moon { display: none; }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Building blocks */
|
|
70
|
+
main { display: grid; gap: 20px; padding-bottom: 96px; }
|
|
71
|
+
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
|
|
72
|
+
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
|
|
73
|
+
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--surface); text-decoration: none; transition: transform 0.1s ease, background 0.15s ease; white-space: nowrap; }
|
|
74
|
+
.btn:hover { background: var(--surface-2); }
|
|
75
|
+
.btn:active { transform: translateY(1px); }
|
|
76
|
+
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
|
|
77
|
+
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
|
|
78
|
+
.btn.primary:hover { filter: brightness(1.08); }
|
|
79
|
+
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); padding-inline: 10px; }
|
|
80
|
+
.btn.quiet:hover { color: var(--text); background: var(--surface-2); }
|
|
81
|
+
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
|
|
82
|
+
.btn.big { min-height: 52px; font-size: 1.05rem; }
|
|
83
|
+
.pro-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 9px; border-radius: 99px; background: var(--accent); color: var(--accent-text); vertical-align: middle; }
|
|
84
|
+
.tag { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
|
|
85
|
+
.tag.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
|
|
86
|
+
|
|
87
|
+
/* Segmented control built from radio buttons */
|
|
88
|
+
.seg { display: inline-flex; flex-wrap: wrap; padding: 4px; gap: 2px; border-radius: 12px; background: var(--surface-2); border: 0; margin: 0; min-width: 0; }
|
|
89
|
+
.seg legend { padding: 0; }
|
|
90
|
+
.seg label { position: relative; }
|
|
91
|
+
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
|
|
92
|
+
.seg span { display: block; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 0.9rem; color: var(--muted); }
|
|
93
|
+
.seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
|
|
94
|
+
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 1px; }
|
|
95
|
+
|
|
96
|
+
/* Switch built from a checkbox */
|
|
97
|
+
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
|
|
98
|
+
.switch input { appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--border); position: relative; cursor: pointer; flex: none; margin: 0; transition: background 0.15s ease; }
|
|
99
|
+
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.15s ease; }
|
|
100
|
+
.switch input:checked { background: var(--accent); }
|
|
101
|
+
.switch input:checked::after { transform: translateX(18px); }
|
|
102
|
+
|
|
103
|
+
input[type=range] { width: 100%; accent-color: var(--accent); height: 28px; margin: 0; cursor: pointer; }
|
|
104
|
+
select { min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); width: 100%; }
|
|
105
|
+
|
|
106
|
+
/* Account strip */
|
|
107
|
+
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px; }
|
|
108
|
+
.account .who { flex: 1 1 260px; min-width: 0; }
|
|
109
|
+
.account .who strong { font-size: 1.05rem; }
|
|
110
|
+
.account .facts { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 4px; }
|
|
111
|
+
.account .actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
112
|
+
.code-box { display: grid; gap: 10px; justify-items: start; }
|
|
113
|
+
.user-code { font: 700 2rem/1 ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.12em; padding: 12px 18px; border-radius: 12px; background: var(--surface-2); border: 2px dashed var(--accent); }
|
|
114
|
+
|
|
115
|
+
/* Live preview */
|
|
116
|
+
.term { border-radius: var(--radius); overflow: hidden; background: var(--term-bg); color: var(--term-text); border: 1px solid #2c2a26; font: 0.9rem/1.6 ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace; }
|
|
117
|
+
.term-bar { display: flex; align-items: center; gap: 7px; padding: 10px 14px; background: #2a2926; }
|
|
118
|
+
.term-bar i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
|
|
119
|
+
.term-bar i:nth-child(2) { background: #febc2e; }
|
|
120
|
+
.term-bar i:nth-child(3) { background: #28c840; }
|
|
121
|
+
.term-bar span { margin-left: 10px; color: var(--term-dim); font-size: 0.8rem; }
|
|
122
|
+
.term-body { padding: 16px 16px 14px; display: grid; gap: 10px; }
|
|
123
|
+
.t-dim { color: var(--term-dim); }
|
|
124
|
+
.t-line { min-height: 1.6em; transition: color 0.3s ease; }
|
|
125
|
+
.t-line.rare { color: var(--term-rare); }
|
|
126
|
+
.t-line.medium { color: var(--term-medium); }
|
|
127
|
+
.t-line.well { color: var(--term-well); }
|
|
128
|
+
.t-line.cooked { color: var(--term-cooked); font-weight: 700; }
|
|
129
|
+
.spin { display: inline-block; width: 1.2em; color: #f59e0b; }
|
|
130
|
+
.t-status { border-top: 1px solid #2c2a26; padding-top: 10px; display: flex; justify-content: space-between; gap: 12px; color: var(--term-dim); font-size: 0.8rem; }
|
|
131
|
+
.t-status .t-line { font-size: 0.8rem; }
|
|
132
|
+
@media (max-width: 480px) { .t-status .esc { display: none; } }
|
|
133
|
+
.flash { animation: flash 0.9s ease 2; }
|
|
134
|
+
@keyframes flash { 50% { background: rgb(252 165 165 / 0.18); } }
|
|
135
|
+
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }
|
|
136
|
+
|
|
137
|
+
.preview-controls { display: grid; gap: 14px; margin-top: 16px; }
|
|
138
|
+
@media (min-width: 720px) { .preview-controls { grid-template-columns: 1fr 1fr; } }
|
|
139
|
+
.slider-row { display: grid; gap: 4px; }
|
|
140
|
+
.slider-row label { display: flex; justify-content: space-between; font-weight: 600; font-size: 0.92rem; }
|
|
141
|
+
.slider-row output { font-variant-numeric: tabular-nums; }
|
|
142
|
+
.scale { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; list-style: none; padding: 0; }
|
|
143
|
+
.scale li { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--border); border-top: 4px solid var(--lvl); font-size: 0.8rem; color: var(--muted); }
|
|
144
|
+
.scale li.on { color: var(--text); background: var(--surface-2); font-weight: 700; }
|
|
145
|
+
.scale .rare { --lvl: var(--rare); } .scale .medium { --lvl: var(--medium); } .scale .well { --lvl: var(--well); } .scale .cooked { --lvl: var(--cooked); }
|
|
146
|
+
@media (max-width: 460px) { .scale li .lvl-name { display: none; } .scale li { justify-content: center; font-size: 1.1rem; } }
|
|
147
|
+
.firing { margin-top: 12px; font-size: 0.92rem; }
|
|
148
|
+
.line-settings { display: grid; gap: 12px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
|
|
149
|
+
.line-settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
|
|
150
|
+
|
|
151
|
+
/* Alarms: one group per limit, one row per alarm */
|
|
152
|
+
.alarms { display: grid; gap: 14px; }
|
|
153
|
+
@media (min-width: 900px) { .alarms { grid-template-columns: 1fr 1fr; align-items: start; } }
|
|
154
|
+
.limit { display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
|
|
155
|
+
.limit.off .alarm-list { opacity: 0.45; }
|
|
156
|
+
.limit-head { display: flex; align-items: center; gap: 10px; }
|
|
157
|
+
.limit-head h3 { margin: 0; flex: 1; font-size: 1.05rem; }
|
|
158
|
+
.alarm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
|
|
159
|
+
.alarm-row { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--surface-2); border-left: 4px solid var(--lvl, var(--accent)); }
|
|
160
|
+
.alarm-row.rare { --lvl: var(--rare); } .alarm-row.medium { --lvl: var(--medium); } .alarm-row.well { --lvl: var(--well); } .alarm-row.cooked { --lvl: var(--cooked); }
|
|
161
|
+
.alarm-row .when { display: flex; align-items: baseline; gap: 8px; }
|
|
162
|
+
.alarm-row .num { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
|
|
163
|
+
.alarm-row input[type=range] { width: 100%; margin: 0; }
|
|
164
|
+
.alarm-row .what { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
|
|
165
|
+
.alarm-row .what select { flex: 1 1 140px; min-width: 0; }
|
|
166
|
+
.switch.mini { gap: 6px; }
|
|
167
|
+
.btn.add { justify-self: start; }
|
|
168
|
+
.locked { margin: 0; color: var(--muted); }
|
|
169
|
+
|
|
170
|
+
/* Sound library */
|
|
171
|
+
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
|
|
172
|
+
.tile { position: relative; display: grid; gap: 4px; justify-items: start; text-align: left; padding: 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; min-height: 92px; }
|
|
173
|
+
.tile:hover { background: var(--surface-2); }
|
|
174
|
+
.tile .emoji { font-size: 1.5rem; line-height: 1; }
|
|
175
|
+
.tile strong { font-size: 0.95rem; overflow-wrap: anywhere; }
|
|
176
|
+
.tile small { color: var(--muted); font-size: 0.78rem; }
|
|
177
|
+
.tile.playing { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
|
|
178
|
+
.locked { position: relative; }
|
|
179
|
+
.locked > .lock-cover { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin-top: 14px; padding: 18px; border-radius: var(--radius); background: var(--surface-2); text-align: center; }
|
|
180
|
+
.upload-msg { margin-top: 10px; min-height: 1.4em; font-size: 0.92rem; }
|
|
181
|
+
.upload-msg.error { color: var(--danger); }
|
|
182
|
+
|
|
183
|
+
/* Break reminders */
|
|
184
|
+
.breaks { display: grid; gap: 16px; }
|
|
185
|
+
.breaks .row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
|
|
186
|
+
.breaks .minutes { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
|
|
187
|
+
.breaks .sound-row { display: flex; gap: 8px; align-items: center; }
|
|
188
|
+
.breaks .sound-row select { flex: 1; }
|
|
189
|
+
.hours-list { list-style: none; padding: 0; margin: 6px 0 10px; display: grid; gap: 8px; }
|
|
190
|
+
.hours-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
|
191
|
+
.hours-list li.invalid input { border-color: var(--danger); }
|
|
192
|
+
#hours-note.error { color: var(--danger); font-weight: 600; }
|
|
193
|
+
.hours-list input[type=time] { min-height: 44px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
|
|
194
|
+
.breaks.off .when { opacity: 0.55; }
|
|
195
|
+
|
|
196
|
+
/* Danger zone */
|
|
197
|
+
details.danger-zone { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
|
|
198
|
+
details.danger-zone summary { cursor: pointer; padding: 16px 20px; font-weight: 600; color: var(--muted); }
|
|
199
|
+
.danger-body { display: grid; gap: 16px; padding: 0 20px 20px; }
|
|
200
|
+
.danger-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
|
|
201
|
+
.steps { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; color: var(--muted); }
|
|
202
|
+
.paused { background: var(--surface-2); box-shadow: none; }
|
|
203
|
+
.paused ul { margin: 8px 0 0; padding-left: 1.2em; color: var(--muted); }
|
|
204
|
+
.notice { padding: 12px 16px; border-radius: 12px; background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--text); }
|
|
205
|
+
.sync-conflict p { margin: 0 0 10px; }
|
|
206
|
+
.sync-conflict .actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
207
|
+
|
|
208
|
+
.foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 0.875rem; }
|
|
209
|
+
|
|
210
|
+
/* Toast */
|
|
211
|
+
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); margin: 0; max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease; z-index: 5; }
|
|
212
|
+
.toast.show { opacity: 1; transform: translate(-50%, 0); }
|
|
213
|
+
.toast.error { background: var(--danger); color: #fff; }
|
|
214
|
+
@media (prefers-reduced-motion: reduce) { .toast, .t-line, .switch input, .switch input::after { transition: none; } }
|
|
215
|
+
</style>
|
|
216
|
+
</head>
|
|
217
|
+
<body>
|
|
218
|
+
<header class="top wrap">
|
|
219
|
+
<div class="brand">
|
|
220
|
+
<svg class="logo" viewBox="0 0 32 32" aria-hidden="true"><path d="M16 3C9.4 3 5 7.6 5 13.5c0 3.6 1.7 6.3 4 7.8V25a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-3.7c2.3-1.5 4-4.2 4-7.8C27 7.6 22.6 3 16 3Z" fill="#ea580c"/><circle cx="11.5" cy="14" r="3" fill="#1c1917"/><circle cx="20.5" cy="14" r="3" fill="#1c1917"/><path d="M16 17.6l-1.7 2.9h3.4Z" fill="#1c1917"/><path d="M13 23v4M16 23v4M19 23v4" stroke="#1c1917" stroke-width="1.3" stroke-linecap="round"/></svg>
|
|
221
|
+
<div><strong id="product">Settings</strong><span id="path">Loading…</span></div>
|
|
222
|
+
</div>
|
|
223
|
+
<button class="icon-btn" id="theme-toggle" type="button" aria-label="Switch to dark theme">
|
|
224
|
+
<svg class="i-moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z"/></svg>
|
|
225
|
+
<svg class="i-sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.5"/><path d="M12 1.5v3M12 19.5v3M1.5 12h3M19.5 12h3M4.6 4.6l2.1 2.1M17.3 17.3l2.1 2.1M4.6 19.4l2.1-2.1M17.3 6.7l2.1-2.1"/></svg>
|
|
226
|
+
</button>
|
|
227
|
+
</header>
|
|
228
|
+
|
|
229
|
+
<main class="wrap" id="main">
|
|
230
|
+
<p class="notice hidden" id="notice" role="status"></p>
|
|
231
|
+
<div class="notice sync-conflict hidden" id="sync-conflict" role="alert">
|
|
232
|
+
<p>Your alarms were changed on your account page or another computer since this computer last sent its own. Which do you want to keep?</p>
|
|
233
|
+
<div class="actions">
|
|
234
|
+
<button class="btn" id="keep-mine" type="button">Keep this computer's</button>
|
|
235
|
+
<button class="btn quiet" id="use-theirs" type="button">Use the newer ones</button>
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
<section class="card" aria-labelledby="account-title">
|
|
240
|
+
<h2 id="account-title" class="sr-only">Account</h2>
|
|
241
|
+
<div class="account" id="account"><p class="muted">Loading your account…</p></div>
|
|
242
|
+
</section>
|
|
243
|
+
|
|
244
|
+
<section class="card" aria-labelledby="preview-title">
|
|
245
|
+
<div class="card-head">
|
|
246
|
+
<h2 id="preview-title">Live preview</h2>
|
|
247
|
+
<span class="muted small">Exactly what Claude Code shows. Drag to see when you're cooked.</span>
|
|
248
|
+
</div>
|
|
249
|
+
<figure class="term" style="margin:0" aria-labelledby="preview-caption">
|
|
250
|
+
<div class="term-bar" aria-hidden="true"><i></i><i></i><i></i><span>claude</span></div>
|
|
251
|
+
<div class="term-body">
|
|
252
|
+
<p class="t-dim" aria-hidden="true">> refactor the billing module and add tests</p>
|
|
253
|
+
<p class="t-line" id="spinner-line"><span class="spin" id="spin" aria-hidden="true">✻</span> <span id="spinner-text"></span></p>
|
|
254
|
+
<div class="t-status"><span class="esc" aria-hidden="true">esc to interrupt</span></div>
|
|
255
|
+
</div>
|
|
256
|
+
<figcaption id="preview-caption" class="sr-only">A preview of the usage line in Claude Code's spinner.</figcaption>
|
|
257
|
+
</figure>
|
|
258
|
+
<div class="preview-controls">
|
|
259
|
+
<div class="slider-row">
|
|
260
|
+
<label for="left-5h"><span>5-hour limit left</span><output id="left-5h-out" for="left-5h">63%</output></label>
|
|
261
|
+
<input type="range" id="left-5h" min="0" max="100" value="63">
|
|
262
|
+
</div>
|
|
263
|
+
<div class="slider-row">
|
|
264
|
+
<label for="left-week"><span>Weekly limit left</span><output id="left-week-out" for="left-week">80%</output></label>
|
|
265
|
+
<input type="range" id="left-week" min="0" max="100" value="80">
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
<ol class="scale" aria-label="Doneness scale" id="scale">
|
|
269
|
+
<li class="rare" data-level="rare"><span aria-hidden="true">🥩</span><span class="lvl-name">Rare</span></li>
|
|
270
|
+
<li class="medium" data-level="medium"><span aria-hidden="true">🍳</span><span class="lvl-name">Medium</span></li>
|
|
271
|
+
<li class="well" data-level="well"><span aria-hidden="true">🍖</span><span class="lvl-name">Well-done</span></li>
|
|
272
|
+
<li class="cooked" data-level="cooked"><span aria-hidden="true">💀</span><span class="lvl-name">Cooked</span></li>
|
|
273
|
+
</ol>
|
|
274
|
+
<p class="firing" id="firing" aria-live="polite"></p>
|
|
275
|
+
<div class="line-settings">
|
|
276
|
+
<div class="row">
|
|
277
|
+
<span id="spinner-label">Show usage in the spinner</span>
|
|
278
|
+
<fieldset class="seg" aria-labelledby="spinner-label">
|
|
279
|
+
<label><input type="radio" name="spinner" value="always"><span>Always</span></label>
|
|
280
|
+
<label><input type="radio" name="spinner" value="low"><span>When low</span></label>
|
|
281
|
+
<label><input type="radio" name="spinner" value="off"><span>Off</span></label>
|
|
282
|
+
</fieldset>
|
|
283
|
+
</div>
|
|
284
|
+
</div>
|
|
285
|
+
</section>
|
|
286
|
+
|
|
287
|
+
<section aria-labelledby="alarms-title">
|
|
288
|
+
<div class="card-head">
|
|
289
|
+
<h2 id="alarms-title">Alarms</h2>
|
|
290
|
+
<span class="muted small" id="alarm-count"></span>
|
|
291
|
+
</div>
|
|
292
|
+
<div class="alarms" id="alarms"></div>
|
|
293
|
+
</section>
|
|
294
|
+
|
|
295
|
+
<section class="card" aria-labelledby="breaks-title">
|
|
296
|
+
<div class="card-head">
|
|
297
|
+
<h2 id="breaks-title">Break reminders <span class="pro-badge">Paid</span></h2>
|
|
298
|
+
</div>
|
|
299
|
+
<p class="muted" id="breaks-copy">Every 45 min of non-stop work, a nudge to stretch and drink water.</p>
|
|
300
|
+
<div class="breaks" id="breaks" style="margin-top:14px">
|
|
301
|
+
<label class="switch"><span>Remind me to take breaks</span><input type="checkbox" role="switch" id="breaks-enabled"></label>
|
|
302
|
+
<div class="when">
|
|
303
|
+
<label class="slider-row" for="breaks-minutes">
|
|
304
|
+
<span class="field-label" style="margin:0">After this much non-stop work</span>
|
|
305
|
+
<span class="minutes"><output id="breaks-minutes-out" for="breaks-minutes">45</output> min</span>
|
|
306
|
+
</label>
|
|
307
|
+
<input type="range" id="breaks-minutes" min="15" max="120" step="5" value="45">
|
|
308
|
+
</div>
|
|
309
|
+
<div class="when">
|
|
310
|
+
<span class="field-label" id="breaks-sound-label">Sound</span>
|
|
311
|
+
<div class="sound-row">
|
|
312
|
+
<select id="breaks-sound" aria-labelledby="breaks-sound-label"></select>
|
|
313
|
+
<button class="btn" type="button" id="breaks-test">▶ Test</button>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
<div class="when">
|
|
317
|
+
<span class="field-label">When</span>
|
|
318
|
+
<p class="muted small" id="hours-note" style="margin:0">Only inside these times. Outside them: no break sounds.</p>
|
|
319
|
+
<ul class="hours-list" id="hours-list"></ul>
|
|
320
|
+
<button class="btn" type="button" id="hours-add">Add a time block</button>
|
|
321
|
+
</div>
|
|
322
|
+
</div>
|
|
323
|
+
<div class="locked hidden" id="breaks-locked">
|
|
324
|
+
<div class="lock-cover">
|
|
325
|
+
<span>🔒 Break reminders come with the paid plan</span>
|
|
326
|
+
<span class="pro-badge">Paid</span>
|
|
327
|
+
<a class="btn primary" id="upgrade-breaks" target="_blank" rel="noopener noreferrer">Get the paid plan</a>
|
|
328
|
+
</div>
|
|
329
|
+
</div>
|
|
330
|
+
</section>
|
|
331
|
+
|
|
332
|
+
<section class="card" aria-labelledby="phone-title">
|
|
333
|
+
<div class="card-head">
|
|
334
|
+
<h2 id="phone-title">Phone alerts <span class="pro-badge">Paid</span></h2>
|
|
335
|
+
</div>
|
|
336
|
+
<p class="muted">Also send every alarm and break reminder to your phone, through the free ntfy app. Set it up once on your account page. The phone plays its own notification sound.</p>
|
|
337
|
+
<div class="breaks" id="phone" style="margin-top:14px">
|
|
338
|
+
<label class="switch"><span>Send alerts to my phone</span><input type="checkbox" role="switch" id="phone-enabled"></label>
|
|
339
|
+
<p class="small muted" style="margin-top:8px"><a id="phone-setup" target="_blank" rel="noopener noreferrer">Set up your phone</a></p>
|
|
340
|
+
</div>
|
|
341
|
+
<div class="locked hidden" id="phone-locked">
|
|
342
|
+
<div class="lock-cover">
|
|
343
|
+
<span>🔒 Phone alerts come with the paid plan</span>
|
|
344
|
+
<span class="pro-badge">Paid</span>
|
|
345
|
+
<a class="btn primary" id="upgrade-phone" target="_blank" rel="noopener noreferrer">Get the paid plan</a>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
</section>
|
|
349
|
+
|
|
350
|
+
<section class="card" aria-labelledby="sounds-title">
|
|
351
|
+
<div class="card-head">
|
|
352
|
+
<h2 id="sounds-title">Sounds</h2>
|
|
353
|
+
<span class="muted small">Click a sound to hear it.</span>
|
|
354
|
+
</div>
|
|
355
|
+
<div class="tiles" id="tiles"></div>
|
|
356
|
+
<div id="custom-area">
|
|
357
|
+
<h3 style="margin-top:20px">Your sounds <span class="pro-badge">Paid</span></h3>
|
|
358
|
+
<div class="tiles" id="custom-tiles" style="margin-top:10px"></div>
|
|
359
|
+
<p class="upload-msg">Add your own from an MP3, WAV, M4A or a video in <a id="add-sounds" target="_blank" rel="noopener noreferrer">your account</a>. Every computer gets them within a few minutes.</p>
|
|
360
|
+
</div>
|
|
361
|
+
<div class="locked hidden" id="custom-locked">
|
|
362
|
+
<div class="lock-cover">
|
|
363
|
+
<span>🔒 The sound library, and your own from MP3, WAV, M4A or a video</span>
|
|
364
|
+
<span class="pro-badge">Paid</span>
|
|
365
|
+
<a class="btn primary" id="upgrade-sounds" target="_blank" rel="noopener noreferrer">Get the paid plan</a>
|
|
366
|
+
</div>
|
|
367
|
+
</div>
|
|
368
|
+
</section>
|
|
369
|
+
|
|
370
|
+
<details class="danger-zone">
|
|
371
|
+
<summary>Danger zone</summary>
|
|
372
|
+
<div class="danger-body">
|
|
373
|
+
<div class="danger-row">
|
|
374
|
+
<span id="plugin-state" class="muted">Checking the plugin…</span>
|
|
375
|
+
<button class="btn" id="toggle" type="button" disabled>Turn off</button>
|
|
376
|
+
</div>
|
|
377
|
+
<div class="danger-row">
|
|
378
|
+
<label class="switch" style="justify-content:flex-start"><input type="checkbox" role="switch" id="delete-data"> <span>Also delete my settings and custom sounds</span></label>
|
|
379
|
+
<button class="btn danger" id="uninstall" type="button">Uninstall</button>
|
|
380
|
+
</div>
|
|
381
|
+
<ul class="steps hidden" id="steps"></ul>
|
|
382
|
+
</div>
|
|
383
|
+
</details>
|
|
384
|
+
|
|
385
|
+
<div class="foot">
|
|
386
|
+
<span>Changes save automatically.</span>
|
|
387
|
+
<button class="btn quiet" id="done" type="button">Close settings</button>
|
|
388
|
+
</div>
|
|
389
|
+
</main>
|
|
390
|
+
|
|
391
|
+
<p class="toast" id="toast" role="status" aria-live="polite"></p>
|
|
392
|
+
|
|
393
|
+
<script nonce="__NONCE__">
|
|
394
|
+
'use strict'
|
|
395
|
+
const token = new URLSearchParams(location.search).get('token') || ''
|
|
396
|
+
const $ = id => document.getElementById(id)
|
|
397
|
+
const SOUNDS = {
|
|
398
|
+
'sad-trombone': ['🎺', 'Sad trombone', 'The classic'],
|
|
399
|
+
chime: ['🔔', 'Chime', 'Gentle'],
|
|
400
|
+
alarm: ['🚨', 'Alarm', 'Hard to miss'],
|
|
401
|
+
boing: ['🪀', 'Boing', 'Silly'],
|
|
402
|
+
'break-chime': ['☕', 'Break chime', 'For break reminders'],
|
|
403
|
+
faaah: ['😱', 'Faaah', 'Meme'],
|
|
404
|
+
'among-us-reveal': ['🚀', 'Among Us reveal', 'Meme'],
|
|
405
|
+
shocked: ['😲', 'Shocked', 'Meme'],
|
|
406
|
+
dexter: ['🔪', 'Dexter meme', 'Meme'],
|
|
407
|
+
'camera-shutter': ['📸', 'Camera shutter', 'Meme'],
|
|
408
|
+
'end-credits': ['🎬', 'End credits', 'Meme'],
|
|
409
|
+
'out-of-your-mind': ['🤯', 'Are you out of your mind', 'Meme'],
|
|
410
|
+
'funny-laugh': ['😂', 'Funny laugh', 'Meme'],
|
|
411
|
+
'spiderman-song': ['🕷️', 'Spider-Man song', 'Meme'],
|
|
412
|
+
'chicken-scream': ['🐔', 'Chicken scream', 'Meme'],
|
|
413
|
+
explosion: ['💥', 'Explosion', 'Meme'],
|
|
414
|
+
punch: ['👊', 'Punch', 'Meme'],
|
|
415
|
+
'cat-laugh': ['😹', 'Cat laugh', 'Meme'],
|
|
416
|
+
'bark-fart': ['🐶', 'Bark and fart', 'Meme'],
|
|
417
|
+
'metal-gear-alert': ['❗', 'Metal Gear alert', 'Meme'],
|
|
418
|
+
'baby-laugh': ['👶', 'Baby laugh', 'Meme'],
|
|
419
|
+
huh: ['❓', 'Huh?', 'Meme'],
|
|
420
|
+
'du-bist-gut-genug': ['💪', 'Du bist gut genug', 'Meme'],
|
|
421
|
+
'huh-cat': ['🐱', 'Huh? cat', 'Meme'],
|
|
422
|
+
'sad-violin': ['🎻', 'Sad violin', 'Meme'],
|
|
423
|
+
'oh-my-god': ['🙀', 'Oh my god', 'Meme'],
|
|
424
|
+
'ayyy-scream': ['🗣️', 'Ayyy scream', 'Meme'],
|
|
425
|
+
'e-lutador': ['🥊', 'É lutador', 'Meme'],
|
|
426
|
+
'duck-toy': ['🦆', 'Duck toy', 'Meme'],
|
|
427
|
+
aayein: ['🤨', 'Aayein', 'Meme'],
|
|
428
|
+
gunshot: ['🔫', 'Gunshot', 'Meme'],
|
|
429
|
+
'fortnite-death': ['☠️', 'Fortnite death', 'Meme'],
|
|
430
|
+
'social-credit-siren': ['🚨', '-999 social credit', 'Meme'],
|
|
431
|
+
'brain-fart': ['🧠', 'Long brain fart', 'Meme'],
|
|
432
|
+
galaxy: ['🌌', 'Galaxy meme', 'Meme'],
|
|
433
|
+
nuagghhhh: ['😫', 'Nuagghhhh', 'Meme'],
|
|
434
|
+
bruh: ['😑', 'Bruh', 'Meme'],
|
|
435
|
+
awkward: ['😬', 'Awkward moment', 'Meme'],
|
|
436
|
+
snapchat: ['👻', 'Snapchat message', 'Meme'],
|
|
437
|
+
run: ['🏃', 'Run', 'Meme'],
|
|
438
|
+
'vine-boom': ['🔊', 'Vine boom', 'Meme'],
|
|
439
|
+
damn: ['😤', 'Damn!', 'Meme'],
|
|
440
|
+
faaaaaa: ['😩', 'Faaaaaa', 'Meme'],
|
|
441
|
+
yoooo: ['🎌', 'Yoooo', 'Meme'],
|
|
442
|
+
}
|
|
443
|
+
// Same scale and lines as the landing page. Doneness follows whichever window has the least left.
|
|
444
|
+
const LEVELS = [
|
|
445
|
+
{ id: 'rare', min: 60, icon: '🥩', line: 'Rare. Plenty of tokens, go wild.' },
|
|
446
|
+
{ id: 'medium', min: 30, icon: '🍳', line: 'Medium. Pace yourself, chef.' },
|
|
447
|
+
{ id: 'well', min: 10, icon: '🍖', line: 'Well-done. Choose your next prompt wisely.' },
|
|
448
|
+
{ id: 'cooked', min: -1, icon: '💀', line: "Cooked. You're nearly out." },
|
|
449
|
+
]
|
|
450
|
+
const SPINNER = ['·', '✢', '✳', '✶', '✻', '✽', '✻', '✶', '✳', '✢']
|
|
451
|
+
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
452
|
+
|
|
453
|
+
let state
|
|
454
|
+
let config
|
|
455
|
+
const levelFor = left => LEVELS.find(level => left > level.min)
|
|
456
|
+
|
|
457
|
+
function h(tag, attrs = {}, ...children) {
|
|
458
|
+
const el = document.createElement(tag)
|
|
459
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
460
|
+
if (value === undefined || value === false) continue
|
|
461
|
+
if (key.startsWith('on')) el.addEventListener(key.slice(2), value)
|
|
462
|
+
else if (value === true) el.setAttribute(key, '')
|
|
463
|
+
else el.setAttribute(key, value)
|
|
464
|
+
}
|
|
465
|
+
el.append(...children.filter(child => child !== undefined && child !== null && child !== false))
|
|
466
|
+
return el
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function api(path, options = {}) {
|
|
470
|
+
let res
|
|
471
|
+
try {
|
|
472
|
+
res = await fetch(path, { ...options, headers: { 'x-token': token, ...(options.headers || {}) } })
|
|
473
|
+
} catch {
|
|
474
|
+
// No answer at all: the config command that serves this page has stopped.
|
|
475
|
+
throw new Error('Settings closed. Run npx amicookedyet@latest config again to keep editing.')
|
|
476
|
+
}
|
|
477
|
+
const body = res.headers.get('content-type')?.includes('json') ? await res.json() : await res.blob()
|
|
478
|
+
if (!res.ok) throw new Error(body.error || `Request failed (${res.status})`)
|
|
479
|
+
return body
|
|
480
|
+
}
|
|
481
|
+
const postJson = (path, body) => api(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body ?? {}) })
|
|
482
|
+
|
|
483
|
+
let toastTimer
|
|
484
|
+
function toast(message, error = false) {
|
|
485
|
+
const el = $('toast')
|
|
486
|
+
el.textContent = message
|
|
487
|
+
el.classList.toggle('error', error)
|
|
488
|
+
el.classList.add('show')
|
|
489
|
+
clearTimeout(toastTimer)
|
|
490
|
+
toastTimer = setTimeout(() => el.classList.remove('show'), error ? 4000 : 1600)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// --- Theme (remembered per browser, like the landing page) ---------------------
|
|
494
|
+
const root = document.documentElement
|
|
495
|
+
const systemDark = matchMedia('(prefers-color-scheme: dark)')
|
|
496
|
+
try { const saved = localStorage.getItem('theme'); if (saved === 'light' || saved === 'dark') root.dataset.theme = saved } catch {}
|
|
497
|
+
const isDark = () => (root.dataset.theme ? root.dataset.theme === 'dark' : systemDark.matches)
|
|
498
|
+
const syncTheme = () => $('theme-toggle').setAttribute('aria-label', `Switch to ${isDark() ? 'light' : 'dark'} theme`)
|
|
499
|
+
$('theme-toggle').addEventListener('click', () => {
|
|
500
|
+
root.dataset.theme = isDark() ? 'light' : 'dark'
|
|
501
|
+
try { localStorage.setItem('theme', root.dataset.theme) } catch {}
|
|
502
|
+
syncTheme()
|
|
503
|
+
})
|
|
504
|
+
systemDark.addEventListener('change', syncTheme)
|
|
505
|
+
syncTheme()
|
|
506
|
+
|
|
507
|
+
// --- Autosave -----------------------------------------------------------------
|
|
508
|
+
let saveTimer
|
|
509
|
+
let saving = Promise.resolve()
|
|
510
|
+
function changed({ rerender = true } = {}) {
|
|
511
|
+
if (rerender) render()
|
|
512
|
+
else renderPreview()
|
|
513
|
+
clearTimeout(saveTimer)
|
|
514
|
+
saveTimer = setTimeout(save, 450)
|
|
515
|
+
}
|
|
516
|
+
function save() {
|
|
517
|
+
saving = saving.then(async () => {
|
|
518
|
+
try {
|
|
519
|
+
const saved = (await api('/api/config', { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify(config) })).config
|
|
520
|
+
// Keep what the user is editing; take only what the server corrected.
|
|
521
|
+
if (JSON.stringify(saved) !== JSON.stringify(config)) { config = saved; render() }
|
|
522
|
+
toast('Saved')
|
|
523
|
+
scheduleSync()
|
|
524
|
+
} catch (error) {
|
|
525
|
+
toast(`Not saved: ${error.message}`, true)
|
|
526
|
+
}
|
|
527
|
+
})
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// --- Sync with the license (paid) ------------------------------------------------
|
|
531
|
+
// Saves land on disk at once; they go to the license a few seconds after the
|
|
532
|
+
// last one, since the API takes 30 an hour from a computer, and on Done.
|
|
533
|
+
let syncTimer
|
|
534
|
+
function scheduleSync() {
|
|
535
|
+
clearTimeout(syncTimer)
|
|
536
|
+
if (state?.plan === 'paid') syncTimer = setTimeout(syncNow, 5000)
|
|
537
|
+
}
|
|
538
|
+
async function syncNow() {
|
|
539
|
+
clearTimeout(syncTimer)
|
|
540
|
+
if (state?.plan !== 'paid') return 'off'
|
|
541
|
+
try {
|
|
542
|
+
const { sync } = await postJson('/api/sync')
|
|
543
|
+
$('sync-conflict').classList.toggle('hidden', sync !== 'conflict')
|
|
544
|
+
return sync
|
|
545
|
+
} catch {
|
|
546
|
+
return 'pending'
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
async function resolveSync(keep) {
|
|
550
|
+
try {
|
|
551
|
+
const { sync } = await postJson('/api/sync/resolve', { keep })
|
|
552
|
+
$('sync-conflict').classList.toggle('hidden', sync !== 'conflict')
|
|
553
|
+
if (keep === 'theirs') await load()
|
|
554
|
+
if (sync === 'synced') toast(keep === 'theirs' ? 'Using the newer settings' : "Kept this computer's settings")
|
|
555
|
+
else if (sync === 'pending') toast('Not sent yet. Claude Code sends it when it starts.')
|
|
556
|
+
} catch (error) {
|
|
557
|
+
toast(error.message, true)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
$('keep-mine').addEventListener('click', () => resolveSync('mine'))
|
|
561
|
+
$('use-theirs').addEventListener('click', () => resolveSync('theirs'))
|
|
562
|
+
|
|
563
|
+
// --- Sounds -------------------------------------------------------------------
|
|
564
|
+
let player
|
|
565
|
+
let playingKey
|
|
566
|
+
async function play(sound, tile) {
|
|
567
|
+
if (sound === 'none') return toast('This alarm has no sound')
|
|
568
|
+
const custom = sound.startsWith('custom:') && config.customSounds.find(item => `custom:${item.id}` === sound)
|
|
569
|
+
const path = custom ? `/sounds/custom/${custom.file}` : `/sounds/builtin/${sound}.wav`
|
|
570
|
+
try {
|
|
571
|
+
const blob = await api(path)
|
|
572
|
+
player?.pause()
|
|
573
|
+
if (player) URL.revokeObjectURL(player.src)
|
|
574
|
+
document.querySelectorAll('.tile.playing').forEach(el => el.classList.remove('playing'))
|
|
575
|
+
player = new Audio(URL.createObjectURL(blob))
|
|
576
|
+
playingKey = sound
|
|
577
|
+
tile?.classList.add('playing')
|
|
578
|
+
player.addEventListener('ended', () => { tile?.classList.remove('playing'); playingKey = undefined })
|
|
579
|
+
await player.play()
|
|
580
|
+
} catch (error) {
|
|
581
|
+
toast(`Could not play: ${error.message}`, true)
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const soundName = sound =>
|
|
585
|
+
sound === 'none' ? 'No sound' : SOUNDS[sound]?.[1] ?? config.customSounds.find(item => `custom:${item.id}` === sound)?.name ?? (sound.startsWith('custom:') ? 'Own sound from another computer' : SOUNDS[state.presetSound]?.[1] ?? state.presetSound)
|
|
586
|
+
|
|
587
|
+
// --- Preview ------------------------------------------------------------------
|
|
588
|
+
const leftNow = () => ({ five_hour: Number($('left-5h').value), seven_day: Number($('left-week').value) })
|
|
589
|
+
const isDue = (alarm, kind, left) => config.alarmsOn?.[kind] !== false && (alarm.window === 'any' || alarm.window === kind) && left <= alarm.percentLeft
|
|
590
|
+
|
|
591
|
+
function renderPreview() {
|
|
592
|
+
const left = leftNow()
|
|
593
|
+
$('left-5h-out').textContent = `${left.five_hour}%`
|
|
594
|
+
$('left-week-out').textContent = `${left.seven_day}%`
|
|
595
|
+
const level = levelFor(Math.min(left.five_hour, left.seven_day))
|
|
596
|
+
const text = `${level.icon} 5h ${left.five_hour}% left · week ${left.seven_day}% left · ${level.line}`
|
|
597
|
+
const due = config.alarms.filter(alarm => isDue(alarm, 'five_hour', left.five_hour) || isDue(alarm, 'seven_day', left.seven_day))
|
|
598
|
+
// Low once any alarm is due, or past 20% left when none is set (as in the plugin).
|
|
599
|
+
const low = config.alarms.length ? due.length > 0 : Math.min(left.five_hour, left.seven_day) <= 20
|
|
600
|
+
const spinnerShown = config.line.spinner === 'always' || (config.line.spinner === 'low' && low)
|
|
601
|
+
|
|
602
|
+
$('spinner-text').textContent = spinnerShown ? text : 'Thinking…'
|
|
603
|
+
$('spinner-line').className = `t-line ${spinnerShown ? level.id : 't-dim'}`
|
|
604
|
+
for (const li of $('scale').children) li.classList.toggle('on', li.dataset.level === level.id)
|
|
605
|
+
|
|
606
|
+
const effect = alarm => [alarm.notify && 'notification', alarm.sound !== 'none' && soundName(alarm.sound).toLowerCase()].filter(Boolean).join(' + ') || 'silent'
|
|
607
|
+
$('firing').replaceChildren(
|
|
608
|
+
due.length
|
|
609
|
+
? h('span', {}, '🔔 ', ...due.flatMap((alarm, i) => [i ? '; ' : '', h('strong', {}, `Alarm ${config.alarms.indexOf(alarm) + 1}`), ` fires (${effect(alarm)})`]), '.')
|
|
610
|
+
: h('span', { class: 'muted' }, config.alarms.length ? 'No alarm fires at this level.' : 'No alarms set. Add one below.'),
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
let frame = 0
|
|
615
|
+
if (!reducedMotion) setInterval(() => { $('spin').textContent = SPINNER[frame++ % SPINNER.length] }, 120)
|
|
616
|
+
$('left-5h').addEventListener('input', renderPreview)
|
|
617
|
+
$('left-week').addEventListener('input', renderPreview)
|
|
618
|
+
|
|
619
|
+
function showAt(percent, window) {
|
|
620
|
+
// Moves the preview to where this alarm fires, so Test shows the line too.
|
|
621
|
+
if (window !== 'seven_day') $('left-5h').value = percent
|
|
622
|
+
if (window === 'seven_day') $('left-week').value = percent
|
|
623
|
+
if (window === 'any') $('left-week').value = Math.max(percent, Number($('left-week').value))
|
|
624
|
+
renderPreview()
|
|
625
|
+
const line = $('spinner-line')
|
|
626
|
+
line.classList.remove('flash')
|
|
627
|
+
void line.offsetWidth
|
|
628
|
+
line.classList.add('flash')
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// --- Alarms -------------------------------------------------------------------
|
|
632
|
+
// Two groups, one per limit. Every change saves at once: add, move, sound,
|
|
633
|
+
// switch and remove are each one click or one drag.
|
|
634
|
+
const limits = () => state.limits[state.plan]
|
|
635
|
+
const LIMITS = [['five_hour', '5-hour limit'], ['seven_day', 'Weekly limit']]
|
|
636
|
+
// The 29 steps as % left, most left first: 99, 95 … 10, 9 … 0.
|
|
637
|
+
const steps = () => state.alarmSteps
|
|
638
|
+
// People think of a limit as used: "at 90% used".
|
|
639
|
+
const usedText = left => `${100 - left}% used`
|
|
640
|
+
const alarmsIn = window => config.alarms.filter(alarm => alarm.window === window)
|
|
641
|
+
const takenIn = (window, except) => new Set(alarmsIn(window).filter(alarm => alarm !== except).map(alarm => alarm.percentLeft))
|
|
642
|
+
// The free step nearest to `index`, so two alarms never share a step.
|
|
643
|
+
function freeStep(index, taken) {
|
|
644
|
+
for (let gap = 0; gap < steps().length; gap++) {
|
|
645
|
+
for (const i of [index + gap, index - gap]) if (i >= 0 && i < steps().length && !taken.has(steps()[i])) return i
|
|
646
|
+
}
|
|
647
|
+
return -1
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function soundSelect(alarm, label) {
|
|
651
|
+
const select = h('select', { 'aria-label': label })
|
|
652
|
+
const builtIn = h('optgroup', { label: 'Built in' }, ...state.builtInSounds.map(name => h('option', { value: name }, `${SOUNDS[name]?.[0] ?? '🔊'} ${SOUNDS[name]?.[1] ?? name}`)))
|
|
653
|
+
select.append(builtIn)
|
|
654
|
+
if (limits().customSounds && config.customSounds.length) {
|
|
655
|
+
select.append(h('optgroup', { label: 'Your sounds' }, ...config.customSounds.map(sound => h('option', { value: `custom:${sound.id}` }, `🎵 ${sound.name}`))))
|
|
656
|
+
}
|
|
657
|
+
// Chosen on another computer, through the license: it plays the preset here.
|
|
658
|
+
if (alarm.sound.startsWith('custom:') && !config.customSounds.some(sound => `custom:${sound.id}` === alarm.sound)) {
|
|
659
|
+
select.append(h('option', { value: alarm.sound }, '🎵 Own sound from another computer'))
|
|
660
|
+
}
|
|
661
|
+
select.append(h('option', { value: 'none' }, '🔇 No sound'))
|
|
662
|
+
select.value = alarm.sound
|
|
663
|
+
select.disabled = Boolean(limits().fixedSound)
|
|
664
|
+
select.addEventListener('change', () => { alarm.sound = select.value; changed({ rerender: false }) })
|
|
665
|
+
return select
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function alarmRow(alarm, n, name) {
|
|
669
|
+
const fixed = limits().fixedPercentLeft !== undefined
|
|
670
|
+
const label = `${name} alarm ${n}`
|
|
671
|
+
const level = levelFor(alarm.percentLeft)
|
|
672
|
+
const num = h('strong', { class: 'num' }, usedText(alarm.percentLeft))
|
|
673
|
+
const left = h('span', { class: 'muted small' }, `${alarm.percentLeft}% left`)
|
|
674
|
+
const row = h('li', { class: `alarm-row ${level.id}` })
|
|
675
|
+
|
|
676
|
+
const slider = h('input', {
|
|
677
|
+
type: 'range', min: '0', max: String(steps().length - 1), step: '1',
|
|
678
|
+
value: String(steps().indexOf(alarm.percentLeft)),
|
|
679
|
+
'aria-label': `${label}: fires at`, 'aria-valuetext': usedText(alarm.percentLeft),
|
|
680
|
+
disabled: fixed,
|
|
681
|
+
})
|
|
682
|
+
slider.addEventListener('input', () => {
|
|
683
|
+
// Slides past steps another alarm on this limit already holds.
|
|
684
|
+
const index = freeStep(Number(slider.value), takenIn(alarm.window, alarm))
|
|
685
|
+
if (index < 0) return
|
|
686
|
+
slider.value = String(index)
|
|
687
|
+
alarm.percentLeft = steps()[index]
|
|
688
|
+
const next = levelFor(alarm.percentLeft)
|
|
689
|
+
num.textContent = usedText(alarm.percentLeft)
|
|
690
|
+
left.textContent = `${alarm.percentLeft}% left`
|
|
691
|
+
slider.setAttribute('aria-valuetext', usedText(alarm.percentLeft))
|
|
692
|
+
row.className = `alarm-row ${next.id}`
|
|
693
|
+
changed({ rerender: false })
|
|
694
|
+
})
|
|
695
|
+
|
|
696
|
+
const notify = h('input', { type: 'checkbox', role: 'switch', checked: alarm.notify, 'aria-label': `${label}: system notification` })
|
|
697
|
+
notify.addEventListener('change', () => { alarm.notify = notify.checked; changed({ rerender: false }) })
|
|
698
|
+
|
|
699
|
+
row.append(
|
|
700
|
+
h('div', { class: 'when' }, h('span', { 'aria-hidden': 'true' }, level.icon), num, left),
|
|
701
|
+
slider,
|
|
702
|
+
h('div', { class: 'what' },
|
|
703
|
+
soundSelect(alarm, `${label}: sound`),
|
|
704
|
+
h('button', { class: 'btn', type: 'button', 'aria-label': `Test ${label}`, title: 'Test', onclick: () => { showAt(alarm.percentLeft, alarm.window); play(alarm.sound) } }, '▶'),
|
|
705
|
+
h('label', { class: 'switch mini', title: 'System notification' }, h('span', { class: 'small' }, 'Notify'), notify),
|
|
706
|
+
!fixed && h('button', { class: 'btn quiet', type: 'button', 'aria-label': `Remove ${label}`, title: 'Remove', onclick: () => { config.alarms.splice(config.alarms.indexOf(alarm), 1); changed() } }, '✕'),
|
|
707
|
+
),
|
|
708
|
+
)
|
|
709
|
+
return row
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function limitGroup([window, name]) {
|
|
713
|
+
const max = limits().alarms[window]
|
|
714
|
+
const alarms = alarmsIn(window)
|
|
715
|
+
const on = config.alarmsOn?.[window] !== false
|
|
716
|
+
const group = h('section', { class: `limit ${on ? '' : 'off'}`, 'aria-label': name })
|
|
717
|
+
|
|
718
|
+
if (max === 0) {
|
|
719
|
+
group.append(
|
|
720
|
+
h('div', { class: 'limit-head' }, h('h3', {}, name)),
|
|
721
|
+
h('p', { class: 'locked' }, `🔒 ${name} alarms come with the paid plan. `,
|
|
722
|
+
h('a', { href: state.links.buy, target: '_blank', rel: 'noopener noreferrer' }, 'Get the paid plan')),
|
|
723
|
+
)
|
|
724
|
+
return group
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
const toggle = h('input', { type: 'checkbox', role: 'switch', checked: on, 'aria-label': `${name} alarms on` })
|
|
728
|
+
toggle.addEventListener('change', () => { config.alarmsOn = { ...config.alarmsOn, [window]: toggle.checked }; changed() })
|
|
729
|
+
const free = freeStep(steps().indexOf(20), takenIn(window))
|
|
730
|
+
const canAdd = alarms.length < max && free >= 0
|
|
731
|
+
const add = () => {
|
|
732
|
+
config.alarms.push({ id: `alarm-${Math.random().toString(36).slice(2, 8)}`, percentLeft: steps()[free], window, sound: state.presetSound, notify: true })
|
|
733
|
+
changed()
|
|
734
|
+
$('alarms').querySelector(`[aria-label="${name}"] .alarm-row:last-child input[type=range]`)?.focus()
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
group.append(...[
|
|
738
|
+
h('div', { class: 'limit-head' },
|
|
739
|
+
h('h3', {}, name),
|
|
740
|
+
h('span', { class: 'muted small' }, `${alarms.length} of ${max}`),
|
|
741
|
+
h('label', { class: 'switch' }, h('span', { class: 'small' }, on ? 'On' : 'Off'), toggle),
|
|
742
|
+
),
|
|
743
|
+
alarms.length
|
|
744
|
+
? h('ol', { class: 'alarm-list' }, ...alarms.map((alarm, i) => alarmRow(alarm, i + 1, name)))
|
|
745
|
+
: h('p', { class: 'muted small' }, 'No alarms on this limit.'),
|
|
746
|
+
canAdd && h('button', { class: 'btn add', type: 'button', onclick: add }, '+ Add alarm'),
|
|
747
|
+
!canAdd && state.plan !== 'paid' && h('p', { class: 'small muted' }, 'More alarms come with the paid plan. ',
|
|
748
|
+
h('a', { href: state.links.buy, target: '_blank', rel: 'noopener noreferrer' }, 'Get the paid plan')),
|
|
749
|
+
].filter(Boolean))
|
|
750
|
+
return group
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
function renderAlarms() {
|
|
754
|
+
$('alarms').replaceChildren(...LIMITS.map(limitGroup))
|
|
755
|
+
const fixed = limits().fixedPercentLeft
|
|
756
|
+
$('alarm-count').textContent = fixed !== undefined ? `Free plan: one alarm at ${usedText(fixed)}` : 'When several are due at once, only the most urgent plays.'
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// --- Sound library ------------------------------------------------------------
|
|
760
|
+
function renderSounds() {
|
|
761
|
+
$('tiles').replaceChildren(...state.builtInSounds.map(name => {
|
|
762
|
+
const [emoji, label, note] = SOUNDS[name] ?? ['🔊', name, '']
|
|
763
|
+
const tile = h('button', { class: 'tile', type: 'button', 'aria-label': `Play ${label}` }, h('span', { class: 'emoji', 'aria-hidden': 'true' }, emoji), h('strong', {}, label), h('small', {}, note))
|
|
764
|
+
tile.addEventListener('click', () => play(name, tile))
|
|
765
|
+
return tile
|
|
766
|
+
}))
|
|
767
|
+
|
|
768
|
+
const open = limits().customSounds
|
|
769
|
+
$('custom-area').classList.toggle('hidden', !open)
|
|
770
|
+
$('custom-locked').classList.toggle('hidden', open)
|
|
771
|
+
// Own sounds are added, renamed and removed in the account; here they play.
|
|
772
|
+
$('custom-tiles').replaceChildren(...config.customSounds.map(sound => {
|
|
773
|
+
const tile = h('button', { class: 'tile', type: 'button', 'aria-label': `Play ${sound.name}` }, h('span', { class: 'emoji', 'aria-hidden': 'true' }, '🎵'), h('strong', {}, sound.name), h('small', {}, 'yours'))
|
|
774
|
+
tile.addEventListener('click', () => play(`custom:${sound.id}`, tile))
|
|
775
|
+
return tile
|
|
776
|
+
}))
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// --- Account ------------------------------------------------------------------
|
|
780
|
+
const when = seconds => new Date(seconds * 1000).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })
|
|
781
|
+
const link = (label, href, primary) => h('a', { class: `btn${primary ? ' primary' : ''}`, href, target: '_blank', rel: 'noopener noreferrer' }, label)
|
|
782
|
+
|
|
783
|
+
function renderAccount(failed) {
|
|
784
|
+
const box = $('account')
|
|
785
|
+
const account = state.account
|
|
786
|
+
if (!account.activated) {
|
|
787
|
+
const input = h('input', { type: 'text', id: 'code', placeholder: 'BCDFG-HJKLM', autocomplete: 'off', spellcheck: 'false', maxlength: '16', 'aria-label': 'Activation code' })
|
|
788
|
+
input.addEventListener('keydown', event => { if (event.key === 'Enter') activate(input) })
|
|
789
|
+
box.replaceChildren(
|
|
790
|
+
h('div', { class: 'who' },
|
|
791
|
+
h('strong', {}, 'Free plan'),
|
|
792
|
+
h('p', { class: 'muted' }, account.lapsed
|
|
793
|
+
? `${account.lapsed} You're on the free plan now. To use the paid plan again, buy it again.`
|
|
794
|
+
: 'The usage line, the jokes and one alarm at 10% left. Bought the paid plan? Type your activation code.'),
|
|
795
|
+
failed && h('p', { class: 'small', style: 'color:var(--danger);margin-top:4px', role: 'alert' }, failed),
|
|
796
|
+
),
|
|
797
|
+
h('div', { class: 'actions' },
|
|
798
|
+
input,
|
|
799
|
+
h('button', { class: 'btn primary', type: 'button', onclick: () => activate(input) }, 'Activate'),
|
|
800
|
+
link('Get the paid plan', state.links.buy),
|
|
801
|
+
link('My account', state.links.manage),
|
|
802
|
+
),
|
|
803
|
+
)
|
|
804
|
+
return
|
|
805
|
+
}
|
|
806
|
+
if (account.lapsed) {
|
|
807
|
+
// The API says this computer was removed from the license, though its token hasn't expired.
|
|
808
|
+
box.replaceChildren(
|
|
809
|
+
h('div', { class: 'who' },
|
|
810
|
+
h('strong', {}, 'Paid plan '),
|
|
811
|
+
h('span', { class: 'tag' }, 'Not active'),
|
|
812
|
+
h('p', { style: 'margin-top:2px;font-weight:600' }, account.lapsed),
|
|
813
|
+
h('p', { class: 'muted' }, "You're on the free plan until you activate this computer again. Your settings are kept."),
|
|
814
|
+
),
|
|
815
|
+
h('div', { class: 'actions' },
|
|
816
|
+
link('My account', state.links.manage, true),
|
|
817
|
+
h('button', { class: 'btn quiet', type: 'button', onclick: signOutNow }, 'Remove license'),
|
|
818
|
+
),
|
|
819
|
+
)
|
|
820
|
+
return
|
|
821
|
+
}
|
|
822
|
+
const expired = account.licenseExpiresAt && account.licenseExpiresAt * 1000 <= Date.now()
|
|
823
|
+
box.replaceChildren(
|
|
824
|
+
h('div', { class: 'who' },
|
|
825
|
+
h('strong', {}, 'Paid plan '),
|
|
826
|
+
h('span', { class: `tag${expired ? '' : ' ok'}` }, expired ? 'Expired' : 'Active'),
|
|
827
|
+
h('p', { style: 'margin-top:2px;font-weight:600' }, 'Yours for good'),
|
|
828
|
+
h('div', { class: 'facts muted small' },
|
|
829
|
+
account.licenseExpiresAt && h('span', {}, `Renews itself daily; this check is good until ${when(account.licenseExpiresAt)}`),
|
|
830
|
+
!account.verified && h('span', {}, 'Not verified by this build'),
|
|
831
|
+
),
|
|
832
|
+
),
|
|
833
|
+
h('div', { class: 'actions' },
|
|
834
|
+
link('My account', state.links.manage),
|
|
835
|
+
h('button', { class: 'btn quiet', type: 'button', onclick: signOutNow }, 'Remove license'),
|
|
836
|
+
),
|
|
837
|
+
)
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
async function activate(input) {
|
|
841
|
+
if (!input.value.trim()) return input.focus()
|
|
842
|
+
try {
|
|
843
|
+
await postJson('/api/activate', { code: input.value })
|
|
844
|
+
await load()
|
|
845
|
+
toast('Activated. Restart Claude Code to apply it.')
|
|
846
|
+
} catch (error) {
|
|
847
|
+
renderAccount(error.message)
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
async function signOutNow() {
|
|
852
|
+
if (!confirm('Remove the license from this computer? It frees the slot, the paid features stop here, and your settings are kept. A new code brings them back.')) return
|
|
853
|
+
try {
|
|
854
|
+
await postJson('/api/logout')
|
|
855
|
+
await load()
|
|
856
|
+
toast('License removed from this computer')
|
|
857
|
+
} catch (error) {
|
|
858
|
+
toast(error.message, true)
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// --- Danger zone --------------------------------------------------------------
|
|
863
|
+
function renderPlugin(plugin) {
|
|
864
|
+
const toggle = $('toggle')
|
|
865
|
+
toggle.disabled = !plugin?.installed
|
|
866
|
+
toggle.textContent = plugin?.installed && !plugin.enabled ? 'Turn on' : 'Turn off'
|
|
867
|
+
$('plugin-state').textContent = !plugin
|
|
868
|
+
? 'Could not reach Claude Code.'
|
|
869
|
+
: !plugin.installed
|
|
870
|
+
? 'The Claude Code plugin is not installed.'
|
|
871
|
+
: plugin.enabled
|
|
872
|
+
? 'The Claude Code plugin is on.'
|
|
873
|
+
: 'The Claude Code plugin is off. Your settings are kept.'
|
|
874
|
+
}
|
|
875
|
+
function showSteps(steps) {
|
|
876
|
+
$('steps').replaceChildren(...steps.map(step => h('li', {}, `${step.ok ? '✓' : '✗'} ${step.text}`)))
|
|
877
|
+
$('steps').classList.remove('hidden')
|
|
878
|
+
}
|
|
879
|
+
$('toggle').addEventListener('click', async () => {
|
|
880
|
+
const enable = $('toggle').textContent === 'Turn on'
|
|
881
|
+
if (!enable && !confirm('Turn the plugin off? Claude Code stops showing the usage line and alarms until you turn it back on. Your settings are kept.')) return
|
|
882
|
+
$('toggle').disabled = true
|
|
883
|
+
try {
|
|
884
|
+
const result = await postJson('/api/plugin', { enabled: enable })
|
|
885
|
+
showSteps(result.steps)
|
|
886
|
+
renderPlugin(result.plugin)
|
|
887
|
+
toast(`${enable ? 'Turned on' : 'Turned off'}. Restart Claude Code to apply it.`)
|
|
888
|
+
} catch (error) {
|
|
889
|
+
$('toggle').disabled = false
|
|
890
|
+
toast(error.message, true)
|
|
891
|
+
}
|
|
892
|
+
})
|
|
893
|
+
$('uninstall').addEventListener('click', async () => {
|
|
894
|
+
const deleteData = $('delete-data').checked
|
|
895
|
+
const question = deleteData
|
|
896
|
+
? 'Uninstall and delete your settings and custom sounds? This cannot be undone.'
|
|
897
|
+
: 'Uninstall the plugin? Your settings are kept in case you come back.'
|
|
898
|
+
if (!confirm(question)) return
|
|
899
|
+
clearTimeout(saveTimer)
|
|
900
|
+
await saving
|
|
901
|
+
document.querySelectorAll('button, input, select, a.btn').forEach(el => { el.disabled = true; el.setAttribute('aria-disabled', 'true') })
|
|
902
|
+
try {
|
|
903
|
+
const { steps } = await postJson('/api/uninstall', { deleteData })
|
|
904
|
+
showSteps(steps)
|
|
905
|
+
toast(steps.every(step => step.ok) ? 'Uninstalled. You can close this tab.' : 'Finished with errors, see the danger zone.', !steps.every(step => step.ok))
|
|
906
|
+
} catch (error) {
|
|
907
|
+
toast(`Uninstall failed: ${error.message}`, true)
|
|
908
|
+
}
|
|
909
|
+
})
|
|
910
|
+
$('done').addEventListener('click', async () => {
|
|
911
|
+
clearTimeout(saveTimer)
|
|
912
|
+
save()
|
|
913
|
+
await saving
|
|
914
|
+
if ((await syncNow()) === 'conflict') return toast('Choose which alarm settings to keep first.', true)
|
|
915
|
+
try { await postJson('/api/close') } catch {}
|
|
916
|
+
document.querySelectorAll('button, input, select').forEach(el => { el.disabled = true })
|
|
917
|
+
toast('Closed. You can close this tab.')
|
|
918
|
+
})
|
|
919
|
+
|
|
920
|
+
// --- Line settings ------------------------------------------------------------
|
|
921
|
+
for (const radio of document.querySelectorAll('input[name=spinner]')) {
|
|
922
|
+
radio.addEventListener('change', () => { config.line.spinner = radio.value; changed({ rerender: false }) })
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// --- Break reminders ------------------------------------------------------------
|
|
926
|
+
function renderBreaks() {
|
|
927
|
+
const open = limits().breakReminders === true
|
|
928
|
+
const breaks = config.breaks
|
|
929
|
+
$('breaks').classList.toggle('hidden', !open)
|
|
930
|
+
$('breaks-locked').classList.toggle('hidden', open)
|
|
931
|
+
$('breaks').classList.toggle('off', !breaks.enabled)
|
|
932
|
+
$('breaks-copy').textContent = `Every ${breaks.minutes} min of non-stop work, a nudge to stretch and drink water.`
|
|
933
|
+
$('breaks-enabled').checked = breaks.enabled
|
|
934
|
+
$('breaks-minutes').value = breaks.minutes
|
|
935
|
+
$('breaks-minutes-out').textContent = breaks.minutes
|
|
936
|
+
$('breaks-minutes').setAttribute('aria-valuetext', `${breaks.minutes} minutes`)
|
|
937
|
+
$('breaks-sound').replaceChildren(
|
|
938
|
+
...state.builtInSounds.map(name => h('option', { value: name }, `${SOUNDS[name]?.[0] ?? '🔊'} ${SOUNDS[name]?.[1] ?? name}`)),
|
|
939
|
+
h('option', { value: 'none' }, '🔇 No sound'),
|
|
940
|
+
)
|
|
941
|
+
$('breaks-sound').value = breaks.sound
|
|
942
|
+
hoursDraft = (breaks.hours ?? []).map(block => ({ ...block }))
|
|
943
|
+
renderHours()
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// Break hours: reminders come only inside these time blocks; none means any
|
|
947
|
+
// time. The same rule as the computers use (packages/config): each block ends
|
|
948
|
+
// after it starts, a 00:00 end means midnight, and blocks may touch but not
|
|
949
|
+
// overlap. Edits stay here until they make sense, then save.
|
|
950
|
+
let hoursDraft = []
|
|
951
|
+
const minutesOf = clock => Number(clock.slice(0, 2)) * 60 + Number(clock.slice(3))
|
|
952
|
+
const endOf = clock => (clock === '00:00' ? 24 * 60 : minutesOf(clock))
|
|
953
|
+
const shown = clock => (clock === '00:00' ? 'midnight' : clock)
|
|
954
|
+
const MAX_BREAK_HOURS = 8
|
|
955
|
+
|
|
956
|
+
function hoursProblem(hours) {
|
|
957
|
+
for (const block of hours) {
|
|
958
|
+
if (!/^\d\d:\d\d$/.test(block.from) || !/^\d\d:\d\d$/.test(block.to)) return { block, message: 'Each time block needs a start and an end.' }
|
|
959
|
+
if (endOf(block.to) <= minutesOf(block.from)) return { block, message: `${block.from} to ${shown(block.to)}: the end must come after the start.` }
|
|
960
|
+
}
|
|
961
|
+
const sorted = [...hours].sort((a, b) => minutesOf(a.from) - minutesOf(b.from))
|
|
962
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
963
|
+
const [before, block] = [sorted[i - 1], sorted[i]]
|
|
964
|
+
if (minutesOf(block.from) < endOf(before.to)) return { block, message: `${before.from}-${shown(before.to)} and ${block.from}-${shown(block.to)} overlap.` }
|
|
965
|
+
}
|
|
966
|
+
return undefined
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// Shows what is wrong, or saves the blocks when nothing is.
|
|
970
|
+
function hoursChanged() {
|
|
971
|
+
const problem = hoursProblem(hoursDraft)
|
|
972
|
+
for (const row of $('hours-list').children) row.classList.toggle('invalid', row.block === problem?.block)
|
|
973
|
+
$('hours-note').textContent = problem
|
|
974
|
+
? `Not saved: ${problem.message}`
|
|
975
|
+
: hoursDraft.length ? 'Only inside these times. Outside them: no break sounds.' : 'No time blocks: reminders can come any time you work.'
|
|
976
|
+
$('hours-note').classList.toggle('error', Boolean(problem))
|
|
977
|
+
$('hours-add').disabled = hoursDraft.length >= MAX_BREAK_HOURS
|
|
978
|
+
return problem
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
function saveHours() {
|
|
982
|
+
if (hoursChanged()) return
|
|
983
|
+
const hours = [...hoursDraft].sort((a, b) => minutesOf(a.from) - minutesOf(b.from)).map(block => ({ ...block }))
|
|
984
|
+
if (hours.length) config.breaks.hours = hours
|
|
985
|
+
else delete config.breaks.hours
|
|
986
|
+
changed({ rerender: false })
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function renderHours() {
|
|
990
|
+
$('hours-list').replaceChildren(...hoursDraft.map(block => {
|
|
991
|
+
const time = (field, label) => {
|
|
992
|
+
const input = h('input', { type: 'time', value: block[field], 'aria-label': label })
|
|
993
|
+
input.addEventListener('change', () => { block[field] = input.value; saveHours() })
|
|
994
|
+
return input
|
|
995
|
+
}
|
|
996
|
+
const row = h('li', {},
|
|
997
|
+
h('label', {}, 'From ', time('from', 'Start')),
|
|
998
|
+
h('label', {}, 'to ', time('to', 'End (00:00 is midnight)')),
|
|
999
|
+
h('button', { class: 'btn quiet', type: 'button', onclick: () => { hoursDraft.splice(hoursDraft.indexOf(block), 1); renderHours(); saveHours() } }, 'Remove'),
|
|
1000
|
+
)
|
|
1001
|
+
row.block = block
|
|
1002
|
+
return row
|
|
1003
|
+
}))
|
|
1004
|
+
hoursChanged()
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
$('hours-add').addEventListener('click', () => {
|
|
1008
|
+
// Starts where the latest block ends, two hours long, or 09:00-17:00.
|
|
1009
|
+
const last = hoursDraft.reduce((latest, block) => (!latest || endOf(block.to) > endOf(latest.to) ? block : latest), undefined)
|
|
1010
|
+
const start = last && endOf(last.to) <= 22 * 60 ? endOf(last.to) : undefined
|
|
1011
|
+
const clock = minutes => `${String(Math.floor(minutes / 60) % 24).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`
|
|
1012
|
+
hoursDraft.push(start === undefined ? { from: '09:00', to: '17:00' } : { from: clock(start), to: clock(start + 120) })
|
|
1013
|
+
renderHours()
|
|
1014
|
+
saveHours()
|
|
1015
|
+
})
|
|
1016
|
+
|
|
1017
|
+
$('breaks-enabled').addEventListener('change', event => { config.breaks.enabled = event.target.checked; renderBreaks(); changed({ rerender: false }) })
|
|
1018
|
+
$('breaks-minutes').addEventListener('input', event => {
|
|
1019
|
+
config.breaks.minutes = Number(event.target.value)
|
|
1020
|
+
$('breaks-minutes-out').textContent = config.breaks.minutes
|
|
1021
|
+
$('breaks-copy').textContent = `Every ${config.breaks.minutes} min of non-stop work, a nudge to stretch and drink water.`
|
|
1022
|
+
event.target.setAttribute('aria-valuetext', `${config.breaks.minutes} minutes`)
|
|
1023
|
+
changed({ rerender: false })
|
|
1024
|
+
})
|
|
1025
|
+
$('breaks-sound').addEventListener('change', event => { config.breaks.sound = event.target.value; changed({ rerender: false }) })
|
|
1026
|
+
$('breaks-test').addEventListener('click', () => play(config.breaks.sound))
|
|
1027
|
+
|
|
1028
|
+
// --- Phone alerts -------------------------------------------------------------
|
|
1029
|
+
function renderPhone() {
|
|
1030
|
+
const open = limits().phonePush === true
|
|
1031
|
+
$('phone').classList.toggle('hidden', !open)
|
|
1032
|
+
$('phone-locked').classList.toggle('hidden', open)
|
|
1033
|
+
$('phone-enabled').checked = config.phone?.enabled === true
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
$('phone-enabled').addEventListener('change', event => {
|
|
1037
|
+
if (event.target.checked) config.phone = { enabled: true }
|
|
1038
|
+
else delete config.phone
|
|
1039
|
+
changed({ rerender: false })
|
|
1040
|
+
})
|
|
1041
|
+
|
|
1042
|
+
function render() {
|
|
1043
|
+
renderAlarms()
|
|
1044
|
+
renderBreaks()
|
|
1045
|
+
renderPhone()
|
|
1046
|
+
renderSounds()
|
|
1047
|
+
for (const radio of document.querySelectorAll('input[name=spinner]')) radio.checked = radio.value === config.line.spinner
|
|
1048
|
+
renderPreview()
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
async function load() {
|
|
1052
|
+
try {
|
|
1053
|
+
state = await api('/api/state')
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
$('account').replaceChildren(h('p', { role: 'alert' }, `Could not load your settings: ${error.message}. Run __COMMAND__ config again.`))
|
|
1056
|
+
return
|
|
1057
|
+
}
|
|
1058
|
+
config = state.config
|
|
1059
|
+
document.title = `${state.product} settings`
|
|
1060
|
+
$('product').textContent = state.product
|
|
1061
|
+
$('path').textContent = state.configPath
|
|
1062
|
+
$('upgrade-sounds').href = state.links.buy
|
|
1063
|
+
$('upgrade-breaks').href = state.links.buy
|
|
1064
|
+
$('upgrade-phone').href = state.links.buy
|
|
1065
|
+
$('phone-setup').href = state.links.manage
|
|
1066
|
+
$('add-sounds').href = state.links.manage
|
|
1067
|
+
|
|
1068
|
+
const notes = []
|
|
1069
|
+
if (state.error) notes.push(`${state.error}. Showing the defaults; your next change replaces the file.`)
|
|
1070
|
+
if (state.hidden.alarms > 0) notes.push(`${state.hidden.alarms} alarm(s) are past your plan's limits and are hidden. Your next change removes them.`)
|
|
1071
|
+
if (state.hidden.customSounds > 0) notes.push(`${state.hidden.customSounds} custom sound(s) need a paid plan and are hidden. Your next change removes them.`)
|
|
1072
|
+
$('notice').textContent = notes.join(' ')
|
|
1073
|
+
$('notice').classList.toggle('hidden', !notes.length)
|
|
1074
|
+
|
|
1075
|
+
renderAccount()
|
|
1076
|
+
renderPlugin(state.plugin)
|
|
1077
|
+
render()
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
load()
|
|
1081
|
+
</script>
|
|
1082
|
+
</body>
|
|
1083
|
+
</html>
|