driftnet 0.7.1 → 0.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "driftnet",
3
- "version": "0.7.1",
3
+ "version": "0.8.0",
4
4
  "mcpName": "io.github.KevinChu1110/driftnet",
5
5
  "description": "Drop links into any chat; get them sorted, explained and searchable, for you and your agents. Any model, or none.",
6
6
  "license": "MIT",
package/public/index.html CHANGED
@@ -361,8 +361,9 @@
361
361
  .hint { color: var(--muted); font-size: 13px; margin: -4px 2px 0; }
362
362
 
363
363
  /* A card sits on top of two action strips that show while it is dragged. */
364
- .swipe { position: relative; border-radius: 12px; overflow: hidden; scroll-margin-top: 90px; transition: height .25s ease, margin .25s ease, opacity .25s ease; }
364
+ .swipe { content-visibility: auto; contain-intrinsic-size: auto 150px; position: relative; border-radius: 12px; overflow: hidden; scroll-margin-top: 90px; transition: height .25s ease, margin .25s ease, opacity .25s ease; }
365
365
  .swipe.gone { opacity: 0; }
366
+ .page-more { display: flex; justify-content: center; padding: 8px 0 24px; }
366
367
  /* Inside the card (the swipe wrapper clips anything outside it). */
367
368
  .swipe.flash .card { animation: flash 2s ease; }
368
369
  @keyframes flash { 0%, 55% { outline: 3px solid var(--accent); outline-offset: -3px; background: var(--accent-soft); } 100% { outline-color: transparent; } }
@@ -399,6 +400,9 @@
399
400
  .plan-op.off { opacity: .5; }
400
401
  #plan-body { max-height: 55vh; overflow: auto; }
401
402
  .badge.folder { background: color-mix(in srgb, var(--c) 14%, var(--panel)); color: var(--c); font-weight: 600; }
403
+ .badge.health { background: var(--danger-soft); color: var(--danger); }
404
+ .badge.health.stale, .badge.health.moved { background: var(--accent-soft); color: var(--muted); }
405
+ .stars { color: var(--star); }
402
406
  .rating { font-size: 12px; color: var(--muted); white-space: nowrap; }
403
407
  .rating.must { color: var(--star); font-weight: 600; }
404
408
  .rating .ico { width: 13px; height: 13px; fill: currentColor; vertical-align: -2px; margin-right: 2px; }
@@ -691,7 +695,7 @@
691
695
  kind: "Kind", switchTo: "中文", nav: "Views and categories",
692
696
  stats: (n, s) => `${n} ${n === 1 ? "item" : "items"} · shared ${s}×`, shared: (n) => `shared ${n}×`,
693
697
  empty: "Nothing here yet — drop a link in your chat.", emptyFav: "No favorites yet — swipe a card right, or tap the star.",
694
- emptyTrash: "The trash is empty.", hint: "Swipe right to favorite, left to remove.", hintTrash: "Swipe right to restore.",
698
+ pageMore: (n) => `Show more (${n} left)`, emptyTrash: "The trash is empty.", hint: "Swipe right to favorite, left to remove.", hintTrash: "Swipe right to restore.",
695
699
  kinds: { repo: "Repos", product: "Products", video: "Videos", article: "Articles", post: "Posts", other: "Other" },
696
700
  kind1: { repo: "Repo", product: "Product", video: "Video", article: "Article", post: "Post", other: "Other" },
697
701
  worth: { skip: "skip", low: "low", normal: "worth a look", "must-see": "must-see" },
@@ -735,6 +739,10 @@
735
739
  split: "Split", splitHelp: "Cards and mind map side by side", splitCards: "Cards",
736
740
  kSelect: "Select or unselect the card", kRange: "Select a range", kHold: "Hold", kLong: "Start selecting on a phone", keysClose: "Close", kClear: "Clear the selection", kUndo: "Undo the last action", kHelp: "This list",
737
741
  kQuickNone: "Move a card into a folder first; the nine you use most get a number here.", kQuickN: (f) => `Move into ${f}`,
742
+ review: "Needs review", emptyReview: "No dead, archived or stale links found.", hintReview: "These links look dead, archived or stale. Refresh to re-read, check the link again from the card, or move them to the trash.",
743
+ checkLink: "Check link", linkChecked: "Link checked", linkCheckFailed: "Couldn't check the link",
744
+ health: { dead: ["☠", "dead", "The link no longer works (404 / gone)"], archived: ["🗄", "archived", "The repo is archived (read-only)"], stale: ["💤", "stale", "No pushes for 18 months"], moved: ["↪", "moved", "The repo moved or was renamed"] },
745
+ stars: (n) => `${n} GitHub stars`,
738
746
  inbox: "Inbox", emptyInbox: "Inbox zero — every card has a folder you chose.", hintInbox: "Tap a folder to file the card. Not filed yet: the cards below.",
739
747
  chipOther: "Other folder…", chipTitle: (p) => `Confidence ${p}%`,
740
748
  keysInbox: "In the Inbox", kChip: "File into the card's suggested folder 1–3", kSkip: "Skip: focus the next card", kQuickInbox: "In the Inbox, 1–3 pick the focused card's suggested folders instead; 4–9 still file into your most-used folders.",
@@ -756,8 +764,16 @@
756
764
  plugins: "Plugins", pluginsNone: (dir) => `No plugins. Put .js files in ${dir} — see examples/plugins in the repo.`,
757
765
  status: (e) => `Now: sorting by ${({ jev: "Jev", llm: "the model", heuristic: "built-in rules" })[e.judge] ?? e.judge}, summaries: ${e.summarizer === "off" ? "off" : e.summarizer}`, keep: "set — leave empty to keep", unset: "not set",
758
766
  locked: "set by the environment driftnet runs in", forbidden: "Server settings can only be changed on the computer running driftnet (or set DRIFTNET_TOKEN). Display settings still work.",
