Umer359 Claude Sonnet 5 commited on
Commit
5f7bcb0
·
1 Parent(s): 53461af

Add persistent conversations, sidebar, export, PWA support, keyboard shortcuts, and an accessibility pass

Browse files

- Conversations now persist to localStorage per-thread and survive reload/crash
- New sidebar lists saved chats (switch, delete); font-size (A-/A+) and
export-as-text/PDF (jsPDF) live in its footer
- Copy button added to user messages too (bot replies already had one)
- Cmd/Ctrl+K focuses the composer, Esc clears a draft or closes the sidebar
- PWA: manifest.json + a narrow offline app-shell service worker (never
touches the chat API or CDN libraries) + generated app icons, so Nox is
installable via "Add to Home Screen"
- Accessibility: aria-live on the thread, dialog role + focus handling on
the sidebar, visible focus rings, and a text-size control

All client-side/localStorage — no worker changes, zero Neuron cost.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016b3u4n81zwJ6rpE9NeCokb

Files changed (7) hide show
  1. apple-touch-icon.png +0 -0
  2. icon-192.png +0 -0
  3. icon-512-maskable.png +0 -0
  4. icon-512.png +0 -0
  5. index.html +459 -5
  6. manifest.json +15 -0
  7. sw.js +51 -0
apple-touch-icon.png ADDED
icon-192.png ADDED
icon-512-maskable.png ADDED
icon-512.png ADDED
index.html CHANGED
@@ -21,6 +21,12 @@
21
  <meta name="twitter:title" content="Nox — by Devseis" />
22
  <meta name="twitter:description" content="A free AI assistant by Devseis. Ask anything, or attach an image or document." />
23
  <meta name="twitter:image" content="https://devseis-nox.static.hf.space/devseis-logo.png" />
 
 
 
 
 
 
24
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
25
  <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
26
  <!-- Code blocks are always rendered dark (see .bubble.markdown pre code below), so this
@@ -49,13 +55,19 @@
49
  --bg:#0b0e14; --panel:#11151d; --border:#232a37; --text:#e8ecf4; --muted:#8b94a7;
50
  --accent:#ff914d; --accent-text:#1a1006; --accent-soft:rgba(255,145,77,.16); --accent-border:rgba(255,145,77,.4); --bubble-bot:#161c27;
51
  --input-bg:#2c323d;
 
52
  }
53
  *{box-sizing:border-box;}
 
 
54
  html,body{height:100%;}
55
  body{margin:0;background:var(--bg);color:var(--text);font-family:"Space Grotesk",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;height:100vh;height:100dvh;display:flex;flex-direction:column;overflow:hidden;}
56
  header{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 20px;padding-top:calc(14px + env(safe-area-inset-top));border-bottom:1px solid var(--border);background:var(--panel);flex-shrink:0;}
 
57
  .new-chat-btn{background:transparent;color:var(--text);border:1px solid var(--border);border-radius:8px;padding:0 14px;height:34px;font-size:13px;font-weight:600;cursor:pointer;}
58
  .new-chat-btn:hover{background:var(--bg);}
 
 
59
  .header-actions{display:flex;align-items:center;gap:8px;}
60
  .theme-btn{width:28px;height:28px;min-height:auto;border-radius:50%;padding:0;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center;background:transparent;border:1.5px solid var(--border);cursor:pointer;color:var(--text);}
61
  .theme-btn:hover{background:var(--bg);border-color:var(--accent);}
@@ -83,7 +95,7 @@
83
  .msg.user{justify-content:flex-end;}
84
  .msg.bot{gap:8px;align-items:flex-end;}
85
  .avatar{width:26px;height:26px;border-radius:50%;background:var(--accent-soft);display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;}
86
- .bubble{max-width:75%;padding:11px 16px;border-radius:20px;line-height:1.5;font-size:15px;font-weight:500;white-space:pre-wrap;transition:background-color .15s;}
87
  .msg.user .bubble{background:var(--accent-soft);border:1px solid var(--accent-border);border-bottom-right-radius:6px;}
88
  .msg.bot .bubble{background:var(--bubble-bot);border-bottom-left-radius:6px;}
89
  .typing-dots{display:inline-flex;gap:5px;align-items:center;padding:6px 2px;}
@@ -99,6 +111,7 @@
99
  .msg-action-btn{background:transparent;border:none;color:var(--muted);font-size:13.5px;padding:5px 7px;border-radius:7px;cursor:pointer;min-height:auto;font-family:inherit;opacity:.6;transition:opacity .15s,background-color .15s;line-height:1;}
100
  .msg-action-btn:hover{opacity:1;background:rgba(127,127,127,.14);}
101
  .msg-action-btn.active{opacity:1;background:rgba(127,127,127,.14);}
 
102
  .bubble.markdown{white-space:normal;}
103
  .bubble.markdown p{margin:0 0 8px;}
104
  .bubble.markdown p:last-child{margin-bottom:0;}
@@ -126,6 +139,27 @@
126
  .cap-banner .cap-title{font-weight:700;font-size:13.5px;}
127
  .cap-banner .cap-sub{color:var(--muted);font-size:12.5px;}
128
  .cap-banner .cap-countdown{font-weight:700;color:var(--accent);font-variant-numeric:tabular-nums;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  .modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:1000;padding:20px;padding:20px env(safe-area-inset-right) calc(20px + env(safe-area-inset-bottom)) env(safe-area-inset-left);}
130
  .modal-box{background:var(--panel);border:1px solid var(--border);border-radius:20px;padding:32px 28px;max-width:360px;width:100%;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.35);animation:modal-in .22s ease-out;}
131
  @keyframes modal-in{from{opacity:0;transform:scale(.94) translateY(8px);}to{opacity:1;transform:scale(1) translateY(0);}}
@@ -160,7 +194,10 @@
160
  </head>
161
  <body>
162
  <header>
163
- <button type="button" id="newChat" class="new-chat-btn">New chat</button>
 
 
 
164
  <div class="header-actions">
165
  <button type="button" id="themeToggle" class="theme-btn" title="Toggle theme" aria-label="Toggle theme">🌙</button>
166
  <div class="lang-flags" id="langFlags">
@@ -184,8 +221,32 @@
184
  <button type="button" class="chip" data-prompt="Catch me up on today's news.">📰 Today's news</button>
185
  </div>
186
  </div>