759
- savedServer: "Saved — already in effect", chat: "Chat replies", webhook: "Outgoing webhook", feed: "Feed (RSS)", genCopied: "New password generated and copied — press Save to keep it",
767
+ savedServer: "Saved — already in effect", chat: "Chat replies", webhook: "Outgoing webhook", digest: "Scheduled digest", feed: "Feed (RSS)", genCopied: "New password generated and copied — press Save to keep it",
760
768
  tabGeneral: "General", tabAccess: "Access", tabAi: "AI",
769
+ impTitle: "Import bookmarks", impHelp: "Bring in a bookmarks file from your browser (HTML), Pocket, Raindrop (CSV), a driftnet JSON list, or any text with links.",
770
+ impFile: "Choose a file", impKeep: "Keep my bookmark folders (under Imported)", impReading: "Reading the file…",
771
+ impConfirm: (n, dup) => `Import ${n} links (${dup} already there)? With a model set up, each new link is one model call.`,
772
+ impNone: (dup, skip) => `Nothing new to import (${dup} already there, ${skip} skipped).`, impCapped: (n) => `Only the first ${n} links are taken in one import.`,
773
+ impSkipped: (n) => `${n} skipped (not web links, or private addresses).`, impStart: "Start import", impBusy: "An import is already running. Try again when it finishes.",
774
+ impProgress: (done, total, added, failed) => `Importing… ${done} of ${total} (${added} added, ${failed} failed)`,
775
+ impDone: (total, added, already, failed) => `Done: ${added} added, ${already} already there, ${failed} failed (of ${total}).`,
776
+ impFailedRun: "The import stopped unexpectedly.", impBadFile: "Couldn't read that file.",
761
777
  accessStatus: (pw, key, url) => `Password: ${pw === "✓" ? "set" : "not set"} · Share key: ${key === "✓" ? "made" : "none"} · Public URL: ${url === "—" ? "off" : url}`,
762
778
  access: "Access & connections",
763
779
  password: "Admin password", passwordHelp: "Once set, adding links, changing settings and agents that write all need it. At least 8 characters, no spaces.",
@@ -808,6 +824,11 @@
808
824
  DRIFTNET_BLOCK_DOMAINS: ["Never catalogue these domains", "Comma or space separated, e.g. example.com, spam.io"],
809
825
  DRIFTNET_WEBHOOK_URL: ["Webhook URL", "driftnet POSTs each new or updated card here (n8n, Zapier, Slack workflows…). Treated as a secret."],
810
826
  DRIFTNET_WEBHOOK_SECRET: ["Webhook signing secret", "Optional. Adds X-Driftnet-Signature: sha256=<HMAC of the body>."],
827
+ DRIFTNET_DIGEST: ["Digest", "A short summary of new cards, posted into your chats."],
828
+ DRIFTNET_DIGEST_AT: ["Digest time", "HH:MM in the server's local time zone, e.g. 09:00 (default)."],
829
+ DRIFTNET_DIGEST_DAY: ["Digest day (weekly)", ""],
830
+ DRIFTNET_DIGEST_TO: ["Digest targets", "Comma separated: telegram:<chat id>, discord:<channel id>, slack:<channel id>, line:<user, group or room id>. Uses the bot tokens already set."],
831
+ DRIFTNET_HEALTH: ["Link health check", "Weekly: a few cards at a time, driftnet checks that links still work and repos aren't archived. Marks dead, archived and stale cards."],
811
832
  DRIFTNET_WEBHOOK_ALLOW_LOCAL: ["Allow a local webhook", "Needed when the receiver is on your own network (n8n on a LAN). Only that exact address is allowed."],
812
833
  },
813
834
  choices: {
@@ -817,7 +838,10 @@
817
838
  DRIFTNET_SUMMARY_DEPTH: { "": "Standard (default)", brief: "Brief: one line, 2 highlights, what you see", standard: "Standard", detailed: "Detailed: more highlights, use cases, how to try it" },
818
839
  DRIFTNET_LOCALE: { "": "Same as the summaries", en: "English", "zh-TW": "繁體中文" },
819
840
  DRIFTNET_REPLY: { "": "One line + link (default)", link: "One line + link", full: "Full summary", off: "Don't reply" },
841
+ DRIFTNET_DIGEST: { "": "Off (default)", off: "Off", daily: "Every day", weekly: "Every week" },
842
+ DRIFTNET_DIGEST_DAY: { "": "Monday (default)", mon: "Monday", tue: "Tuesday", wed: "Wednesday", thu: "Thursday", fri: "Friday", sat: "Saturday", sun: "Sunday" },
820
843
  DRIFTNET_WEBHOOK_ALLOW_LOCAL: { "": "No (public addresses only)", 1: "Yes" },
844
+ DRIFTNET_HEALTH: { "": "Off (default)", off: "Off", weekly: "Weekly (recommended)" },
821
845
  },
822
846
  },
823
847
  },
@@ -826,7 +850,7 @@
826
850
  kind: "類型", switchTo: "EN", nav: "檢視與分類",
827
851
  stats: (n, s) => `${n} 則 · 分享 ${s} 次`, shared: (n) => `分享 ${n} 次`,
828
852
  empty: "還沒有內容,把連結丟進聊天室吧。", emptyFav: "還沒有最愛,把卡片往右滑或按星號。",
829
- emptyTrash: "垃圾桶是空的。", hint: "往右滑加入最愛,往左滑移到垃圾桶。", hintTrash: "往右滑還原。",
853
+ pageMore: (n) => `再顯示 ${n} 張`, emptyTrash: "垃圾桶是空的。", hint: "往右滑加入最愛,往左滑移到垃圾桶。", hintTrash: "往右滑還原。",
830
854
  kinds: { repo: "程式庫", product: "產品", video: "影片", article: "文章", post: "貼文", other: "其他" },
831
855
  worth: { skip: "略過", low: "次要", normal: "值得看", "must-see": "必看" },
832
856
  flags: { injection: "提示詞注入", "hidden-chars": "隱藏字元", "low-reputation": "低信譽來源" },
@@ -869,6 +893,10 @@
869
893
  split: "並排", splitHelp: "卡片列表與樹狀圖並排顯示", splitCards: "卡片",