187
- <div id="thread" style="display:none;"></div>
188
  </main>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  <div class="modal-overlay" id="capModalOverlay" style="display:none;" role="dialog" aria-modal="true">
190
  <div class="modal-box">
191
  <div class="modal-emoji" id="modalEmoji">🌙</div>
@@ -222,6 +283,7 @@
222
  <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/18.0.12/lib/marked.umd.min.js"></script>
223
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.4.15/purify.min.js"></script>
224
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/highlight.min.js"></script>
 
225
  <!--
226
  pdf.js was previously loaded as an ES module (`<script type="module">` +
227
  dynamic import()), which loads in the background — on a slow mobile
@@ -344,6 +406,28 @@ function createFeedbackRow(replyText, userMessageText) {
344
  return wrap;
345
  }
346
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  const thread = document.getElementById('thread');
348
  const chatMain = document.getElementById('chatMain');
349
 
@@ -390,6 +474,18 @@ const modalTitleEl = document.getElementById('modalTitle');
390
  const modalSubEl = document.getElementById('modalSub');
391
  const modalCountdownEl = document.getElementById('modalCountdown');
392
  const modalOkBtn = document.getElementById('modalOkBtn');
 
 
 
 
 
 
 
 
 
 
 
 
393
 
394
  const MAX_ATTACHMENT_BYTES = 4 * 1024 * 1024; // 4MB
395
  const MAX_DOC_CHARS = 12000;
@@ -508,6 +604,12 @@ const TRANSLATIONS = {
508
  capTitleNeurons: "Nox is at capacity right now",
509
  capSubNeurons: "Should free up in approximately",
510
  capPlaceholder: "Nox is resting — come back after the reset 🌙",
 
 
 
 
 
 
511
  },
512
  fr: {
513
  heroTitle: "🌙 Salut, je suis Nox.",
@@ -533,6 +635,12 @@ const TRANSLATIONS = {
533
  capTitleNeurons: "Nox est à pleine capacité pour le moment",
534
  capSubNeurons: "Devrait se libérer dans environ",
535
  capPlaceholder: "Nox se repose — reviens après la réinitialisation 🌙",
 
 
 
 
 
 
536
  },
537
  de: {
538
  heroTitle: "🌙 Hallo, ich bin Nox.",
@@ -558,6 +666,12 @@ const TRANSLATIONS = {
558
  capTitleNeurons: "Nox ist gerade ausgelastet",
559
  capSubNeurons: "Sollte in etwa wieder frei sein in",
560
  capPlaceholder: "Nox macht Pause — komm nach dem Reset wieder 🌙",
 
 
 
 
 
 
561
  },
562
  lb: {
563
  heroTitle: "🌙 Moien, ech sinn den Nox.",
@@ -583,6 +697,12 @@ const TRANSLATIONS = {
583
  capTitleNeurons: "Den Nox ass am Moment ausgelaascht",
584
  capSubNeurons: "Sollt an ongeféier erëm fräi sinn an",
585
  capPlaceholder: "Nox rout — kommt nom Reset zréck 🌙",
 
 
 
 
 
 
586
  },
587
  pt: {
588
  heroTitle: "🌙 Olá, sou o Nox.",
@@ -608,6 +728,12 @@ const TRANSLATIONS = {
608
  capTitleNeurons: "O Nox está no limite de capacidade agora",
609
  capSubNeurons: "Deve ficar disponível novamente em aproximadamente",
610
  capPlaceholder: "O Nox está a descansar — volta depois do reset 🌙",
 
 
 
 
 
 
611
  },
612
  };
613
 
@@ -705,6 +831,13 @@ function applyLanguage(lang) {
705
  themeToggleBtn.title = t.themeToggleTitle;
706
  themeToggleBtn.setAttribute('aria-label', t.themeToggleTitle);
707
  }
 
 
 
 
 
 
 
708
  const privacyLink = document.getElementById('footerPrivacyLink');
709
  if (privacyLink) privacyLink.textContent = t.privacyLink;
710
  const poweredByEl = document.getElementById('footerPoweredBy');
@@ -716,6 +849,7 @@ function applyLanguage(lang) {
716
 
717
  try { localStorage.setItem('noxLang', currentLang); } catch {}
718
  renderStatusBar();
 
719
  if (capBanner.style.display !== 'none' && currentResetKind) showResetBanner(currentResetKind);
720
  if (history.length) history[0] = { role: 'system', content: buildSystemPrompt() };
721
  }
@@ -726,6 +860,298 @@ document.querySelectorAll('.flag-btn').forEach((btn) => {
726
 
727
  let history = [{ role: "system", content: buildSystemPrompt() }];
728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  function showEmptyState() {
730
  emptyState.style.display = 'flex';
731
  thread.style.display = 'none';
@@ -912,11 +1338,14 @@ async function fetchStats() {
912
 
913
  function startNewChat() {
914
  history = [{ role: "system", content: buildSystemPrompt() }];
 
 
915
  thread.innerHTML = '';
916
  showEmptyState();
917
  input.value = '';
918
  input.style.height = 'auto';
919
  input.focus();
 
920
  }
921
 
922
  newChatBtn.addEventListener('click', startNewChat);
@@ -1066,6 +1495,7 @@ async function requestReply(imageBase64) {
1066
  finishReason = result.finishReason;
1067
  }
1068
  history.push({ role: 'assistant', content: reply });
 
1069
  loadingBubble.parentElement.after(createFeedbackRow(reply, userMessageText));
1070
  scrollToBottom();
1071
  fetchStats();
@@ -1092,6 +1522,7 @@ async function requestReply(imageBase64) {
1092
  loadingBubble.innerHTML = renderMarkdown(reply);
1093
  enhanceCodeBlocks(loadingBubble);
1094
  history.push({ role: 'assistant', content: reply });
 
1095
  loadingBubble.parentElement.after(createFeedbackRow(reply, userMessageText));
1096
  updateGlobalUsage(data.usage);
1097
  scrollToBottom();
@@ -1130,8 +1561,10 @@ form.addEventListener('submit', async (e) => {
1130
  const imageToSend = pendingImage ? pendingImage.base64 : null;
1131
  clearAttachment();
1132
 
1133
- addMessage('user', displayText);
 
1134
  history.push({ role: 'user', content: messageContent });
 
1135
 
1136
  await requestReply(imageToSend);
1137
  if (!lastUsage || lastUsage.used < lastUsage.cap) {
@@ -1141,9 +1574,30 @@ form.addEventListener('submit', async (e) => {
1141
  }
1142
  });
1143
 
1144
- startNewChat();
 
 
 
 
 
 
 
 
 
 
 
 
 
1145
  applyLanguage(currentLang);
 
 
1146
  fetchStats();
 
 
 
 
 
 
1147
  </script>
1148
  </body>
1149
  </html>
 
21
  <meta name="twitter:title" content="Nox — by Devseis" />
22
  <meta name="twitter:description" content="A free AI assistant by Devseis. Ask anything, or attach an image or document." />
23
  <meta name="twitter:image" content="https://devseis-nox.static.hf.space/devseis-logo.png" />
24
+ <link rel="manifest" href="manifest.json" />
25
+ <meta name="theme-color" content="#0b0e14" />
26
+ <link rel="apple-touch-icon" href="apple-touch-icon.png" />
27
+ <link rel="icon" href="icon-192.png" />
28
+ <meta name="apple-mobile-web-app-capable" content="yes" />
29
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
30
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
31
  <link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
32
  <!-- Code blocks are always rendered dark (see .bubble.markdown pre code below), so this
 
55
  --bg:#0b0e14; --panel:#11151d; --border:#232a37; --text:#e8ecf4; --muted:#8b94a7;
56
  --accent:#ff914d; --accent-text:#1a1006; --accent-soft:rgba(255,145,77,.16); --accent-border:rgba(255,145,77,.4); --bubble-bot:#161c27;
57
  --input-bg:#2c323d;
58
+ --msg-font-size:15px;
59
  }
60
  *{box-sizing:border-box;}
61
+ button:focus-visible, a:focus-visible, .chip:focus-visible, .convo-row:focus-visible{outline:2px solid var(--accent);outline-offset:2px;}
62
+ .input-pill:focus-within{box-shadow:0 0 0 2px var(--accent-border);}
63
  html,body{height:100%;}
64
  body{margin:0;background:var(--bg);color:var(--text);font-family:"Space Grotesk",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;height:100vh;height:100dvh;display:flex;flex-direction:column;overflow:hidden;}
65
  header{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 20px;padding-top:calc(14px + env(safe-area-inset-top));border-bottom:1px solid var(--border);background:var(--panel);flex-shrink:0;}
66
+ .header-left{display:flex;align-items:center;gap:8px;}
67
  .new-chat-btn{background:transparent;color:var(--text);border:1px solid var(--border);border-radius:8px;padding:0 14px;height:34px;font-size:13px;font-weight:600;cursor:pointer;}
68
  .new-chat-btn:hover{background:var(--bg);}
69
+ .sidebar-toggle-btn{width:34px;height:34px;min-height:auto;border-radius:8px;padding:0;display:flex;align-items:center;justify-content:center;background:transparent;border:1px solid var(--border);color:var(--text);cursor:pointer;font-size:15px;}
70
+ .sidebar-toggle-btn:hover{background:var(--bg);}
71
  .header-actions{display:flex;align-items:center;gap:8px;}
72
  .theme-btn{width:28px;height:28px;min-height:auto;border-radius:50%;padding:0;font-size:14px;line-height:1;display:flex;align-items:center;justify-content:center;background:transparent;border:1.5px solid var(--border);cursor:pointer;color:var(--text);}
73
  .theme-btn:hover{background:var(--bg);border-color:var(--accent);}
 
95
  .msg.user{justify-content:flex-end;}
96
  .msg.bot{gap:8px;align-items:flex-end;}
97
  .avatar{width:26px;height:26px;border-radius:50%;background:var(--accent-soft);display:flex;align-items:center;justify-content:center;font-size:14px;flex-shrink:0;}
98
+ .bubble{max-width:75%;padding:11px 16px;border-radius:20px;line-height:1.5;font-size:var(--msg-font-size);font-weight:500;white-space:pre-wrap;transition:background-color .15s;}
99
  .msg.user .bubble{background:var(--accent-soft);border:1px solid var(--accent-border);border-bottom-right-radius:6px;}
100
  .msg.bot .bubble{background:var(--bubble-bot);border-bottom-left-radius:6px;}
101
  .typing-dots{display:inline-flex;gap:5px;align-items:center;padding:6px 2px;}
 
111
  .msg-action-btn{background:transparent;border:none;color:var(--muted);font-size:13.5px;padding:5px 7px;border-radius:7px;cursor:pointer;min-height:auto;font-family:inherit;opacity:.6;transition:opacity .15s,background-color .15s;line-height:1;}
112
  .msg-action-btn:hover{opacity:1;background:rgba(127,127,127,.14);}
113
  .msg-action-btn.active{opacity:1;background:rgba(127,127,127,.14);}
114
+ .msg-actions.user-actions{margin:-6px 0 10px 0;justify-content:flex-end;}
115
  .bubble.markdown{white-space:normal;}
116
  .bubble.markdown p{margin:0 0 8px;}
117
  .bubble.markdown p:last-child{margin-bottom:0;}
 
139
  .cap-banner .cap-title{font-weight:700;font-size:13.5px;}
140
  .cap-banner .cap-sub{color:var(--muted);font-size:12.5px;}
141
  .cap-banner .cap-countdown{font-weight:700;color:var(--accent);font-variant-numeric:tabular-nums;}
142
+ .sidebar-overlay{position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:900;}
143
+ .sidebar{position:fixed;top:0;left:0;bottom:0;width:280px;max-width:82vw;background:var(--panel);border-right:1px solid var(--border);z-index:901;display:flex;flex-direction:column;box-shadow:8px 0 24px rgba(0,0,0,.25);animation:sidebar-in .2s ease-out;padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom);}
144
+ @keyframes sidebar-in{from{transform:translateX(-100%);}to{transform:translateX(0);}}
145
+ .sidebar-header{display:flex;align-items:center;justify-content:space-between;padding:16px 16px 10px;flex-shrink:0;}
146
+ .sidebar-header h2{margin:0;font-size:16px;font-weight:700;}
147
+ .sidebar-close-btn{background:transparent;border:none;color:var(--muted);font-size:18px;cursor:pointer;padding:4px 8px;min-height:auto;line-height:1;}
148
+ .sidebar-close-btn:hover{color:var(--text);}
149
+ .sidebar-list{flex:1;overflow-y:auto;padding:4px 10px;min-height:0;}
150
+ .sidebar-empty{color:var(--muted);font-size:13px;padding:20px 12px;text-align:center;line-height:1.5;}
151
+ .convo-row{display:flex;align-items:center;gap:4px;padding:10px 10px;border-radius:10px;cursor:pointer;margin-bottom:2px;}
152
+ .convo-row:hover{background:var(--bg);}
153
+ .convo-row.active{background:var(--accent-soft);}
154
+ .convo-title{flex:1;font-size:13.5px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
155
+ .convo-delete{background:transparent;border:none;color:var(--muted);font-size:14px;cursor:pointer;padding:4px 7px;min-height:auto;border-radius:6px;opacity:.6;}
156
+ .convo-delete:hover{opacity:1;background:rgba(224,82,82,.15);color:#e05252;}
157
+ .sidebar-footer{border-top:1px solid var(--border);padding:12px 16px;display:flex;flex-direction:column;gap:10px;flex-shrink:0;}
158
+ .sidebar-footer-row{display:flex;align-items:center;justify-content:space-between;gap:8px;}
159
+ .sidebar-footer-row span{font-size:12px;color:var(--muted);font-weight:600;}
160
+ .sidebar-footer-row .btn-group{display:flex;gap:4px;}
161
+ .sidebar-footer .small-btn{background:var(--bg);border:1px solid var(--border);color:var(--text);border-radius:8px;padding:5px 10px;font-size:12px;font-weight:600;cursor:pointer;min-height:auto;font-family:inherit;}
162
+ .sidebar-footer .small-btn:hover{border-color:var(--accent);}
163
  .modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);display:flex;align-items:center;justify-content:center;z-index:1000;padding:20px;padding:20px env(safe-area-inset-right) calc(20px + env(safe-area-inset-bottom)) env(safe-area-inset-left);}
164
  .modal-box{background:var(--panel);border:1px solid var(--border);border-radius:20px;padding:32px 28px;max-width:360px;width:100%;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.35);animation:modal-in .22s ease-out;}
165
  @keyframes modal-in{from{opacity:0;transform:scale(.94) translateY(8px);}to{opacity:1;transform:scale(1) translateY(0);}}
 
194
  </head>
195
  <body>
196
  <header>
197
+ <div class="header-left">
198
+ <button type="button" id="sidebarToggle" class="sidebar-toggle-btn" title="Saved chats" aria-label="Saved chats" aria-haspopup="dialog">☰</button>
199
+ <button type="button" id="newChat" class="new-chat-btn">New chat</button>
200
+ </div>
201
  <div class="header-actions">
202
  <button type="button" id="themeToggle" class="theme-btn" title="Toggle theme" aria-label="Toggle theme">🌙</button>
203
  <div class="lang-flags" id="langFlags">
 
221
  <button type="button" class="chip" data-prompt="Catch me up on today's news.">📰 Today's news</button>
222
  </div>
223
  </div>
224
+ <div id="thread" style="display:none;" aria-live="polite" role="log"></div>
225
  </main>
226
+ <div class="sidebar-overlay" id="sidebarOverlay" style="display:none;"></div>
227
+ <aside class="sidebar" id="sidebar" role="dialog" aria-modal="true" aria-label="Saved chats" style="display:none;">
228
+ <div class="sidebar-header">
229
+ <h2 id="sidebarTitle">Chats</h2>
230
+ <button type="button" id="sidebarClose" class="sidebar-close-btn" aria-label="Close">✕</button>
231
+ </div>
232
+ <div class="sidebar-list" id="sidebarList"></div>
233
+ <div class="sidebar-footer">
234
+ <div class="sidebar-footer-row">
235
+ <span id="fontSizeLabel">Text size</span>
236
+ <div class="btn-group">
237
+ <button type="button" id="fontSizeDown" class="small-btn" aria-label="Smaller text">A−</button>
238
+ <button type="button" id="fontSizeUp" class="small-btn" aria-label="Larger text">A+</button>
239
+ </div>
240
+ </div>
241
+ <div class="sidebar-footer-row">
242
+ <span id="exportLabel">Export this chat</span>
243
+ <div class="btn-group">
244
+ <button type="button" id="exportTextBtn" class="small-btn">Text</button>
245
+ <button type="button" id="exportPdfBtn" class="small-btn">PDF</button>
246
+ </div>
247
+ </div>
248
+ </div>
249
+ </aside>
250
  <div class="modal-overlay" id="capModalOverlay" style="display:none;" role="dialog" aria-modal="true">
251
  <div class="modal-box">
252
  <div class="modal-emoji" id="modalEmoji">🌙</div>
 
283
  <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/18.0.12/lib/marked.umd.min.js"></script>
284
  <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.4.15/purify.min.js"></script>
285
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/highlight.min.js"></script>
286
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
287
  <!--
288
  pdf.js was previously loaded as an ES module (`<script type="module">` +
289
  dynamic import()), which loads in the background — on a slow mobile
 
406
  return wrap;
407
  }
408
 
409
+ // Same copy affordance as createFeedbackRow but for a USER message — no
410
+ // thumbs (rating your own message doesn't mean anything), right-aligned to
411
+ // sit under the right-aligned user bubble via the .user-actions modifier.
412
+ function createCopyOnlyRow(text) {
413
+ const wrap = document.createElement('div');
414
+ wrap.className = 'msg-actions user-actions';
415
+ const copyBtn = document.createElement('button');
416
+ copyBtn.type = 'button';
417
+ copyBtn.className = 'msg-action-btn';
418
+ copyBtn.title = 'Copy message';
419
+ copyBtn.setAttribute('aria-label', 'Copy message');
420
+ copyBtn.textContent = '📋';
421
+ copyBtn.addEventListener('click', () => {
422
+ navigator.clipboard.writeText(text).then(() => {
423
+ copyBtn.textContent = '✅';
424
+ setTimeout(() => { copyBtn.textContent = '📋'; }, 1200);
425
+ }).catch(() => {});
426
+ });
427
+ wrap.appendChild(copyBtn);
428
+ return wrap;
429
+ }
430
+
431
  const thread = document.getElementById('thread');
432
  const chatMain = document.getElementById('chatMain');
433
 
 
474
  const modalSubEl = document.getElementById('modalSub');
475
  const modalCountdownEl = document.getElementById('modalCountdown');
476
  const modalOkBtn = document.getElementById('modalOkBtn');
477
+ const sidebarToggleBtn = document.getElementById('sidebarToggle');
478
+ const sidebarEl = document.getElementById('sidebar');
479
+ const sidebarOverlayEl = document.getElementById('sidebarOverlay');
480
+ const sidebarCloseBtn = document.getElementById('sidebarClose');
481
+ const sidebarListEl = document.getElementById('sidebarList');
482
+ const sidebarTitleEl = document.getElementById('sidebarTitle');
483
+ const fontSizeLabelEl = document.getElementById('fontSizeLabel');
484
+ const fontSizeDownBtn = document.getElementById('fontSizeDown');
485
+ const fontSizeUpBtn = document.getElementById('fontSizeUp');
486
+ const exportLabelEl = document.getElementById('exportLabel');
487
+ const exportTextBtn = document.getElementById('exportTextBtn');
488
+ const exportPdfBtn = document.getElementById('exportPdfBtn');
489
 
490
  const MAX_ATTACHMENT_BYTES = 4 * 1024 * 1024; // 4MB
491
  const MAX_DOC_CHARS = 12000;
 
604
  capTitleNeurons: "Nox is at capacity right now",
605
  capSubNeurons: "Should free up in approximately",
606
  capPlaceholder: "Nox is resting — come back after the reset 🌙",
607
+ sidebarToggleTitle: "Saved chats",
608
+ sidebarTitle: "Chats",
609
+ sidebarEmpty: "No saved chats yet — start typing to save one here.",
610
+ fontSizeLabel: "Text size",
611
+ exportLabel: "Export this chat",
612
+ deleteChatTitle: "Delete chat",
613
  },
614
  fr: {
615
  heroTitle: "🌙 Salut, je suis Nox.",
 
635
  capTitleNeurons: "Nox est à pleine capacité pour le moment",
636
  capSubNeurons: "Devrait se libérer dans environ",
637
  capPlaceholder: "Nox se repose — reviens après la réinitialisation 🌙",
638
+ sidebarToggleTitle: "Discussions enregistrées",
639
+ sidebarTitle: "Discussions",
640
+ sidebarEmpty: "Aucune discussion enregistrée pour l'instant — écris un message pour en créer une.",
641
+ fontSizeLabel: "Taille du texte",
642
+ exportLabel: "Exporter cette discussion",
643
+ deleteChatTitle: "Supprimer la discussion",
644
  },
645
  de: {
646
  heroTitle: "🌙 Hallo, ich bin Nox.",
 
666
  capTitleNeurons: "Nox ist gerade ausgelastet",
667
  capSubNeurons: "Sollte in etwa wieder frei sein in",
668
  capPlaceholder: "Nox macht Pause — komm nach dem Reset wieder 🌙",
669
+ sidebarToggleTitle: "Gespeicherte Chats",
670
+ sidebarTitle: "Chats",
671
+ sidebarEmpty: "Noch keine gespeicherten Chats — schreib etwas, um hier einen zu speichern.",
672
+ fontSizeLabel: "Textgröße",
673
+ exportLabel: "Diesen Chat exportieren",
674
+ deleteChatTitle: "Chat löschen",
675
  },
676
  lb: {
677
  heroTitle: "🌙 Moien, ech sinn den Nox.",
 
697
  capTitleNeurons: "Den Nox ass am Moment ausgelaascht",
698
  capSubNeurons: "Sollt an ongeféier erëm fräi sinn an",
699
  capPlaceholder: "Nox rout — kommt nom Reset zréck 🌙",
700
+ sidebarToggleTitle: "Gespäichert Chats",
701
+ sidebarTitle: "Chats",
702
+ sidebarEmpty: "Nach keng gespäichert Chats — schreif eppes fir ee hei ze späicheren.",
703
+ fontSizeLabel: "Textgréisst",
704
+ exportLabel: "Dëse Chat exportéieren",
705
+ deleteChatTitle: "Chat läschen",
706
  },
707
  pt: {
708
  heroTitle: "🌙 Olá, sou o Nox.",
 
728
  capTitleNeurons: "O Nox está no limite de capacidade agora",
729
  capSubNeurons: "Deve ficar disponível novamente em aproximadamente",
730
  capPlaceholder: "O Nox está a descansar — volta depois do reset 🌙",
731
+ sidebarToggleTitle: "Conversas guardadas",
732
+ sidebarTitle: "Conversas",
733
+ sidebarEmpty: "Ainda não há conversas guardadas — escreve algo para guardar uma aqui.",
734
+ fontSizeLabel: "Tamanho do texto",
735
+ exportLabel: "Exportar esta conversa",
736
+ deleteChatTitle: "Eliminar conversa",
737
  },
738
  };
739
 
 
831
  themeToggleBtn.title = t.themeToggleTitle;
832
  themeToggleBtn.setAttribute('aria-label', t.themeToggleTitle);
833
  }
834
+ if (sidebarToggleBtn) {
835
+ sidebarToggleBtn.title = t.sidebarToggleTitle;
836
+ sidebarToggleBtn.setAttribute('aria-label', t.sidebarToggleTitle);
837
+ }
838
+ if (sidebarTitleEl) sidebarTitleEl.textContent = t.sidebarTitle;
839
+ if (fontSizeLabelEl) fontSizeLabelEl.textContent = t.fontSizeLabel;
840
+ if (exportLabelEl) exportLabelEl.textContent = t.exportLabel;
841
  const privacyLink = document.getElementById('footerPrivacyLink');
842
  if (privacyLink) privacyLink.textContent = t.privacyLink;
843
  const poweredByEl = document.getElementById('footerPoweredBy');
 
849
 
850
  try { localStorage.setItem('noxLang', currentLang); } catch {}
851
  renderStatusBar();
852
+ if (typeof renderSidebarList === 'function') renderSidebarList();
853
  if (capBanner.style.display !== 'none' && currentResetKind) showResetBanner(currentResetKind);
854
  if (history.length) history[0] = { role: 'system', content: buildSystemPrompt() };
855
  }
 
860
 
861
  let history = [{ role: "system", content: buildSystemPrompt() }];
862
 
863
+ // Every real conversation (one that has at least one message) is kept as
864
+ // its own entry in one localStorage object, keyed by a generated id — not
865
+ // serialized as one giant blob per save, so switching chats is just picking
866
+ // a different entry rather than re-parsing everything. A brand new "New
867
+ // chat" is NOT written here until its first message; an empty conversation
868
+ // nobody typed into isn't worth cluttering the sidebar with.
869
+ const CONVOS_KEY = 'noxConversations';
870
+ const ACTIVE_CONVO_KEY = 'noxActiveConvoId';
871
+ let activeConvoId = null;
872
+
873
+ function loadConversations() {
874
+ try {
875
+ const raw = localStorage.getItem(CONVOS_KEY);
876
+ const parsed = raw ? JSON.parse(raw) : {};
877
+ return (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) ? parsed : {};
878
+ } catch { return {}; }
879
+ }
880
+
881
+ function saveConversations(convos) {
882
+ try { localStorage.setItem(CONVOS_KEY, JSON.stringify(convos)); } catch {}
883
+ }
884
+
885
+ function getSavedActiveConvoId() {
886
+ try { return localStorage.getItem(ACTIVE_CONVO_KEY); } catch { return null; }
887
+ }
888
+
889
+ function setSavedActiveConvoId(id) {
890
+ try {
891
+ if (id) localStorage.setItem(ACTIVE_CONVO_KEY, id);
892
+ else localStorage.removeItem(ACTIVE_CONVO_KEY);
893
+ } catch {}
894
+ }
895
+
896
+ function makeConvoId() {
897
+ return 'c-' + (crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).slice(2));
898
+ }
899
+
900
+ function deriveConvoTitle(messages) {
901
+ const firstUser = messages.find((m) => m.role === 'user');
902
+ const raw = (firstUser?.content || '').replace(/\s+/g, ' ').trim();
903
+ if (!raw) return 'New chat';
904
+ return raw.length > 42 ? raw.slice(0, 42) + '…' : raw;
905
+ }
906
+
907
+ // Called after every user/assistant message lands in `history` — a single
908
+ // conversation's worth of JSON, not the whole store, so this stays cheap
909
+ // even with many saved chats. This is what makes a reload/crash/accidental
910
+ // tab close non-destructive: the exact `messages` array (system prompt
911
+ // excluded — that's rebuilt fresh from buildSystemPrompt() on load, so a
912
+ // later language or persona change applies to old chats too) is what gets
913
+ // restored.
914
+ function persistActiveConversation() {
915
+ const messages = history.filter((m) => m.role !== 'system');
916
+ if (!messages.length) return;
917
+ if (!activeConvoId) activeConvoId = makeConvoId();
918
+ const convos = loadConversations();
919
+ const existing = convos[activeConvoId];
920
+ convos[activeConvoId] = {
921
+ id: activeConvoId,
922
+ title: deriveConvoTitle(messages),
923
+ messages,
924
+ createdAt: existing?.createdAt || Date.now(),
925
+ updatedAt: Date.now(),
926
+ };
927
+ saveConversations(convos);
928
+ setSavedActiveConvoId(activeConvoId);
929
+ renderSidebarList();
930
+ }
931
+
932
+ function deleteConversation(id) {
933
+ const convos = loadConversations();
934
+ delete convos[id];
935
+ saveConversations(convos);
936
+ if (id === activeConvoId) {
937
+ startNewChat();
938
+ } else {
939
+ renderSidebarList();
940
+ }
941
+ }
942
+
943
+ function renderSidebarList() {
944
+ if (!sidebarListEl) return;
945
+ const t = TRANSLATIONS[currentLang] || TRANSLATIONS.en;
946
+ const convos = loadConversations();
947
+ const list = Object.values(convos).sort((a, b) => b.updatedAt - a.updatedAt);
948
+ sidebarListEl.innerHTML = '';
949
+ if (!list.length) {
950
+ const empty = document.createElement('div');
951
+ empty.className = 'sidebar-empty';
952
+ empty.textContent = t.sidebarEmpty;
953
+ sidebarListEl.appendChild(empty);
954
+ return;
955
+ }
956
+ list.forEach((c) => {
957
+ const row = document.createElement('div');
958
+ row.className = 'convo-row' + (c.id === activeConvoId ? ' active' : '');
959
+ row.tabIndex = 0;
960
+ row.setAttribute('role', 'button');
961
+ row.setAttribute('aria-label', c.title);
962
+
963
+ const title = document.createElement('div');
964
+ title.className = 'convo-title';
965
+ title.textContent = c.title;
966
+
967
+ const del = document.createElement('button');
968
+ del.type = 'button';
969
+ del.className = 'convo-delete';
970
+ del.title = t.deleteChatTitle;
971
+ del.setAttribute('aria-label', t.deleteChatTitle);
972
+ del.textContent = '🗑';
973
+ del.addEventListener('click', (e) => {
974
+ e.stopPropagation();
975
+ deleteConversation(c.id);
976
+ });
977
+
978
+ row.addEventListener('click', () => loadConversationById(c.id));
979
+ row.addEventListener('keydown', (e) => {
980
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); loadConversationById(c.id); }
981
+ });
982
+
983
+ row.append(title, del);
984
+ sidebarListEl.appendChild(row);
985
+ });
986
+ }
987
+
988
+ function loadConversationById(id) {
989
+ const convos = loadConversations();
990
+ const convo = convos[id];
991
+ if (!convo) return;
992
+ activeConvoId = id;
993
+ setSavedActiveConvoId(id);
994
+ history = [{ role: 'system', content: buildSystemPrompt() }, ...convo.messages];
995
+ renderThreadFromHistory();
996
+ closeSidebar();
997
+ }
998
+
999
+ // Rebuilds the visible thread DOM from `history` — used both when
1000
+ // restoring the last-open conversation on page load and when switching to
1001
+ // a different saved one from the sidebar. Bot replies get their code
1002
+ // blocks re-highlighted and a fresh copy/feedback row (a new vote from
1003
+ // this render doesn't carry over any previous vote's highlight state —
1004
+ // votes aren't persisted, only the messages are, which is an acceptable
1005
+ // simplification since the KV record of the original vote still exists
1006
+ // server-side).
1007
+ function renderThreadFromHistory() {
1008
+ thread.innerHTML = '';
1009
+ const messages = history.filter((m) => m.role !== 'system');
1010
+ if (!messages.length) {
1011
+ showEmptyState();
1012
+ return;
1013
+ }
1014
+ hideEmptyState();
1015
+ let lastUserText = '';
1016
+ messages.forEach((m) => {
1017
+ if (m.role === 'user') {
1018
+ lastUserText = m.content;
1019
+ const bubble = addMessage('user', m.content);
1020
+ bubble.parentElement.after(createCopyOnlyRow(m.content));
1021
+ } else if (m.role === 'assistant') {
1022
+ const bubble = addMessage('bot', '');
1023
+ bubble.classList.add('markdown');
1024
+ bubble.innerHTML = renderMarkdown(m.content);
1025
+ enhanceCodeBlocks(bubble);
1026
+ bubble.parentElement.after(createFeedbackRow(m.content, lastUserText));
1027
+ }
1028
+ });
1029
+ scrollToBottom();
1030
+ }
1031
+
1032
+ function openSidebar() {
1033
+ renderSidebarList();
1034
+ sidebarEl.style.display = 'flex';
1035
+ sidebarOverlayEl.style.display = 'block';
1036
+ sidebarCloseBtn.focus();
1037
+ }
1038
+
1039
+ function closeSidebar() {
1040
+ if (sidebarEl.style.display === 'none') return;
1041
+ sidebarEl.style.display = 'none';
1042
+ sidebarOverlayEl.style.display = 'none';
1043
+ sidebarToggleBtn.focus();
1044
+ }
1045
+
1046
+ sidebarToggleBtn.addEventListener('click', openSidebar);
1047
+ sidebarCloseBtn.addEventListener('click', closeSidebar);
1048
+ sidebarOverlayEl.addEventListener('click', closeSidebar);
1049
+
1050
+ // Persisted per-visitor text-size preference — steps rather than a free
1051
+ // slider, simple to reason about and to keep in sync with a disabled state
1052
+ // at each end.
1053
+ const FONT_SIZES = [13, 15, 17, 19];
1054
+ function getSavedFontSizeIndex() {
1055
+ try {
1056
+ const raw = localStorage.getItem('noxFontSizeIdx');
1057
+ const idx = raw !== null ? parseInt(raw, 10) : 1;
1058
+ return FONT_SIZES[idx] !== undefined ? idx : 1;
1059
+ } catch { return 1; }
1060
+ }
1061
+ let fontSizeIdx = getSavedFontSizeIndex();
1062
+ function applyFontSize() {
1063
+ document.documentElement.style.setProperty('--msg-font-size', FONT_SIZES[fontSizeIdx] + 'px');
1064
+ if (fontSizeDownBtn) fontSizeDownBtn.disabled = fontSizeIdx === 0;
1065
+ if (fontSizeUpBtn) fontSizeUpBtn.disabled = fontSizeIdx === FONT_SIZES.length - 1;
1066
+ }
1067
+ if (fontSizeDownBtn) fontSizeDownBtn.addEventListener('click', () => {
1068
+ if (fontSizeIdx === 0) return;
1069
+ fontSizeIdx--;
1070
+ applyFontSize();
1071
+ try { localStorage.setItem('noxFontSizeIdx', String(fontSizeIdx)); } catch {}
1072
+ });
1073
+ if (fontSizeUpBtn) fontSizeUpBtn.addEventListener('click', () => {
1074
+ if (fontSizeIdx === FONT_SIZES.length - 1) return;
1075
+ fontSizeIdx++;
1076
+ applyFontSize();
1077
+ try { localStorage.setItem('noxFontSizeIdx', String(fontSizeIdx)); } catch {}
1078
+ });
1079
+
1080
+ function downloadBlob(blob, filename) {
1081
+ const url = URL.createObjectURL(blob);
1082
+ const a = document.createElement('a');
1083
+ a.href = url;
1084
+ a.download = filename;
1085
+ document.body.appendChild(a);
1086
+ a.click();
1087
+ a.remove();
1088
+ setTimeout(() => URL.revokeObjectURL(url), 1000);
1089
+ }
1090
+
1091
+ if (exportTextBtn) exportTextBtn.addEventListener('click', () => {
1092
+ const messages = history.filter((m) => m.role !== 'system');
1093
+ if (!messages.length) return;
1094
+ const text = messages.map((m) => `${m.role === 'user' ? 'You' : 'Nox'}: ${m.content}`).join('\n\n');
1095
+ downloadBlob(new Blob([text], { type: 'text/plain;charset=utf-8' }), 'nox-chat.txt');
1096
+ });
1097
+
1098
+ if (exportPdfBtn) exportPdfBtn.addEventListener('click', () => {
1099
+ const messages = history.filter((m) => m.role !== 'system');
1100
+ if (!messages.length || typeof window.jspdf === 'undefined') return;
1101
+ const { jsPDF } = window.jspdf;
1102
+ const doc = new jsPDF({ unit: 'pt', format: 'a4' });
1103
+ const pageWidth = doc.internal.pageSize.getWidth();
1104
+ const pageHeight = doc.internal.pageSize.getHeight();
1105
+ const margin = 40;
1106
+ const maxWidth = pageWidth - margin * 2;
1107
+ let y = margin;
1108
+ doc.setFont('helvetica', 'bold');
1109
+ doc.setFontSize(16);
1110
+ doc.text('Nox — chat export', margin, y);
1111
+ y += 26;
1112
+ doc.setFont('helvetica', 'normal');
1113
+ doc.setFontSize(11);
1114
+ messages.forEach((m) => {
1115
+ const label = m.role === 'user' ? 'You' : 'Nox';
1116
+ const lines = doc.splitTextToSize(`${label}: ${m.content}`, maxWidth);
1117
+ lines.forEach((line) => {
1118
+ if (y > pageHeight - margin) {
1119
+ doc.addPage();
1120
+ y = margin;
1121
+ }
1122
+ doc.text(line, margin, y);
1123
+ y += 15;
1124
+ });
1125
+ y += 8;
1126
+ });
1127
+ doc.save('nox-chat.pdf');
1128
+ });
1129
+
1130
+ // Cmd/Ctrl+K jumps straight to the composer from anywhere on the page; Esc
1131
+ // backs out of whatever's currently "in front" — the sidebar first if it's
1132
+ // open, otherwise just clears a non-empty draft. Deliberately does NOT
1133
+ // auto-dismiss the at-capacity modal on Esc — that state means every
1134
+ // request would fail anyway, so hiding the explanation without the visitor
1135
+ // reading it first isn't helpful.
1136
+ document.addEventListener('keydown', (e) => {
1137
+ const isCmdK = (e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k';
1138
+ if (isCmdK) {
1139
+ e.preventDefault();
1140
+ input.focus();
1141
+ return;
1142
+ }
1143
+ if (e.key === 'Escape') {
1144
+ if (sidebarEl.style.display !== 'none') {
1145
+ closeSidebar();
1146
+ return;
1147
+ }
1148
+ if (document.activeElement === input && input.value) {
1149
+ input.value = '';
1150
+ input.style.height = 'auto';
1151
+ }
1152
+ }
1153
+ });
1154
+
1155
  function showEmptyState() {
1156
  emptyState.style.display = 'flex';
1157
  thread.style.display = 'none';
 
1338
 
1339
  function startNewChat() {
1340
  history = [{ role: "system", content: buildSystemPrompt() }];
1341
+ activeConvoId = null;
1342
+ setSavedActiveConvoId(null);
1343
  thread.innerHTML = '';
1344
  showEmptyState();
1345
  input.value = '';
1346
  input.style.height = 'auto';
1347
  input.focus();
1348
+ renderSidebarList();
1349
  }
1350
 
1351
  newChatBtn.addEventListener('click', startNewChat);
 
1495
  finishReason = result.finishReason;
1496
  }
1497
  history.push({ role: 'assistant', content: reply });
1498
+ persistActiveConversation();
1499
  loadingBubble.parentElement.after(createFeedbackRow(reply, userMessageText));
1500
  scrollToBottom();
1501
  fetchStats();
 
1522
  loadingBubble.innerHTML = renderMarkdown(reply);
1523
  enhanceCodeBlocks(loadingBubble);
1524
  history.push({ role: 'assistant', content: reply });
1525
+ persistActiveConversation();
1526
  loadingBubble.parentElement.after(createFeedbackRow(reply, userMessageText));
1527
  updateGlobalUsage(data.usage);
1528
  scrollToBottom();
 
1561
  const imageToSend = pendingImage ? pendingImage.base64 : null;
1562
  clearAttachment();
1563
 
1564
+ const userBubble = addMessage('user', displayText);
1565
+ userBubble.parentElement.after(createCopyOnlyRow(displayText));
1566
  history.push({ role: 'user', content: messageContent });
1567
+ persistActiveConversation();
1568
 
1569
  await requestReply(imageToSend);
1570
  if (!lastUsage || lastUsage.used < lastUsage.cap) {
 
1574
  }
1575
  });