870
894
  kSelect: "選取/取消選取這張", kRange: "選取一段範圍", kHold: "長按", kLong: "在手機上開始選取卡片", keysClose: "關閉", kClear: "取消全部選取", kUndo: "復原上一個動作", kHelp: "顯示這份清單",
871
895
  kQuickNone: "先把卡片移進某個資料夾;最常用的九個資料夾會在這裡得到數字鍵。", kQuickN: (f) => `移到 ${f}`,
896
+ review: "需要檢查", emptyReview: "沒有發現失效、封存或久未更新的連結。", hintReview: "這些連結看起來已失效、封存或久未更新。可以重新整理、在卡片上再檢查一次連結,或移到垃圾桶。",
897
+ checkLink: "檢查連結", linkChecked: "已檢查連結", linkCheckFailed: "無法檢查連結",
898
+ health: { dead: ["☠", "失效", "連結已經打不開(404/已移除)"], archived: ["🗄", "已封存", "這個儲存庫已封存(唯讀)"], stale: ["💤", "久未更新", "已超過 18 個月沒有更新"], moved: ["↪", "已搬家", "這個儲存庫已搬家或改名"] },
899
+ stars: (n) => `${n} 顆 GitHub 星`,
872
900
  inbox: "收件匣", emptyInbox: "收件匣清空了——每張卡片都有你選的資料夾。", hintInbox: "點一下資料夾就能歸檔。下面是還沒歸檔的卡片。",
873
901
  chipOther: "其他資料夾…", chipTitle: (p) => `信心 ${p}%`,
874
902
  keysInbox: "在收件匣", kChip: "歸到這張卡片建議的第 1–3 個資料夾", kSkip: "略過:移到下一張卡片", kQuickInbox: "在收件匣裡,1–3 改成選擇目前卡片的建議資料夾;4–9 仍然是放進最常用的資料夾。",
@@ -890,8 +918,16 @@
890
918
  plugins: "外掛", pluginsNone: (dir) => `沒有外掛。把 .js 檔放進 ${dir},範例在 repo 的 examples/plugins。`,
891
919
  status: (e) => `目前:分類用 ${({ jev: "Jev", llm: "模型", heuristic: "內建規則" })[e.judge] ?? e.judge},摘要用 ${e.summarizer === "off" ? "(未開啟)" : e.summarizer}`, keep: "已設定,留空就不變", unset: "未設定",
892
920
  locked: "由執行環境設定", forbidden: "伺服器設定只能在執行 driftnet 的那台電腦上改(或設定 DRIFTNET_TOKEN)。顯示設定照常可用。",
893
- savedServer: "已儲存,馬上生效", chat: "聊天室回覆", webhook: "對外 Webhook", feed: "訂閱源(RSS)", genCopied: "已產生新密碼並複製,按「儲存」才會生效",
921
+ savedServer: "已儲存,馬上生效", chat: "聊天室回覆", webhook: "對外 Webhook", digest: "定時摘要", feed: "訂閱源(RSS)", genCopied: "已產生新密碼並複製,按「儲存」才會生效",
894
922
  tabGeneral: "一般", tabAccess: "存取", tabAi: "AI",
923
+ impTitle: "匯入書籤", impHelp: "匯入瀏覽器的書籤檔(HTML)、Pocket、Raindrop(CSV)、driftnet 的 JSON 清單,或任何含有連結的文字檔。",
924
+ impFile: "選擇檔案", impKeep: "保留我的書籤資料夾(放在「Imported」底下)", impReading: "讀取檔案中…",
925
+ impConfirm: (n, dup) => `匯入 ${n} 個連結(${dup} 個已經有了)?若已設定模型,每個新連結都會呼叫一次模型。`,
926
+ impNone: (dup, skip) => `沒有新的連結可匯入(${dup} 個已經有了,略過 ${skip} 個)。`, impCapped: (n) => `一次最多匯入前 ${n} 個連結。`,
927
+ impSkipped: (n) => `略過 ${n} 個(不是網頁連結,或是內網位址)。`, impStart: "開始匯入", impBusy: "已有匯入正在進行,請等它完成再試。",
928
+ impProgress: (done, total, added, failed) => `匯入中… ${done} / ${total}(新增 ${added}、失敗 ${failed})`,
929
+ impDone: (total, added, already, failed) => `完成:新增 ${added}、原本就有 ${already}、失敗 ${failed}(共 ${total})。`,
930
+ impFailedRun: "匯入意外中止。", impBadFile: "讀不了這個檔案。",
895
931
  accessStatus: (pw, key, url) => `密碼:${pw === "✓" ? "已設定" : "未設定"} · 分享碼:${key === "✓" ? "已產生" : "沒有"} · 公開網址:${url === "—" ? "關閉" : url}`,
896
932
  access: "存取與連線",
897
933
  password: "管理密碼", passwordHelp: "設定之後,新增連結、改設定、agent 寫入都需要它。至少 8 個字元,不能有空白。",
@@ -942,6 +978,11 @@
942
978
  DRIFTNET_BLOCK_DOMAINS: ["不要收錄的網域", "用逗號或空白分隔,例如 example.com, spam.io"],
943
979
  DRIFTNET_WEBHOOK_URL: ["Webhook 網址", "每張新增或更新的卡片都會 POST 到這裡(n8n、Zapier、Slack 工作流程…)。視為機密。"],
944
980
  DRIFTNET_WEBHOOK_SECRET: ["Webhook 簽章密鑰", "選填。會加上 X-Driftnet-Signature: sha256=<內容的 HMAC>。"],
981
+ DRIFTNET_DIGEST: ["定時摘要", "把新卡片整理成一則短訊息,貼進你的聊天室。"],
982
+ DRIFTNET_DIGEST_AT: ["摘要時間", "伺服器所在時區的 HH:MM,例如 09:00(預設)。"],
983
+ DRIFTNET_DIGEST_DAY: ["摘要星期(每週)", ""],
984
+ DRIFTNET_DIGEST_TO: ["摘要送到哪裡", "以逗號分隔:telegram:<聊天室 id>、discord:<頻道 id>、slack:<頻道 id>、line:<使用者、群組或聊天室 id>。使用已設定的機器人金鑰。"],
985
+ DRIFTNET_HEALTH: ["連結健康檢查", "每週:每次幾張,檢查連結是否還能開、儲存庫是否已封存,並標記失效、封存、久未更新的卡片。"],
945
986
  DRIFTNET_WEBHOOK_ALLOW_LOCAL: ["允許本機 Webhook", "接收端在你自己的區域網路時需要(例如內網的 n8n)。只放行你填的那個位址。"],
946
987
  },
947
988
  choices: {
@@ -951,7 +992,10 @@
951
992
  DRIFTNET_SUMMARY_DEPTH: { "": "標準(預設)", brief: "簡短:一句話、2 個重點、看得到什麼", standard: "標準", detailed: "詳細:更多重點、使用情境、怎麼試用" },
952
993
  DRIFTNET_LOCALE: { "": "跟摘要一樣", en: "English", "zh-TW": "繁體中文" },
953
994
  DRIFTNET_REPLY: { "": "一行+連結(預設)", link: "一行+連結", full: "完整摘要", off: "不回覆" },
995
+ DRIFTNET_DIGEST: { "": "關閉(預設)", off: "關閉", daily: "每天", weekly: "每週" },
996
+ DRIFTNET_DIGEST_DAY: { "": "週一(預設)", mon: "週一", tue: "週二", wed: "週三", thu: "週四", fri: "週五", sat: "週六", sun: "週日" },
954
997
  DRIFTNET_WEBHOOK_ALLOW_LOCAL: { "": "否(只允許公開位址)", 1: "是" },
998
+ DRIFTNET_HEALTH: { "": "關閉(預設)", off: "關閉", weekly: "每週(建議)" },
955
999
  },
956
1000
  },
957
1001
  },
@@ -1018,7 +1062,7 @@
1018
1062
  history.replaceState(null, "", u.pathname + u.search + u.hash);
1019
1063
  })();
1020
1064
 
1021
- async function api(path, init = {}) {
1065
+ async function api(path, init = {}, meta = null) {
1022
1066
  // Reads work with the admin password or the share key; writes go through other helpers with the password.
1023
1067
  const token = store.get("driftnet-token") || store.get("driftnet-key");
1024
1068
  let res = await fetch(path, { ...init, headers: { ...(init.headers ?? {}), ...(token ? { authorization: `Bearer ${token}` } : {}) } });
@@ -1029,6 +1073,7 @@
1029
1073
  }
1030
1074
  if (res.status === 401) throw Object.assign(new Error("unauthorized"), { unauthorized: true });
1031
1075
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
1076
+ if (meta) meta.total = Number(res.headers.get("x-total-count"));
1032
1077
  return res.json();
1033
1078
  }
1034
1079
 
@@ -1092,7 +1137,7 @@
1092
1137
  /** One line under the header saying what is shown, so a closed drawer hides nothing. */