1576
 
1577
+ // Restores whatever conversation was open when the page was last closed,
1578
+ // instead of always starting blank — the single biggest source of "lost my
1579
+ // chat on refresh" frustration this was built to fix. Falls back to a
1580
+ // normal blank new chat if there's nothing saved, or the saved id no longer
1581
+ // exists (e.g. it was deleted from another tab).
1582
+ const restoreId = getSavedActiveConvoId();
1583
+ const restoreConvos = loadConversations();
1584
+ if (restoreId && restoreConvos[restoreId]) {
1585
+ activeConvoId = restoreId;
1586
+ history = [{ role: 'system', content: buildSystemPrompt() }, ...restoreConvos[restoreId].messages];
1587
+ renderThreadFromHistory();
1588
+ } else {
1589
+ startNewChat();
1590
+ }
1591
  applyLanguage(currentLang);
1592
+ applyFontSize();
1593
+ renderSidebarList();
1594
  fetchStats();
1595
+
1596
+ if ('serviceWorker' in navigator) {
1597
+ window.addEventListener('load', () => {
1598
+ navigator.serviceWorker.register('sw.js').catch(() => {});
1599
+ });
1600
+ }
1601
  </script>
1602
  </body>
1603
  </html>
manifest.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Nox — by Devseis",
3
+ "short_name": "Nox",
4
+ "description": "A free AI assistant by Devseis. Ask anything, or attach an image or document.",
5
+ "start_url": "./index.html",
6
+ "scope": "./",
7
+ "display": "standalone",
8
+ "background_color": "#0b0e14",
9
+ "theme_color": "#0b0e14",
10
+ "icons": [
11
+ { "src": "icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
12
+ { "src": "icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
13
+ { "src": "icon-512-maskable.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
14
+ ]
15
+ }
sw.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Minimal offline app-shell cache — deliberately narrow: only the small set
2
+ // of same-origin static files that make up the page itself. Never touches
3
+ // the chat API (cross-origin, and never GET) or the CDN libraries (marked,
4
+ // DOMPurify, pdf.js, highlight.js, the Google Font) — those should always
5
+ // go through the browser's normal cache/network so a library update or a
6
+ // worker deploy is picked up immediately, not stuck behind a stale SW cache.
7
+ const CACHE_NAME = 'nox-shell-v1';
8
+ const APP_SHELL = [
9
+ './',
10
+ './index.html',
11
+ './manifest.json',
12
+ './devseis-logo.png',
13
+ './icon-192.png',
14
+ './icon-512.png',
15
+ ];
16
+
17
+ self.addEventListener('install', (event) => {
18
+ event.waitUntil(
19
+ caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)).catch(() => {})
20
+ );
21
+ self.skipWaiting();
22
+ });
23
+
24
+ self.addEventListener('activate', (event) => {
25
+ event.waitUntil(
26
+ caches.keys().then((keys) =>
27
+ Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
28
+ )
29
+ );
30
+ self.clients.claim();
31
+ });
32
+
33
+ self.addEventListener('fetch', (event) => {
34
+ const req = event.request;
35
+ if (req.method !== 'GET') return;
36
+ const url = new URL(req.url);
37
+ if (url.origin !== self.location.origin) return;
38
+ if (!APP_SHELL.some((p) => url.pathname.endsWith(p.replace('./', '')) || (p === './' && url.pathname === '/'))) return;
39
+
40
+ // Network-first so a redeploy is visible on next load when online; falls
41
+ // back to the cached shell only when the network actually fails (offline).
42
+ event.respondWith(
43
+ fetch(req)
44
+ .then((res) => {
45
+ const copy = res.clone();
46
+ caches.open(CACHE_NAME).then((cache) => cache.put(req, copy)).catch(() => {});
47
+ return res;
48
+ })
49
+ .catch(() => caches.match(req))
50
+ );
51
+ });