1093
1138
  function updateCrumb() {
1094
1139
  const t = T();
1095
- const parts = [state.view === "favorites" ? t.favorites : state.view === "trash" ? t.trash : state.view === "inbox" ? t.inbox
1140
+ const parts = [state.view === "favorites" ? t.favorites : state.view === "trash" ? t.trash : state.view === "inbox" ? t.inbox : state.view === "review" ? t.review
1096
1141
  : state.view === "notes" ? t.notes : state.view === "map" ? t.map : t.all];
1097
1142
  if (state.category) parts.push(catLabel(state.category));
1098
1143
  if (state.kind) parts.push(t.kinds[state.kind] ?? state.kind);
@@ -1131,6 +1176,7 @@
1131
1176
  `<button type="button" class="menu" id="menu-close" aria-label="${esc(T().close)}">✕</button></div>` +
1132
1177
  `<div class="row">` +
1133
1178
  (role === "admin" || stats.inbox ? btn("view", "inbox", T().inbox, stats.inbox || "", "inbox") : "") +
1179
+ (stats.review || state.view === "review" ? btn("view", "review", T().review, stats.review || "", "refresh") : "") +
1134
1180
  btn("view", "all", T().all, stats.items, "all") + btn("view", "favorites", T().favorites, stats.favorites, "star") +
1135
1181
  btn("view", "map", T().map, "", "map") +
1136
1182
  `<button type="button" class="split-btn" data-split aria-pressed="${split}" title="${esc(T().splitHelp)}"><span class="lbl">${ic("split")}<span>${esc(T().split)}</span></span><span class="count"></span></button>` +
@@ -1403,6 +1449,7 @@
1403
1449
  if (el && !visible) {
1404
1450
  if (el.contains(document.activeElement)) (el.nextElementSibling ?? el.previousElementSibling)?.querySelector?.(".card")?.focus();
1405
1451
  dismiss(el);
1452
+ forgetItem(id);
1406
1453
  }
1407
1454
  else if (el) { el.outerHTML = card(item); attachSwipe(document.getElementById(`item-${id}`)); }
1408
1455
  refreshTree();
@@ -1411,7 +1458,7 @@
1411
1458
  if (onMap && onMap !== item) onMap.category = to;
1412
1459
  if (mapShown()) drawMap();
1413
1460
  bumpUse(to);
1414
- if (!quiet) { toast(T().moved(nameOf(item), folderPath(to)), async () => { await moveItem(id, from, true); render(); }); }
1461
+ if (!quiet) { toast(T().moved(nameOf(item), folderPath(to)), async () => { await moveItem(id, from, true); renderKeep(); }); }
1415
1462
  }
1416
1463
  const subtreeOf = (id) => { const out = new Set([id]); for (const q = [id]; q.length;) for (const k of kids(q.pop())) { out.add(k.id); q.push(k.id); } return out; };
1417
1464
  /** Re-draw just the tree's counts after a move. */
@@ -1518,7 +1565,7 @@
1518
1565
  const yes = (b) => (b ? "✓" : "—");
1519
1566
  const accessStatus = `<p class="set-status">${esc(st.accessStatus(yes(a.passwordSet), yes(a.readKey), a.tunnel.running ? a.tunnel.url : "—"))}</p>`;
1520
1567
  server = {
1521
- general: group("language") + group("chat") + group("webhook"),
1568
+ general: group("language") + group("chat") + group("digest") + group("webhook") + importPanel(),
1522
1569
  access: accessStatus + accessPanel(serverSettings, field) + (agentTokens ? tokensPanel(serverSettings.access, agentTokens, minted) + pairPanel(serverSettings.access) : ""),
1523
1570
  ai: `<p class="set-status" id="st-status">${esc(st.status(serverSettings.engines))}</p>` + group("model") + group("rules") +
1524
1571
  `<fieldset class="set-group"><legend>${esc(st.plugins)}</legend><div class="set-row">${plugins}</div></fieldset>`,
@@ -1542,6 +1589,72 @@
1542
1589
  $("settings-dlg").showModal();
1543
1590
  $("st-body").querySelector('[data-tab-btn][aria-selected="true"]')?.focus();
1544
1591
  }
1592
+ /** Settings › Import bookmarks: pick a file, preview the counts (dry run), confirm, then watch the job. */
1593
+ let importContent = "", importTimer = null;
1594
+ function importPanel() {
1595
+ const st = T().st;
1596
+ importContent = ""; clearInterval(importTimer);
1597
+ return `<fieldset class="set-group" id="import-panel"><legend>${esc(st.impTitle)}</legend>
1598
+ <small>${esc(st.impHelp)}</small>
1599
+ <label class="set-row"><span>${esc(st.impFile)}</span><input type="file" id="im-file" accept=".html,.htm,.csv,.json,.txt,.md"></label>
1600
+ <label class="set-row check"><input type="checkbox" id="im-keep"><span>${esc(st.impKeep)}</span></label>
1601
+ <p class="set-status" id="im-status" role="status" aria-live="polite"></p>
1602
+ <div><button class="btn primary" type="button" id="im-start" hidden>${esc(st.impStart)}</button></div></fieldset>`;
1603
+ }
1604
+ async function importCall(body) {
1605
+ const token = store.get("driftnet-token");
1606
+ const res = await fetch("/api/import", { method: "POST", body: JSON.stringify(body),
1607
+ headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) } }).catch(() => null);
1608
+ if (res?.status === 401) { askToken(); return null; }
1609
+ return res ? { status: res.status, body: await res.json().catch(() => ({})) } : null;
1610
+ }
1611
+ $("st-body").addEventListener("change", async (e) => {
1612
+ if (e.target.id !== "im-file") return;
1613
+ const st = T().st, out = $("im-status"), go = $("im-start");
1614
+ go.hidden = true; importContent = ""; clearInterval(importTimer);
1615
+ const file = e.target.files?.[0];
1616
+ if (!file) { out.textContent = ""; return; }
1617
+ out.textContent = st.impReading;
1618
+ const content = await new Promise((ok) => {
1619
+ const r = new FileReader();
1620
+ r.onload = () => ok(String(r.result));
1621
+ r.onerror = () => ok(null);
1622
+ r.readAsText(file);
1623
+ });
1624
+ if (content === null) { out.textContent = st.impBadFile; return; }
1625
+ const r = await importCall({ content, dryRun: true });
1626
+ if (!r || r.status !== 200) { out.textContent = r?.body?.error ?? T().failed; return; }
1627
+ const d = r.body;
1628
+ importContent = content;
1629
+ out.textContent = [d.total ? st.impConfirm(d.total, d.duplicates) : st.impNone(d.duplicates, d.skipped),
1630
+ d.total && d.skipped ? st.impSkipped(d.skipped) : "", d.capped ? st.impCapped(5000) : ""].filter(Boolean).join(" ");
1631
+ go.hidden = !d.total;
1632
+ });
1633
+ $("st-body").addEventListener("click", async (e) => {
1634
+ if (e.target.id !== "im-start") return;
1635
+ const st = T().st, out = $("im-status"), go = $("im-start");
1636
+ go.hidden = true;
1637
+ const r = await importCall({ content: importContent, folders: $("im-keep").checked ? "keep" : "none" });
1638
+ importContent = "";
1639
+ if (!r) { out.textContent = T().failed; return; }
1640
+ if (r.status === 409) { out.textContent = st.impBusy; return; }
1641
+ if (r.status !== 202) { out.textContent = r.body?.error ?? T().failed; return; }
1642
+ const job = r.body.job;
1643
+ out.textContent = st.impProgress(0, r.body.total, 0, 0);
1644
+ const token = store.get("driftnet-token");
1645
+ const tick = async () => {
1646
+ if (!out.isConnected) return clearInterval(importTimer);
1647
+ const p = await fetch(`/api/import/${job}`, { headers: token ? { authorization: `Bearer ${token}` } : {} }).then((x) => x.ok ? x.json() : null).catch(() => null);
1648
+ if (!p) return;
1649
+ if (p.state === "running") out.textContent = st.impProgress(p.done, p.total, p.added, p.failed);
1650
+ else {
1651
+ clearInterval(importTimer);
1652
+ out.textContent = p.state === "done" ? st.impDone(p.total, p.added, p.already, p.failed) : st.impFailedRun;
1653
+ if (p.state === "done" && p.added) load();
1654
+ }
1655
+ };
1656
+ importTimer = setInterval(tick, 2000);
1657
+ });
1545
1658
  let settingsOpener = null;
1546
1659
  $("settings-dlg").addEventListener("close", () => { if (settingsOpener?.isConnected) settingsOpener.focus(); });
1547
1660
  $("st-cancel").onclick = () => $("settings-dlg").close();
@@ -1840,10 +1953,13 @@
1840
1953
  /** Cards shown per folder before the rest fold into a "+N" node. */
1841
1954
  const MAP_CAP = 15;
1842
1955
 
1956
+ let mapTotal = 0;
1843
1957
  async function renderMap() {
1844
1958
  const t = T();
1845
1959
  try {
1846
- mapItems = await api("/api/items?limit=500&minWorth=skip");
1960
+ const meta = {};
1961
+ mapItems = await api("/api/items?limit=500&minWorth=skip", {}, meta);
1962
+ mapTotal = meta.total;
1847
1963
  } catch (err) {
1848
1964
  if (err.unauthorized) return askToken();
1849
1965
  throw err;
@@ -2354,6 +2470,7 @@
2354
2470
  <h3 id="md-title"><a href="${esc(url)}" target="_blank" rel="noopener noreferrer">${esc(name)}</a></h3>
2355
2471
  <p class="md-sub"><span class="badge folder" style="--c:${folderColor(i.category)}">${esc(folderPath(i.category))}</span>
2356
2472
  <span class="rating ${i.worth === "must-see" ? "must" : ""}">${i.worth === "must-see" ? ic("star") : ""}${esc(t.worth[i.worth] ?? i.worth)}</span>
2473
+ ${healthBadge(i)}${starsHtml(i)}
2357
2474
  <span>#${i.id} · ${esc(t.kind1?.[i.kind] ?? t.kinds[i.kind] ?? i.kind)}</span></p>
2358
2475
  ${s?.oneLiner ? `<p class="md-one">${esc(s.oneLiner)}</p>` : ""}
2359
2476
  ${sec("demo", t.mdDemo, s?.demo ? `<p>${esc(s.demo)}</p>` : "")}
@@ -2371,7 +2488,7 @@
2371
2488
  (admin ? (inTrash ? btn("restore", "undo", t.restore)
2372
2489
  : btn("favorite", "star", i.favorite ? t.unfavorite : t.favorite, i.favorite ? "on" : "") + btn("move", "move", t.moveTo) +
2373
2490
  `<button class="btn ${busy ? "spin" : ""}" type="button" data-md="refresh" ${busy ? "disabled" : ""}>${ic("refresh")} ${esc(t.refresh)}</button>` +
2374
- btn("note", "note", i.note ? t.editNote : t.addNote) + `<span class="spacer"></span>` + btn("trash", "trash", t.remove, "danger")) : "") +
2491
+ btn("health", "refresh", t.checkLink) + btn("note", "note", i.note ? t.editNote : t.addNote) + `<span class="spacer"></span>` + btn("trash", "trash", t.remove, "danger")) : "") +
2375
2492
  (modalFrom === "map" ? btn("list", "list", t.showInList) : "");
2376
2493
  }
2377
2494
  function openModal(id, from = "list") {
@@ -2429,6 +2546,7 @@
2429
2546
  }
2430
2547
  if (act1 === "move") { mdlDlg.close(); return openMovePicker(id); }
2431
2548
  if (act1 === "refresh") return refreshItem(id);
2549
+ if (act1 === "health") return checkLink(id);
2432
2550
  if (act1 === "note") return openItemNote(id);
2433
2551
  if (act1 === "favorite") {
2434
2552
  if (el) await run(el, "favorite");
@@ -2903,20 +3021,103 @@
2903
3021
  folders = await api("/api/folders").catch(() => folders);
2904
3022
  await load();
2905
3023
  }
2906
- async function renderCards() {
2907
- const p = new URLSearchParams({ limit: "300" });
3024
+ /** Cards fetched per page; the rest come as the reader reaches the end of the list. */
3025
+ const PAGE = 60;
3026
+ let pageTotal = 0, pageGen = 0, pageBusy = false, pageObserver = null, pageHost = null, keepPages = false;
3027
+ const listParams = () => {
3028
+ const p = new URLSearchParams();
2908
3029
  if (prefs.sort !== "best") p.set("sort", prefs.sort);
2909
- if (state.view !== "all") p.set("view", state.view);
3030
+ if (state.view === "review") p.set("health", "dead,archived,stale");
3031
+ else if (state.view !== "all") p.set("view", state.view);
2910
3032
  for (const k of ["category", "kind", "q"]) if (state[k]) p.set(k, state[k]);
2911
- items = await api(`/api/items?${p}`);
3033
+ return p;
3034
+ };
3035
+ const moreHtml = () => items.length < pageTotal
3036
+ ? `<div class="page-more" id="page-more"><button type="button" class="btn" data-page-more>${esc(T().pageMore(pageTotal - items.length))}</button></div>` : "";
3037
+ /** Redo the list after a change, keeping the pages already loaded (and the scroll position). */
3038
+ function renderKeep() { keepPages = true; return render(); }
3039
+ /** A card left the list for good: later pages must not skip or repeat one. */
3040
+ function forgetItem(id) {
3041
+ const i = items.findIndex((x) => x.id === id);
3042
+ if (i < 0) return;
3043
+ extraItems.set(id, items[i]);
3044
+ items.splice(i, 1);
3045
+ pageTotal = Math.max(0, pageTotal - 1);
3046
+ syncMore();
3047
+ }
3048
+ function syncMore() {
3049
+ const host = pageHost, old = host?.querySelector("#page-more");
3050
+ if (!host) return;
3051
+ if (items.length >= pageTotal) { pageObserver?.disconnect(); old?.remove(); return; }
3052
+ if (old) { old.querySelector("[data-page-more]").textContent = T().pageMore(pageTotal - items.length); return; }
3053
+ host.insertAdjacentHTML("beforeend", moreHtml());
3054
+ watchMore();
3055
+ }
3056
+ function watchMore() {
3057
+ pageObserver?.disconnect();
3058
+ const el = pageHost?.querySelector("#page-more");
3059
+ if (!el) return;
3060
+ el.querySelector("[data-page-more]").onclick = () => loadMore();
3061
+ if ("IntersectionObserver" in window) {
3062
+ pageObserver = new IntersectionObserver((es) => { if (es.some((e) => e.isIntersecting)) loadMore(); }, { rootMargin: "600px 0px" });
3063
+ pageObserver.observe(el);
3064
+ }
3065
+ }
3066
+ async function loadMore() {
3067
+ if (pageBusy || !pageHost || items.length >= pageTotal) return;
3068
+ const gen = pageGen, host = pageHost;
3069
+ pageBusy = true;
3070
+ try {
3071
+ const p = listParams();
3072
+ p.set("limit", String(PAGE)); p.set("offset", String(items.length));
3073
+ const meta = {};
3074
+ const more = await api(`/api/items?${p}`, {}, meta);
3075
+ if (gen !== pageGen) return;
3076
+ if (Number.isFinite(meta.total)) pageTotal = meta.total;
3077
+ const seen = new Set(items.map((i) => i.id));
3078
+ const fresh = more.filter((i) => !seen.has(i.id));
3079
+ items.push(...fresh);
3080
+ if (!more.length) pageTotal = items.length;
3081
+ host.querySelector("#page-more")?.remove();
3082
+ host.insertAdjacentHTML("beforeend", fresh.map(card).join(""));
3083
+ for (const i of fresh) attachSwipe(document.getElementById(`item-${i.id}`));
3084
+ host.insertAdjacentHTML("beforeend", moreHtml());
3085
+ watchMore();
3086
+ syncSelection();
3087
+ } catch (err) {
3088
+ if (err.unauthorized) askToken(); else toast(T().failed);
3089
+ } finally {
3090
+ pageBusy = false;
3091
+ }
3092
+ }
3093
+ async function renderCards() {
3094
+ const gen = ++pageGen;
3095
+ const keep = keepPages && items.length > PAGE; keepPages = false;
3096
+ const y = keep ? scrollY : 0;
3097
+ const p = listParams();
3098
+ p.set("limit", String(keep ? Math.min(500, items.length) : PAGE));
3099
+ const meta = {};
3100
+ // Split view with the map's own unfiltered fetch in hand: the first page is already there.
3101
+ const shared = !keep && splitOn() && state.view === "all" && !state.q && !state.category && !state.kind && prefs.sort === "best" && mapItems.length && Number.isFinite(mapTotal);
3102
+ let got;
3103
+ if (shared) { got = mapItems.slice(0, PAGE).map((i) => ({ ...i })); meta.total = mapTotal; }
3104
+ else got = await api(`/api/items?${p}`, {}, meta);
3105
+ if (gen !== pageGen) return;
3106
+ items = got;
3107
+ pageTotal = Number.isFinite(meta.total) ? meta.total : items.length;
3108
+ pageHost = $("list");
3109
+ pageBusy = false;
3110
+ pageObserver?.disconnect();
2912
3111
  const t = T();
2913
- const empty = state.view === "trash" ? t.emptyTrash : state.view === "favorites" ? t.emptyFav : state.view === "inbox" ? t.emptyInbox : t.empty;
3112
+ const empty = state.view === "trash" ? t.emptyTrash : state.view === "favorites" ? t.emptyFav : state.view === "inbox" ? t.emptyInbox : state.view === "review" ? t.emptyReview : t.empty;
2914
3113
  $("list").innerHTML = items.length
2915
- ? `<p class="hint swipe-hint">${esc(state.view === "trash" ? t.hintTrash : state.view === "inbox" ? t.hintInbox : t.hint)}</p>` + items.map(card).join("")
3114
+ ? `<p class="hint swipe-hint">${esc(state.view === "trash" ? t.hintTrash : state.view === "inbox" ? t.hintInbox : state.view === "review" ? t.hintReview : t.hint)}</p>` + items.map(card).join("") + moreHtml()
2916
3115
  : `<div class="empty first"><span>${esc(empty)}</span>${state.view === "all" && !state.q && !state.category && role === "admin"
2917
3116
  ? `<form class="add" id="add-form"><input id="add-url" type="url" inputmode="url" placeholder="${esc(t.addPlaceholder)}" aria-label="${esc(t.addPlaceholder)}">
2918
3117
  <button class="btn primary" type="submit">${ic("plus")} ${esc(t.addLink)}</button></form>
2919
3118
  <button class="btn" type="button" data-connect-empty>${ic("plug")} ${esc(t.st.connect)}</button>${templateChooser(t)}` : ""}</div>`;
3119
+ watchMore();
3120
+ if (keep) scrollTo({ top: y });
2920
3121
  $("add-form")?.addEventListener("submit", addLink);
2921
3122
  for (const b of $("list").querySelectorAll("[data-template]")) b.addEventListener("click", () => pickTemplate(b.dataset.template));
2922
3123
  $("list").querySelector("[data-connect-empty]")?.addEventListener("click", () => openConnect());
@@ -2937,6 +3138,17 @@
2937
3138
  if (mdlDlg.open) paintModal();
2938
3139
  }
2939
3140
 
3141
+ /** ☠ dead / 🗄 archived / 💤 stale / ↪ moved: what the last link check found (nothing for ok or unchecked). */
3142
+ function healthBadge(i) {
3143
+ const h = T().health[i.health];
3144
+ return h ? `<span class="badge health ${esc(i.health)}" title="${esc(h[2])}" role="img" aria-label="${esc(h[2])}">${h[0]} ${esc(h[1])}</span>` : "";
3145
+ }
3146
+ /** ★ 1.2k for repos whose star count is known. */
3147
+ function starsHtml(i) {
3148
+ if (typeof i.stars !== "number") return "";
3149
+ const n = i.stars >= 1000 ? `${(i.stars / 1000).toFixed(i.stars >= 10000 ? 0 : 1).replace(/\.0$/, "")}k` : String(i.stars);
3150
+ return `<span class="stars" title="${esc(T().stars(i.stars))}">★ ${n}</span>`;
3151
+ }
2940
3152
  function card(i) {
2941
3153
  const s = i.summary;
2942
3154
  const t = T();
@@ -2962,13 +3174,14 @@
2962
3174
  <span class="badge folder" style="--c:${folderColor(i.category)}">${esc(catLabel(i.category))}</span>
2963
3175
  <span class="rating ${i.worth === "must-see" ? "must" : ""}">${i.worth === "must-see" ? ic("star") : ""}${esc(t.worth[i.worth] ?? i.worth)}</span>
2964
3176
  ${i.pending ? `<span class="rating">${esc(summaries ? t.pending : t.noModel)}</span>` : ""}
3177
+ ${healthBadge(i)}
2965
3178
  </div>
2966
3179
  ${s ? `<p>${esc(s.oneLiner)}</p>` : ""}
2967
3180
  ${s?.demo ? `<p class="demo">${esc(s.demo)}</p>` : ""}
2968
3181
  ${i.flags.length ? `<div class="flag">⚠ ${esc(i.flags.map((f) => t.flags[f] ?? f).join(", "))}</div>` : ""}
2969
3182
  ${state.view === "inbox" ? inboxChips(i) : ""}
2970
3183
  <div class="meta">
2971
- <span>#${i.id}</span><span>${esc(t.kind1?.[i.kind] ?? t.kinds[i.kind] ?? i.kind)}</span>${i.shareCount ? `<span>${esc(t.shared(i.shareCount))}</span>` : ""}
3184
+ <span>#${i.id}</span><span>${esc(t.kind1?.[i.kind] ?? t.kinds[i.kind] ?? i.kind)}</span>${starsHtml(i)}${i.shareCount ? `<span>${esc(t.shared(i.shareCount))}</span>` : ""}
2972
3185
  <span>${esc(i.createdAt.slice(0, 10))}</span>
2973
3186
  ${i.note ? `<span class="has-note" title="${esc(t.mdHasNote)}" role="img" aria-label="${esc(t.mdHasNote)}">${ic("note")}</span>` : ""}
2974
3187
  </div>
@@ -3048,14 +3261,15 @@
3048
3261
  if (el.contains(document.activeElement)) (el.nextElementSibling ?? el.previousElementSibling)?.querySelector?.(".card")?.focus();
3049
3262
  el.querySelector(".card").style.transform = `translateX(${action === "trash" ? "-110%" : "110%"})`;
3050
3263
  dismiss(el);
3264
+ forgetItem(id);
3051
3265
  const back = action === "trash" ? "restore" : "trash";
3052
- toast(action === "trash" ? t.removed(nameOf(item)) : t.restored(nameOf(item)), async () => { await act(id, back); load(); });
3266
+ toast(action === "trash" ? t.removed(nameOf(item)) : t.restored(nameOf(item)), async () => { await act(id, back); keepPages = true; load(); });
3053
3267
  } else {
3054
3268
  const on = !item.favorite;
3055
3269
  if (!(await act(id, on ? "favorite" : "unfavorite"))) return;
3056
3270
  item.favorite = on;
3057
3271
  const hadFocus = el.contains(document.activeElement);
3058
- if (state.view === "favorites" && !on) dismiss(el);
3272
+ if (state.view === "favorites" && !on) { dismiss(el); forgetItem(id); }
3059
3273
  else { el.outerHTML = card(item); attachSwipe(document.getElementById(`item-${id}`)); if (hadFocus) document.querySelector(`#item-${id} .card`)?.focus(); }
3060
3274
  if (on) toast(t.faved(nameOf(item)));
3061
3275
  }
@@ -3070,6 +3284,19 @@
3070
3284
  if (mapShown()) drawMap();
3071
3285
  if (modalId === id && mdlDlg.open) paintModal();
3072
3286
  }
3287
+ /** Test one card's link right now (the weekly job does this in batches). */
3288
+ async function checkLink(id) {
3289
+ const item = find(id);
3290
+ if (!item) return;
3291
+ const token = store.get("driftnet-token");
3292
+ const res = await fetch(`/api/items/${id}/health`, { method: "POST", headers: token ? { authorization: `Bearer ${token}` } : {} }).catch(() => null);
3293
+ if (res?.status === 401) return needAdmin();
3294
+ if (!res?.ok) return toast(T().linkCheckFailed);
3295
+ Object.assign(item, await res.json().catch(() => ({})));
3296
+ toast(T().linkChecked);
3297
+ repaintItem(id);
3298
+ refreshCounts();
3299
+ }
3073
3300
  async function refreshItem(id) {
3074
3301
  const item = find(id);
3075
3302
  if (!item || refreshing.has(id)) return;
@@ -3097,7 +3324,7 @@
3097
3324
  if (!stats) return;
3098
3325
  $("stats").textContent = T().stats(stats.items, stats.shares);
3099
3326
  const set = (v, n) => { const c = $("nav").querySelector(`[data-field="view"][data-value="${v}"] .count`); if (c) c.textContent = n || (v === "all" ? "0" : ""); };
3100
- set("all", stats.items); set("favorites", stats.favorites); set("trash", stats.trash); set("inbox", stats.inbox);
3327
+ set("all", stats.items); set("favorites", stats.favorites); set("trash", stats.trash); set("inbox", stats.inbox); set("review", stats.review);
3101
3328
  }
3102
3329
 
3103
3330
  // ── Select several cards: x, Shift-click or a long press; then act on all of them ──
@@ -3163,7 +3390,7 @@
3163
3390
  if (!r) return;
3164
3391
  clearSelection();
3165
3392
  await refreshFolders();
3166
- await render();
3393
+ await renderKeep();
3167
3394
  refreshCounts();
3168
3395
  if (action === "move" && state.view === "map") pulse(`f:${folder}`);
3169
3396
  const text = { move: () => t.bulkMoved(n, folderPath(folder)), trash: () => t.bulkRemoved(n), restore: () => t.bulkRestored(n),
@@ -3171,7 +3398,7 @@
3171
3398
  toast(text, async () => {
3172
3399
  if (!(await mapWrite("/api/items/bulk/undo", "POST", { undo: r.undo }))) return;
3173
3400
  await refreshFolders();
3174
- await render();
3401
+ await renderKeep();
3175
3402
  refreshCounts();
3176
3403
  });
3177
3404
  }