driftnet 0.0.0-stage → 0.1.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/.env.example +87 -0
- package/LICENSE +21 -0
- package/README.md +381 -2
- package/README.zh-TW.md +356 -0
- package/dist/driftnet.mjs +3553 -0
- package/examples/plugins/hackernews.mjs +27 -0
- package/package.json +42 -4
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon.svg +17 -0
- package/public/icon-512.png +0 -0
- package/public/index.html +1145 -0
- package/public/manifest.webmanifest +14 -0
|
@@ -0,0 +1,1145 @@
|
|
|
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, viewport-fit=cover">
|
|
6
|
+
<meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
|
|
7
|
+
<meta name="theme-color" content="#1b1b1a" media="(prefers-color-scheme: dark)">
|
|
8
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
9
|
+
<meta name="apple-mobile-web-app-title" content="driftnet">
|
|
10
|
+
<title>driftnet</title>
|
|
11
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
12
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
|
13
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
14
|
+
<style>
|
|
15
|
+
:root {
|
|
16
|
+
--bg: #f7f7f5; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e4e4df;
|
|
17
|
+
--accent: #2f6fdb; --accent-soft: #e8effc; --warn: #b4540a; --star: #c58a00; --star-soft: #fff4d6;
|
|
18
|
+
--danger: #c62828; --danger-soft: #fde8e8; --ok: #2e7d32; --ok-soft: #e6f4ea;
|
|
19
|
+
font-family: ui-sans-serif, system-ui, -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
|
|
20
|
+
}
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
:root:not([data-theme="light"]) { --bg: #121211; --panel: #1b1b1a; --text: #ececea; --muted: #9a9a94; --line: #2d2d2b;
|
|
23
|
+
--accent: #7aa7ff; --accent-soft: #1e2a40; --warn: #f0a050; --star: #f2c14e; --star-soft: #3a3016;
|
|
24
|
+
--danger: #ef9a9a; --danger-soft: #3b1d1d; --ok: #81c784; --ok-soft: #1d3322; }
|
|
25
|
+
}
|
|
26
|
+
:root[data-theme="dark"] { --bg: #121211; --panel: #1b1b1a; --text: #ececea; --muted: #9a9a94; --line: #2d2d2b;
|
|
27
|
+
--accent: #7aa7ff; --accent-soft: #1e2a40; --warn: #f0a050; --star: #f2c14e; --star-soft: #3a3016;
|
|
28
|
+
--danger: #ef9a9a; --danger-soft: #3b1d1d; --ok: #81c784; --ok-soft: #1d3322; color-scheme: dark; }
|
|
29
|
+
:root[data-theme="light"] { color-scheme: light; }
|
|
30
|
+
* { box-sizing: border-box; }
|
|
31
|
+
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
|
|
32
|
+
button { font: inherit; color: inherit; }
|
|
33
|
+
|
|
34
|
+
header { display: flex; gap: 12px 16px; align-items: center; padding: 12px 20px; padding-top: max(12px, env(safe-area-inset-top));
|
|
35
|
+
border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 3; flex-wrap: wrap; }
|
|
36
|
+
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; margin: 0; letter-spacing: -0.01em; }
|
|
37
|
+
.stats { color: var(--muted); font-size: 13px; }
|
|
38
|
+
.search { flex: 1; min-width: 180px; max-width: 420px; margin-left: auto; padding: 9px 12px; border: 1px solid var(--line);
|
|
39
|
+
border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
|
|
40
|
+
.lang { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 13px; cursor: pointer; min-height: 40px; }
|
|
41
|
+
|
|
42
|
+
.layout { display: grid; grid-template-columns: 256px 1fr; max-width: 1200px; margin: 0 auto; }
|
|
43
|
+
nav { padding: 16px 12px; border-right: 1px solid var(--line); position: sticky; top: 65px; align-self: start; max-height: calc(100vh - 65px); overflow: auto; }
|
|
44
|
+
nav .row { display: contents; }
|
|
45
|
+
nav button { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0;
|
|
46
|
+
border-radius: 8px; background: none; text-align: left; cursor: pointer; }
|
|
47
|
+
nav button:hover { background: var(--accent-soft); }
|
|
48
|
+
nav button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
|
49
|
+
nav .count { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
|
|
50
|
+
nav h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 10px 6px; }
|
|
51
|
+
|
|
52
|
+
/* The reader's folder tree. */
|
|
53
|
+
nav .folders-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 6px 10px; }
|
|
54
|
+
nav .folders-head h2 { margin: 0; }
|
|
55
|
+
nav .icon { width: 30px; min-width: 30px; height: 30px; padding: 0; justify-content: center; color: var(--muted); flex: none; font-size: 15px; }
|
|
56
|
+
nav .icon:hover, nav .icon:focus-visible { color: var(--text); }
|
|
57
|
+
nav .folder { display: flex; align-items: center; gap: 0; padding-left: calc(var(--depth) * 12px); border-radius: 8px; }
|
|
58
|
+
nav .folder > [data-field] { flex: 1; min-width: 0; padding-left: 4px; }
|
|
59
|
+
nav .folder > [data-field] > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
60
|
+
nav .twist { transition: transform .15s ease; font-size: 10px; width: 22px; min-width: 22px; }
|
|
61
|
+
nav .folder .more { width: 26px; min-width: 26px; }
|
|
62
|
+
nav .twist[aria-expanded="true"] { transform: rotate(90deg); }
|
|
63
|
+
nav .twist.leaf { visibility: hidden; }
|
|
64
|
+
nav .folder .more { opacity: 0; }
|
|
65
|
+
nav .folder:hover .more, nav .folder .more:focus-visible, nav .folder:has([aria-pressed="true"]) .more { opacity: 1; }
|
|
66
|
+
@media (hover: none) { nav .folder .more { opacity: 1; } }
|
|
67
|
+
nav .drop-over { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }
|
|
68
|
+
nav .folder.dragged { opacity: .45; }
|
|
69
|
+
|
|
70
|
+
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 18px;
|
|
71
|
+
width: min(420px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.3); }
|
|
72
|
+
dialog::backdrop { background: rgba(0,0,0,.35); }
|
|
73
|
+
dialog h3 { margin: 0 0 12px; font-size: 17px; }
|
|
74
|
+
dialog label { display: grid; gap: 4px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
|
|
75
|
+
dialog input, dialog textarea, dialog select { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
|
|
76
|
+
border-radius: 10px; padding: 9px 11px; width: 100%; }
|
|
77
|
+
dialog textarea { resize: vertical; }
|
|
78
|
+
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
|
|
79
|
+
.dlg-actions .spacer { flex: 1; }
|
|
80
|
+
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 14px; min-height: 40px; cursor: pointer; }
|
|
81
|
+
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); font-weight: 600; }
|
|
82
|
+
.btn.danger { color: var(--danger); }
|
|
83
|
+
.btn.danger.armed { background: var(--danger); border-color: var(--danger); color: var(--panel); }
|
|
84
|
+
.dlg-error { color: var(--danger); font-size: 13px; margin: 0 0 8px; }
|
|
85
|
+
.dlg-error:empty { display: none; }
|
|
86
|
+
.pick { display: grid; gap: 2px; max-height: min(60vh, 460px); overflow: auto; margin: 0 -6px 12px; }
|
|
87
|
+
.pick button { display: flex; justify-content: space-between; gap: 8px; border: 0; background: none; text-align: left; border-radius: 8px;
|
|
88
|
+
padding: 9px 10px 9px calc(10px + var(--depth) * 16px); min-height: 42px; cursor: pointer; }
|
|
89
|
+
.pick button:hover, .pick button:focus-visible { background: var(--accent-soft); }
|
|
90
|
+
.pick button[aria-current="true"] { color: var(--accent); font-weight: 600; }
|
|
91
|
+
.pick .count { color: var(--muted); font-weight: 400; }
|
|
92
|
+
|
|
93
|
+
.found { font-size: 13px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
|
|
94
|
+
.found a { color: var(--accent); text-decoration: none; background: var(--accent-soft); border-radius: 99px; padding: 1px 9px; }
|
|
95
|
+
.found a:hover { text-decoration: underline; }
|
|
96
|
+
.said { margin: 8px 0 2px; padding: 6px 10px; border-left: 3px solid var(--line); color: var(--muted); font-size: 14px; white-space: pre-wrap; }
|
|
97
|
+
.said::before { content: "💬 "; }
|
|
98
|
+
.mynote { margin: 8px 0 2px; padding: 8px 10px; border-radius: 8px; background: var(--star-soft); font-size: 14px; white-space: pre-wrap; }
|
|
99
|
+
.mynote::before { content: "📝 "; }
|
|
100
|
+
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; padding: 0; cursor: pointer; }
|
|
101
|
+
.link-btn:hover { text-decoration: underline; }
|
|
102
|
+
nav .foot { display: grid; gap: 2px; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
|
|
103
|
+
nav .foot button { color: var(--muted); font-size: 14px; }
|
|
104
|
+
.note-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; cursor: pointer; text-align: left;
|
|
105
|
+
font: inherit; color: inherit; width: 100%; }
|
|
106
|
+
.note-card:hover { border-color: var(--accent); }
|
|
107
|
+
.note-card h3 { margin: 0 0 4px; font-size: 16px; }
|
|
108
|
+
.note-card .md { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
|
|
109
|
+
.md h1, .md h2, .md h3 { font-size: 15px; margin: 8px 0 4px; }
|
|
110
|
+
.md p { margin: 4px 0; }
|
|
111
|
+
.md ul { margin: 4px 0; padding-left: 20px; }
|
|
112
|
+
.md blockquote { margin: 4px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
|
|
113
|
+
.md code { background: var(--bg); border-radius: 4px; padding: 0 4px; font-size: 13px; }
|
|
114
|
+
.md pre { background: var(--bg); border-radius: 8px; padding: 8px 10px; overflow: auto; font-size: 13px; }
|
|
115
|
+
.md a { color: var(--accent); }
|
|
116
|
+
.bar { display: flex; gap: 8px; align-items: center; }
|
|
117
|
+
.bar .spacer { flex: 1; }
|
|
118
|
+
dialog.wide { width: min(720px, calc(100vw - 32px)); }
|
|
119
|
+
#nd-body { min-height: 40vh; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
|
|
120
|
+
body.compact .card ul, body.compact .said, body.compact .card .found { display: none; }
|
|
121
|
+
body.compact .card { padding-top: 10px; padding-bottom: 10px; }
|
|
122
|
+
body.compact .card p { margin: 2px 0; }
|
|
123
|
+
body.hide-tags .meta .tags, body.hide-said .said { display: none; }
|
|
124
|
+
.set-group { border: 0; padding: 0; margin: 0 0 16px; }
|
|
125
|
+
.set-group legend { font-weight: 650; font-size: 14px; margin-bottom: 8px; padding: 0; }
|
|
126
|
+
.set-row { display: grid; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
|
|
127
|
+
.set-row.check { grid-template-columns: auto 1fr; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
|
|
128
|
+
.set-row.check input { width: 18px; height: 18px; }
|
|
129
|
+
.set-row small { color: var(--muted); }
|
|
130
|
+
.set-status { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-bottom: 14px; }
|
|
131
|
+
.set-scroll { max-height: min(70vh, 640px); overflow: auto; margin: 0 -18px; padding: 0 18px; }
|
|
132
|
+
.welcome { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
|
|
133
|
+
.tool.grip { cursor: grab; display: none; }
|
|
134
|
+
@media (hover: hover) and (pointer: fine) { .tool.grip { display: grid; } }
|
|
135
|
+
|
|
136
|
+
.menu { display: none; width: 44px; height: 44px; margin: -4px 0 -4px -8px; border: 0; border-radius: 10px; background: none; cursor: pointer;
|
|
137
|
+
place-items: center; color: var(--text); }
|
|
138
|
+
.menu:hover, .menu:focus-visible { background: var(--bg); }
|
|
139
|
+
.scrim, .drawer-head, .crumb { display: none; }
|
|
140
|
+
.drawer-head { align-items: center; justify-content: space-between; padding: 2px 4px 10px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
|
|
141
|
+
.drawer-head .brand { font-size: 17px; }
|
|
142
|
+
.crumb { align-items: center; gap: 8px; width: 100%; border: 0; border-bottom: 1px solid var(--line); background: var(--bg); color: var(--muted);
|
|
143
|
+
font-size: 13px; padding: 9px 16px; text-align: left; cursor: pointer; }
|
|
144
|
+
.crumb b { color: var(--accent); font-weight: 600; }
|
|
145
|
+
main { padding: 16px 20px 48px; display: grid; gap: 12px; align-content: start; }
|
|
146
|
+
.hint { color: var(--muted); font-size: 13px; margin: -4px 2px 0; }
|
|
147
|
+
|
|
148
|
+
/* A card sits on top of two action strips that show while it is dragged. */
|
|
149
|
+
.swipe { position: relative; border-radius: 12px; overflow: hidden; scroll-margin-top: 90px; transition: height .25s ease, margin .25s ease, opacity .25s ease; }
|
|
150
|
+
.swipe.gone { opacity: 0; }
|
|
151
|
+
.act { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 22px; font-weight: 600; font-size: 14px; }
|
|
152
|
+
.act.right { justify-content: flex-start; background: var(--star-soft); color: var(--star); }
|
|
153
|
+
.act.left { justify-content: flex-end; background: var(--danger-soft); color: var(--danger); }
|
|
154
|
+
.act.restore { background: var(--ok-soft); color: var(--ok); }
|
|
155
|
+
.swipe[data-dir="right"] .act.left, .swipe[data-dir="left"] .act.right, .swipe:not([data-dir]) .act { visibility: hidden; }
|
|
156
|
+
.swipe.armed .act { filter: saturate(1.6); }
|
|
157
|
+
.swipe.armed .act span { transform: scale(1.12); }
|
|
158
|
+
.act span { transition: transform .15s ease; }
|
|
159
|
+
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
|
|
160
|
+
touch-action: pan-y; user-select: none; -webkit-user-select: none; transition: transform .22s ease; }
|
|
161
|
+
.card.dragging { transition: none; }
|
|
162
|
+
.swipe:target .card { outline: 2px solid var(--accent); outline-offset: -2px; }
|
|
163
|
+
.top { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding-right: 168px; }
|
|
164
|
+
a.name { color: var(--text); font-weight: 650; font-size: 16px; text-decoration: none; }
|
|
165
|
+
a.name:hover { color: var(--accent); }
|
|
166
|
+
.badge { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
|
|
167
|
+
.worth-must-see { color: var(--star); }
|
|
168
|
+
.card p { margin: 6px 0; }
|
|
169
|
+
.card ul { margin: 6px 0; padding-left: 20px; }
|
|
170
|
+
.meta { color: var(--muted); font-size: 13px; display: flex; gap: 4px 12px; flex-wrap: wrap; }
|
|
171
|
+
.flag { color: var(--warn); font-size: 13px; }
|
|
172
|
+
.tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px; }
|
|
173
|
+
.tool { width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; cursor: pointer; font-size: 18px; line-height: 1;
|
|
174
|
+
display: grid; place-items: center; color: var(--muted); }
|
|
175
|
+
.tool:hover, .tool:focus-visible { background: var(--bg); color: var(--text); }
|
|
176
|
+
.tool.on { color: var(--star); }
|
|
177
|
+
.empty { color: var(--muted); padding: 48px 0; text-align: center; }
|
|
178
|
+
|
|
179
|
+
.toast { position: fixed; left: 50%; bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px)); transform: translate(-50%, 140%);
|
|
180
|
+
background: var(--text); color: var(--panel); border-radius: 12px; padding: 10px 10px 10px 16px; display: flex; gap: 14px;
|
|
181
|
+
align-items: center; box-shadow: 0 6px 24px rgba(0,0,0,.25); transition: transform .25s ease; z-index: 5;
|
|
182
|
+
width: max-content; max-width: min(520px, calc(100vw - 32px)); }
|
|
183
|
+
.toast span { flex: 1; min-width: 0; }
|
|
184
|
+
.toast.show { transform: translate(-50%, 0); }
|
|
185
|
+
.toast button { border: 0; background: none; color: var(--accent-soft); font-weight: 650; padding: 8px 10px; border-radius: 8px; cursor: pointer;
|
|
186
|
+
min-height: 40px; white-space: nowrap; flex-shrink: 0; }
|
|
187
|
+
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast button { color: var(--accent); } }
|
|
188
|
+
:root[data-theme="dark"] .toast button { color: var(--accent); }
|
|
189
|
+
|
|
190
|
+
@media (max-width: 720px) {
|
|
191
|
+
header { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); gap: 8px 10px; }
|
|
192
|
+
.stats { display: none; }
|
|
193
|
+
.lang { margin-left: auto; }
|
|
194
|
+
.search { order: 3; flex-basis: 100%; max-width: none; margin: 0; font-size: 16px; /* 16px: iOS doesn't zoom in */ }
|
|
195
|
+
.layout { grid-template-columns: 1fr; }
|
|
196
|
+
/* The sidebar becomes a drawer behind the ☰ button. */
|
|
197
|
+
.menu { display: grid; }
|
|
198
|
+
nav { position: fixed; top: 0; bottom: 0; left: 0; z-index: 10; width: min(300px, 84vw); max-height: none; border-right: 1px solid var(--line);
|
|
199
|
+
background: var(--panel); padding: max(12px, env(safe-area-inset-top)) 10px calc(20px + env(safe-area-inset-bottom));
|
|
200
|
+
transform: translateX(-102%); visibility: hidden; box-shadow: 8px 0 30px rgba(0,0,0,.18);
|
|
201
|
+
transition: transform .25s ease, visibility 0s linear .25s; /* hide only after sliding out */ }
|
|
202
|
+
body.menu-open nav { transform: none; visibility: visible; transition: transform .25s ease; }
|
|
203
|
+
body.menu-open { overflow: hidden; }
|
|
204
|
+
.scrim { display: block; position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
|
|
205
|
+
body.menu-open .scrim { opacity: 1; pointer-events: auto; }
|
|
206
|
+
.drawer-head { display: flex; }
|
|
207
|
+
nav button { min-height: 44px; }
|
|
208
|
+
.crumb { display: flex; }
|
|
209
|
+
main { padding: 12px 12px calc(40px + env(safe-area-inset-bottom)); gap: 10px; }
|
|
210
|
+
.card { padding: 13px 14px; }
|
|
211
|
+
.top { padding-right: 0; }
|
|
212
|
+
.tools { position: static; justify-content: flex-end; margin: 4px -6px -8px 0; }
|
|
213
|
+
.card ul { padding-left: 18px; }
|
|
214
|
+
}
|
|
215
|
+
@media (prefers-reduced-motion: reduce) { .card, .swipe, .toast, nav, .scrim, nav .twist { transition: none; } }
|
|
216
|
+
</style>
|
|
217
|
+
</head>
|
|
218
|
+
<body>
|
|
219
|
+
<header>
|
|
220
|
+
<button id="menu" class="menu" type="button" aria-controls="nav" aria-expanded="false">
|
|
221
|
+
<svg width="22" height="22" viewBox="0 0 22 22" aria-hidden="true"><path d="M3 6h16M3 11h16M3 16h16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
|
|
222
|
+
</button>
|
|
223
|
+
<h1 class="brand"><img src="/favicon.svg" alt="" width="26" height="26">driftnet</h1>
|
|
224
|
+
<span class="stats" id="stats"></span>
|
|
225
|
+
<input id="q" class="search" type="search" enterkeyhint="search">
|
|
226
|
+
<button id="lang" class="lang" type="button"></button>
|
|
227
|
+
</header>
|
|
228
|
+
<button id="crumb" class="crumb" type="button" aria-controls="nav"></button>
|
|
229
|
+
<div class="scrim" id="scrim"></div>
|
|
230
|
+
<div class="layout">
|
|
231
|
+
<nav id="nav"></nav>
|
|
232
|
+
<main id="list" aria-live="polite"></main>
|
|
233
|
+
</div>
|
|
234
|
+
<dialog id="folder-dlg">
|
|
235
|
+
<form id="folder-form" method="dialog">
|
|
236
|
+
<h3 id="fd-title"></h3>
|
|
237
|
+
<p class="dlg-error" id="fd-error"></p>
|
|
238
|
+
<label><span id="fd-name-l"></span><input id="fd-name" maxlength="60" autocomplete="off"></label>
|
|
239
|
+
<label><span id="fd-desc-l"></span><textarea id="fd-desc" rows="2" maxlength="300"></textarea></label>
|
|
240
|
+
<label><span id="fd-parent-l"></span><select id="fd-parent"></select></label>
|
|
241
|
+
<div class="dlg-actions">
|
|
242
|
+
<button class="btn danger" id="fd-delete" type="button"></button><span class="spacer"></span>
|
|
243
|
+
<button class="btn" id="fd-cancel" type="button"></button><button class="btn primary" id="fd-save" type="submit"></button>
|
|
244
|
+
</div>
|
|
245
|
+
</form>
|
|
246
|
+
</dialog>
|
|
247
|
+
<dialog id="move-dlg">
|
|
248
|
+
<h3 id="mv-title"></h3>
|
|
249
|
+
<div class="pick" id="mv-list"></div>
|
|
250
|
+
<div class="dlg-actions"><span class="spacer"></span><button class="btn" id="mv-cancel" type="button"></button></div>
|
|
251
|
+
</dialog>
|
|
252
|
+
<dialog id="settings-dlg" class="wide">
|
|
253
|
+
<form id="settings-form" method="dialog">
|
|
254
|
+
<h3 id="st-title"></h3>
|
|
255
|
+
<p class="dlg-error" id="st-error"></p>
|
|
256
|
+
<div class="set-scroll" id="st-body"></div>
|
|
257
|
+
<div class="dlg-actions"><span class="spacer"></span>
|
|
258
|
+
<button class="btn" id="st-cancel" type="button"></button><button class="btn primary" id="st-save" type="submit"></button></div>
|
|
259
|
+
</form>
|
|
260
|
+
</dialog>
|
|
261
|
+
<dialog id="note-dlg">
|
|
262
|
+
<form id="note-form" method="dialog">
|
|
263
|
+
<h3 id="in-title"></h3>
|
|
264
|
+
<label><span id="in-help"></span><textarea id="in-text" rows="5" maxlength="5000"></textarea></label>
|
|
265
|
+
<div class="dlg-actions"><span class="spacer"></span>
|
|
266
|
+
<button class="btn" id="in-cancel" type="button"></button><button class="btn primary" id="in-save" type="submit"></button></div>
|
|
267
|
+
</form>
|
|
268
|
+
</dialog>
|
|
269
|
+
<dialog id="notes-dlg" class="wide">
|
|
270
|
+
<form id="nd-form" method="dialog">
|
|
271
|
+
<p class="dlg-error" id="nd-error"></p>
|
|
272
|
+
<label><span id="nd-title-l"></span><input id="nd-title" maxlength="200" autocomplete="off"></label>
|
|
273
|
+
<label><span id="nd-body-l"></span><textarea id="nd-body" maxlength="100000"></textarea></label>
|
|
274
|
+
<div class="dlg-actions">
|
|
275
|
+
<button class="btn danger" id="nd-delete" type="button"></button><span class="spacer"></span>
|
|
276
|
+
<button class="btn" id="nd-cancel" type="button"></button><button class="btn primary" id="nd-save" type="submit"></button>
|
|
277
|
+
</div>
|
|
278
|
+
</form>
|
|
279
|
+
</dialog>
|
|
280
|
+
<div class="toast" id="toast" role="status"><span id="toast-text"></span><button id="toast-undo" type="button"></button></div>
|
|
281
|
+
<script>
|
|
282
|
+
const STRINGS = {
|
|
283
|
+
en: {
|
|
284
|
+
search: "Search tools, tags, links…", all: "All", favorites: "Favorites", trash: "Trash", any: "Any",
|
|
285
|
+
kind: "Kind", switchTo: "中文", nav: "Views and categories",
|
|
286
|
+
stats: (n, s) => `${n} items · shared ${s}×`, shared: (n) => `shared ${n}×`,
|
|
287
|
+
empty: "Nothing here yet — drop a link in your chat.", emptyFav: "No favorites yet — swipe a card right, or tap ☆.",
|
|
288
|
+
emptyTrash: "The trash is empty.", hint: "Swipe right to favorite, left to remove.", hintTrash: "Swipe right to restore.",
|
|
289
|
+
kinds: { repo: "Repos", product: "Products", video: "Videos", article: "Articles", post: "Posts", other: "Other" },
|
|
290
|
+
worth: { skip: "skip", low: "low", normal: "worth a look", "must-see": "★ must-see" },
|
|
291
|
+
flags: { injection: "prompt injection", "hidden-chars": "hidden characters", "low-reputation": "low-reputation source" },
|
|
292
|
+
pending: "⏳ waiting for a summary", enrichedBy: (a) => `summary by ${a}`,
|
|
293
|
+
favorite: "Add to favorites", unfavorite: "Remove from favorites", remove: "Move to trash", restore: "Restore",
|
|
294
|
+
swipeFav: "☆ Favorite", swipeUnfav: "★ Unfavorite", swipeTrash: "Remove 🗑", swipeRestore: "↩ Restore",
|
|
295
|
+
removed: (n) => `“${n}” moved to the trash`, restored: (n) => `“${n}” restored`, faved: (n) => `★ “${n}” added to favorites`,
|
|
296
|
+
undo: "Undo", tokenPrompt: "This catalogue is private. Enter its token (DRIFTNET_TOKEN).", tokenSave: "Open",
|
|
297
|
+
failed: "Couldn't save — check your connection.", menu: "Menu", close: "Close menu", showing: "Showing:",
|
|
298
|
+
folders: "Folders", newFolder: "New folder", newSub: "New folder inside", editFolder: "Edit folder", folderName: "Name",
|
|
299
|
+
folderDesc: "What goes here? (driftnet's AI reads this to sort new links)", folderParent: "Inside", topLevel: "— Top level —",
|
|
300
|
+
save: "Save", cancel: "Cancel", del: "Delete folder", delSure: "Delete — its links move up",
|
|
301
|
+
moveTo: "Move to…", moveTitle: (n) => `Move “${n}” to`, moved: (n, f) => `Moved “${n}” to ${f}`, expand: "Show sub-folders",
|
|
302
|
+
dragHint: "Drag onto a folder in the sidebar", foundIn: "Found in this post:", folderMoved: (n, f) => `“${n}” is now inside ${f}`,
|
|
303
|
+
topLevelShort: "the top level",
|
|
304
|
+
notes: "Notes", note: "Note", addNote: "📝 Add a note", editNote: "📝 Edit note", noteFor: (n) => `Note on “${n}”`,
|
|
305
|
+
noteHelp: "Only for you: what you thought, whether you tried it…", newNote: "+ New note", noteTitle: "Title",
|
|
306
|
+
noteBody: "Markdown. Write #12 to link card 12.", delNote: "Delete note", delNoteSure: "Really delete?", untitled: "Untitled",
|
|
307
|
+
emptyNotes: "No notes yet. Notes can link cards: write #12.", exportMd: "⬇ Export Markdown", exportVault: "⬇ Export for Obsidian / Notion",
|
|
308
|
+
saved: "Saved", settings: "⚙ Settings",
|
|
309
|
+
st: {
|
|
310
|
+
title: "Settings", save: "Save", welcome: "Welcome! Pick a model below (or none: Jev and the built-in rules still sort links), then drop a link in.",
|
|
311
|
+
display: "This browser", sort: "Order", sorts: { best: "Best first", newest: "Newest first", shared: "Most shared first" },
|
|
312
|
+
compact: "Compact cards (one line each)", tags: "Show tags", said: "Show what people said in chat",
|
|
313
|
+
theme: "Theme", themes: { auto: "Follow the system", light: "Light", dark: "Dark" },
|
|
314
|
+
model: "Model & classifier", language: "Language & chat replies", rules: "Your rules",
|
|
315
|
+
plugins: "Plugins", pluginsNone: (dir) => `No plugins. Put .js files in ${dir} — see examples/plugins in the repo.`,
|
|
316
|
+
status: (e) => `Now: sorting by ${({ jev: "Jev", llm: "the model", heuristic: "built-in rules" })[e.judge] ?? e.judge}, summaries by ${e.summarizer === "off" ? "nobody (off)" : e.summarizer}`, keep: "set — leave empty to keep", unset: "not set",
|
|
317
|
+
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.",
|
|
318
|
+
savedServer: "Saved — already in effect",
|
|
319
|
+
labels: {
|
|
320
|
+
DRIFTNET_LLM_PROVIDER: ["Model provider", "Summaries. None: links are still sorted, only without a summary."],
|
|
321
|
+
DRIFTNET_LLM_MODEL: ["Model", "e.g. claude-haiku-5-5, gpt-5-mini, gemini-3.8-flash, qwen3"],
|
|
322
|
+
DRIFTNET_LLM_BASE_URL: ["API URL", "For OpenAI-compatible APIs: Gemini, Grok, OpenRouter, Ollama (http://127.0.0.1:11434/v1)…"],
|
|
323
|
+
DRIFTNET_LLM_API_KEY: ["API key", ""],
|
|
324
|
+
DRIFTNET_LLM_EFFORT: ["Reasoning effort", ""],
|
|
325
|
+
TYPESAFE_API_KEY: ["Jev key", "Optional: a ~100 ms classifier that saves model calls (console.typesafe.ai)"],
|
|
326
|
+
DRIFTNET_JUDGE: ["Jev", ""],
|
|
327
|
+
GITHUB_TOKEN: ["GitHub token", "Optional: GitHub lookups go from 60 to 5000 an hour"],
|
|
328
|
+
DRIFTNET_LANGUAGE: ["Summary language", "English, Traditional Chinese (Taiwan), Japanese…"],
|
|
329
|
+
DRIFTNET_LOCALE: ["Bot language", ""],
|
|
330
|
+
DRIFTNET_REPLY: ["Chat replies", ""],
|
|
331
|
+
DRIFTNET_PUBLIC_URL: ["This page's public URL", "Replies link here, e.g. https://driftnet.example.com"],
|
|
332
|
+
DRIFTNET_SUMMARY_RULES: ["Extra rules for summaries", "e.g. Say whether it's free. Mention if it needs a GPU."],
|
|
333
|
+
DRIFTNET_BLOCK_DOMAINS: ["Never catalogue these domains", "Comma or space separated, e.g. example.com, spam.io"],
|
|
334
|
+
},
|
|
335
|
+
choices: {
|
|
336
|
+
DRIFTNET_LLM_PROVIDER: { "": "None", anthropic: "Anthropic (API key)", openai: "OpenAI-compatible (OpenAI, Gemini, Grok, Ollama…)", "claude-cli": "Claude subscription (Claude Code CLI)", "gemini-cli": "Google account (Gemini CLI)" },
|
|
337
|
+
DRIFTNET_LLM_EFFORT: { "": "Default", low: "Low", medium: "Medium", high: "High" },
|
|
338
|
+
DRIFTNET_JUDGE: { "": "On when a key is set", off: "Off" },
|
|
339
|
+
DRIFTNET_LOCALE: { "": "Same as the summaries", en: "English", "zh-TW": "繁體中文" },
|
|
340
|
+
DRIFTNET_REPLY: { "": "One line + link (default)", link: "One line + link", full: "Full summary", off: "Don't reply" },
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
"zh-TW": {
|
|
345
|
+
search: "搜尋工具、標籤、連結…", all: "全部", favorites: "最愛", trash: "垃圾桶", any: "不限",
|
|
346
|
+
kind: "類型", switchTo: "EN", nav: "檢視與分類",
|
|
347
|
+
stats: (n, s) => `${n} 則 · 分享 ${s} 次`, shared: (n) => `分享 ${n} 次`,
|
|
348
|
+
empty: "還沒有內容,把連結丟進聊天室吧。", emptyFav: "還沒有最愛,把卡片往右滑或按 ☆。",
|
|
349
|
+
emptyTrash: "垃圾桶是空的。", hint: "往右滑加入最愛,往左滑移到垃圾桶。", hintTrash: "往右滑還原。",
|
|
350
|
+
kinds: { repo: "程式庫", product: "產品", video: "影片", article: "文章", post: "貼文", other: "其他" },
|
|
351
|
+
worth: { skip: "略過", low: "普通", normal: "值得看", "must-see": "★ 必看" },
|
|
352
|
+
flags: { injection: "提示詞注入", "hidden-chars": "隱藏字元", "low-reputation": "低信譽來源" },
|
|
353
|
+
pending: "⏳ 等待摘要", enrichedBy: (a) => `由 ${a} 整理`,
|
|
354
|
+
favorite: "加入最愛", unfavorite: "移出最愛", remove: "移到垃圾桶", restore: "還原",
|
|
355
|
+
swipeFav: "☆ 加入最愛", swipeUnfav: "★ 移出最愛", swipeTrash: "移到垃圾桶 🗑", swipeRestore: "↩ 還原",
|
|
356
|
+
removed: (n) => `已將「${n}」移到垃圾桶`, restored: (n) => `已還原「${n}」`, faved: (n) => `★ 已將「${n}」加入最愛`,
|
|
357
|
+
undo: "復原", tokenPrompt: "這份清單是私人的,請輸入 token(DRIFTNET_TOKEN)。", tokenSave: "開啟",
|
|
358
|
+
failed: "沒有存成功,請檢查網路。", menu: "選單", close: "關閉選單", showing: "目前顯示:",
|
|
359
|
+
folders: "資料夾", newFolder: "新資料夾", newSub: "在裡面新增資料夾", editFolder: "編輯資料夾", folderName: "名稱",
|
|
360
|
+
folderDesc: "放什麼?(driftnet 的 AI 會照這段說明把新連結分進來)", folderParent: "放在", topLevel: "— 最上層 —",
|
|
361
|
+
save: "儲存", cancel: "取消", del: "刪除資料夾", delSure: "確定刪除(內容會移到上一層)",
|
|
362
|
+
moveTo: "移動到…", moveTitle: (n) => `把「${n}」移動到`, moved: (n, f) => `已將「${n}」移到 ${f}`, expand: "展開子資料夾",
|
|
363
|
+
dragHint: "拖到側邊欄的資料夾", foundIn: "從這篇找到:", folderMoved: (n, f) => `「${n}」已移到 ${f} 底下`,
|
|
364
|
+
topLevelShort: "最上層",
|
|
365
|
+
notes: "筆記", note: "筆記", addNote: "📝 加筆記", editNote: "📝 改筆記", noteFor: (n) => `「${n}」的筆記`,
|
|
366
|
+
noteHelp: "只有你看得到:心得、試用結果、要注意的地方…", newNote: "+ 新筆記", noteTitle: "標題",
|
|
367
|
+
noteBody: "支援 Markdown。寫 #12 就會連到第 12 張卡片。", delNote: "刪除筆記", delNoteSure: "確定刪除?", untitled: "未命名",
|
|
368
|
+
emptyNotes: "還沒有筆記。筆記可以連到卡片:寫 #12。", exportMd: "⬇ 匯出 Markdown", exportVault: "⬇ 匯出到 Obsidian/Notion",
|
|
369
|
+
saved: "已儲存", settings: "⚙ 設定",
|
|
370
|
+
st: {
|
|
371
|
+
title: "設定", save: "儲存", welcome: "歡迎!先在下面選一個模型(不選也可以:Jev 和內建規則一樣會分類),然後丟一個連結進來試試。",
|
|
372
|
+
display: "這個瀏覽器", sort: "排序", sorts: { best: "值得看的在前", newest: "最新的在前", shared: "最多人分享的在前" },
|
|
373
|
+
compact: "精簡卡片(每張一行)", tags: "顯示標籤", said: "顯示大家在聊天室說的話",
|
|
374
|
+
theme: "外觀", themes: { auto: "跟系統一樣", light: "淺色", dark: "深色" },
|
|
375
|
+
model: "模型與分類", language: "語言與聊天回覆", rules: "自訂規則",
|
|
376
|
+
plugins: "外掛", pluginsNone: (dir) => `沒有外掛。把 .js 檔放進 ${dir},範例在 repo 的 examples/plugins。`,
|
|
377
|
+
status: (e) => `目前:分類用 ${({ jev: "Jev", llm: "模型", heuristic: "內建規則" })[e.judge] ?? e.judge},摘要用 ${e.summarizer === "off" ? "(未開啟)" : e.summarizer}`, keep: "已設定,留空就不變", unset: "未設定",
|
|
378
|
+
locked: "由執行環境設定", forbidden: "伺服器設定只能在執行 driftnet 的那台電腦上改(或設定 DRIFTNET_TOKEN)。顯示設定照常可用。",
|
|
379
|
+
savedServer: "已儲存,馬上生效",
|
|
380
|
+
labels: {
|
|
381
|
+
DRIFTNET_LLM_PROVIDER: ["模型來源", "用來寫摘要。選「不使用」也會分類,只是沒有摘要。"],
|
|
382
|
+
DRIFTNET_LLM_MODEL: ["模型", "例如 claude-haiku-5-5、gpt-5-mini、gemini-3.8-flash、qwen3"],
|
|
383
|
+
DRIFTNET_LLM_BASE_URL: ["API 網址", "OpenAI 相容 API 用:Gemini、Grok、OpenRouter、Ollama(http://127.0.0.1:11434/v1)…"],
|
|
384
|
+
DRIFTNET_LLM_API_KEY: ["API 金鑰", ""],
|
|
385
|
+
DRIFTNET_LLM_EFFORT: ["推理強度", ""],
|
|
386
|
+
TYPESAFE_API_KEY: ["Jev 金鑰", "選填:約 100ms 的分類器,可以省下模型呼叫(console.typesafe.ai)"],
|
|
387
|
+
DRIFTNET_JUDGE: ["Jev", ""],
|
|
388
|
+
GITHUB_TOKEN: ["GitHub token", "選填:GitHub 查詢上限從每小時 60 次變 5000 次"],
|
|
389
|
+
DRIFTNET_LANGUAGE: ["摘要語言", "English、Traditional Chinese (Taiwan)、Japanese…"],
|
|
390
|
+
DRIFTNET_LOCALE: ["機器人語言", ""],
|
|
391
|
+
DRIFTNET_REPLY: ["聊天室回覆", ""],
|
|
392
|
+
DRIFTNET_PUBLIC_URL: ["這個網頁的公開網址", "回覆裡的連結會指到這裡,例如 https://driftnet.example.com"],
|
|
393
|
+
DRIFTNET_SUMMARY_RULES: ["摘要的額外規則", "例如:說明是否免費。需要 GPU 的話要提到。"],
|
|
394
|
+
DRIFTNET_BLOCK_DOMAINS: ["不要收錄的網域", "用逗號或空白分隔,例如 example.com, spam.io"],
|
|
395
|
+
},
|
|
396
|
+
choices: {
|
|
397
|
+
DRIFTNET_LLM_PROVIDER: { "": "不使用", anthropic: "Anthropic(API 金鑰)", openai: "OpenAI 相容(OpenAI、Gemini、Grok、Ollama…)", "claude-cli": "Claude 訂閱(Claude Code CLI)", "gemini-cli": "Google 帳號(Gemini CLI)" },
|
|
398
|
+
DRIFTNET_LLM_EFFORT: { "": "預設", low: "低", medium: "中", high: "高" },
|
|
399
|
+
DRIFTNET_JUDGE: { "": "有金鑰就開", off: "關閉" },
|
|
400
|
+
DRIFTNET_LOCALE: { "": "跟摘要一樣", en: "English", "zh-TW": "繁體中文" },
|
|
401
|
+
DRIFTNET_REPLY: { "": "一行+連結(預設)", link: "一行+連結", full: "完整摘要", off: "不回覆" },
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
const state = { view: "all", category: "", kind: "", q: "" };
|
|
407
|
+
const $ = (id) => document.getElementById(id);
|
|
408
|
+
const esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
409
|
+
const safeUrl = (u) => (/^https?:\/\//.test(u) ? u : "#");
|
|
410
|
+
const store = { get: (k) => { try { return localStorage.getItem(k); } catch { return null; } },
|
|
411
|
+
set: (k, v) => { try { localStorage.setItem(k, v); } catch {} } };
|
|
412
|
+
|
|
413
|
+
let locale = "en";
|
|
414
|
+
let catLabels = {};
|
|
415
|
+
let folders = [];
|
|
416
|
+
let notes = [];
|
|
417
|
+
let items = [];
|
|
418
|
+
// Folders the reader closed in the tree; remembered in this browser.
|
|
419
|
+
const collapsed = new Set((() => { try { return JSON.parse(store.get("driftnet-collapsed") ?? "[]"); } catch { return []; } })());
|
|
420
|
+
const kids = (parent) => folders.filter((f) => f.parent === parent);
|
|
421
|
+
const subtotal = (f) => f.count + kids(f.id).reduce((n, c) => n + subtotal(c), 0);
|
|
422
|
+
const folderById = (id) => folders.find((f) => f.id === id);
|
|
423
|
+
const T = () => STRINGS[locale] ?? STRINGS.en;
|
|
424
|
+
const catLabel = (id) => catLabels[id]?.[locale] ?? id;
|
|
425
|
+
|
|
426
|
+
// Private instances need the token on every request; it stays in this browser only.
|
|
427
|
+
async function api(path, init = {}) {
|
|
428
|
+
const token = store.get("driftnet-token");
|
|
429
|
+
const res = await fetch(path, { ...init, headers: { ...(init.headers ?? {}), ...(token ? { authorization: `Bearer ${token}` } : {}) } });
|
|
430
|
+
if (res.status === 401) throw Object.assign(new Error("unauthorized"), { unauthorized: true });
|
|
431
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
432
|
+
return res.json();
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function askToken(then) {
|
|
436
|
+
$("nav").innerHTML = "";
|
|
437
|
+
$("list").innerHTML = `<form class="card" id="token-form">
|
|
438
|
+
<p>${esc(T().tokenPrompt)}</p>
|
|
439
|
+
<input id="token" class="search" style="max-width:none;width:100%" type="password" autocomplete="current-password">
|
|
440
|
+
<p><button class="lang" type="submit">${esc(T().tokenSave)}</button></p></form>`;
|
|
441
|
+
$("token-form").onsubmit = (e) => {
|
|
442
|
+
e.preventDefault();
|
|
443
|
+
store.set("driftnet-token", $("token").value.trim());
|
|
444
|
+
(then ?? load)();
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function applyLocale() {
|
|
449
|
+
document.documentElement.lang = locale;
|
|
450
|
+
$("q").placeholder = T().search;
|
|
451
|
+
$("q").setAttribute("aria-label", T().search);
|
|
452
|
+
$("lang").textContent = T().switchTo;
|
|
453
|
+
$("nav").setAttribute("aria-label", T().nav);
|
|
454
|
+
$("menu").setAttribute("aria-label", T().menu);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// ── Drawer (phones) ──────────────────────────────────────────────────────
|
|
458
|
+
const isDrawer = () => matchMedia("(max-width: 720px)").matches;
|
|
459
|
+
/** keyboard: move focus into the drawer and back (a tap doesn't need the focus ring). */
|
|
460
|
+
function setMenu(open, keyboard = false) {
|
|
461
|
+
document.body.classList.toggle("menu-open", open);
|
|
462
|
+
$("menu").setAttribute("aria-expanded", String(open));
|
|
463
|
+
if (!keyboard) return;
|
|
464
|
+
if (open) $("nav").querySelector('[aria-pressed="true"]')?.focus({ preventScroll: true });
|
|
465
|
+
else if (isDrawer()) $("menu").focus({ preventScroll: true });
|
|
466
|
+
}
|
|
467
|
+
// event.detail is 0 for a click made with the keyboard (Enter / Space).
|
|
468
|
+
$("menu").onclick = (e) => setMenu(!document.body.classList.contains("menu-open"), e.detail === 0);
|
|
469
|
+
$("crumb").onclick = (e) => setMenu(true, e.detail === 0);
|
|
470
|
+
$("scrim").onclick = () => setMenu(false);
|
|
471
|
+
addEventListener("keydown", (e) => { if (e.key === "Escape" && document.body.classList.contains("menu-open")) setMenu(false, true); });
|
|
472
|
+
|
|
473
|
+
/** One line under the header saying what is shown, so a closed drawer hides nothing. */
|
|
474
|
+
function updateCrumb() {
|
|
475
|
+
const t = T();
|
|
476
|
+
const parts = [state.view === "favorites" ? `★ ${t.favorites}` : state.view === "trash" ? `🗑 ${t.trash}`
|
|
477
|
+
: state.view === "notes" ? `📝 ${t.notes}` : t.all];
|
|
478
|
+
if (state.category) parts.push(catLabel(state.category));
|
|
479
|
+
if (state.kind) parts.push(t.kinds[state.kind] ?? state.kind);
|
|
480
|
+
$("crumb").innerHTML = `${esc(t.showing)} <b>${esc(parts.join(" · "))}</b>`;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
async function load() {
|
|
484
|
+
const saved = store.get("driftnet-locale");
|
|
485
|
+
if (STRINGS[saved]) locale = saved;
|
|
486
|
+
applyLocale();
|
|
487
|
+
let stats, ui;
|
|
488
|
+
try {
|
|
489
|
+
[stats, ui, folders, notes] = await Promise.all([api("/api/stats"), api("/api/ui"), api("/api/folders"), api("/api/notes")]);
|
|
490
|
+
stats.notes = notes.length;
|
|
491
|
+
} catch (err) {
|
|
492
|
+
if (err.unauthorized) return askToken();
|
|
493
|
+
throw err;
|
|
494
|
+
}
|
|
495
|
+
catLabels = ui.categories;
|
|
496
|
+
if (ui.setup && !store.get("driftnet-setup-seen")) { store.set("driftnet-setup-seen", "1"); setTimeout(() => openSettings(true), 300); }
|
|
497
|
+
if (!STRINGS[saved] && STRINGS[ui.locale]) locale = ui.locale;
|
|
498
|
+
applyLocale();
|
|
499
|
+
$("stats").textContent = T().stats(stats.items, stats.shares);
|
|
500
|
+
const btn = (field, key, label, n) =>
|
|
501
|
+
`<button type="button" data-field="${field}" data-value="${esc(key)}" aria-pressed="${state[field] === key}">
|
|
502
|
+
<span>${esc(label)}</span><span class="count">${n ?? ""}</span></button>`;
|
|
503
|
+
$("nav").innerHTML =
|
|
504
|
+
`<div class="drawer-head"><span class="brand"><img src="/favicon.svg" alt="" width="24" height="24">driftnet</span>` +
|
|
505
|
+
`<button type="button" class="menu" id="menu-close" aria-label="${esc(T().close)}">✕</button></div>` +
|
|
506
|
+
`<div class="row">` +
|
|
507
|
+
btn("view", "all", T().all, stats.items) + btn("view", "favorites", `★ ${T().favorites}`, stats.favorites) +
|
|
508
|
+
btn("view", "trash", `🗑 ${T().trash}`, stats.trash || "") +
|
|
509
|
+
btn("view", "notes", `📝 ${T().notes}`, stats.notes || "") +
|
|
510
|
+
`</div><div class="folders-head" data-drop-root><h2>${esc(T().folders)}</h2>` +
|
|
511
|
+
`<button type="button" class="icon" data-new="" title="${esc(T().newFolder)}" aria-label="${esc(T().newFolder)}">+</button></div>` +
|
|
512
|
+
`<div class="tree" role="list">${folderRows(null, 0)}</div><h2>${esc(T().kind)}</h2><div class="row kinds">` + btn("kind", "", T().any, "") +
|
|
513
|
+
Object.entries(T().kinds).map(([k, v]) => btn("kind", k, v, "")).join("") + `</div>` +
|
|
514
|
+
`<div class="foot"><button type="button" data-settings>${esc(T().settings)}</button>` +
|
|
515
|
+
`<button type="button" data-export="markdown">${esc(T().exportMd)}</button>` +
|
|
516
|
+
`<button type="button" data-export="vault">${esc(T().exportVault)}</button></div>`;
|
|
517
|
+
$("nav").onclick = (e) => {
|
|
518
|
+
const b = e.target.closest("button");
|
|
519
|
+
if (!b) return;
|
|
520
|
+
if (b.id === "menu-close") return setMenu(false);
|
|
521
|
+
if (b.dataset.twist) {
|
|
522
|
+
const id = b.dataset.twist;
|
|
523
|
+
collapsed.has(id) ? collapsed.delete(id) : collapsed.add(id);
|
|
524
|
+
store.set("driftnet-collapsed", JSON.stringify([...collapsed]));
|
|
525
|
+
return load();
|
|
526
|
+
}
|
|
527
|
+
if (b.dataset.edit) return openFolderDialog(b.dataset.edit);
|
|
528
|
+
if (b.dataset.export) return download(b.dataset.export);
|
|
529
|
+
if (b.dataset.settings !== undefined) { if (isDrawer()) setMenu(false); return openSettings(); }
|
|
530
|
+
if (b.dataset.new !== undefined) return openFolderDialog(null, b.dataset.new || null);
|
|
531
|
+
const { field, value } = b.dataset;
|
|
532
|
+
// Choosing a category stays inside the current view; choosing a view clears the category.
|
|
533
|
+
if (field === "view") state.category = "";
|
|
534
|
+
state[field] = field !== "view" && state[field] === value ? "" : value;
|
|
535
|
+
$("nav").querySelectorAll("button[data-field]").forEach((x) => x.setAttribute("aria-pressed", state[x.dataset.field] === x.dataset.value));
|
|
536
|
+
if (isDrawer()) setMenu(false);
|
|
537
|
+
render();
|
|
538
|
+
};
|
|
539
|
+
attachDrops();
|
|
540
|
+
render();
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** The folder tree, one row per folder: ▸ toggle, name + count (filters), ⋯ (edit). */
|
|
544
|
+
function folderRows(parent, depth) {
|
|
545
|
+
const t = T();
|
|
546
|
+
return kids(parent).map((f) => {
|
|
547
|
+
const hasKids = kids(f.id).length > 0;
|
|
548
|
+
const open = hasKids && !collapsed.has(f.id);
|
|
549
|
+
return `<div class="folder" role="listitem" data-folder="${esc(f.id)}" draggable="true" style="--depth:${depth}">
|
|
550
|
+
<button type="button" class="icon twist ${hasKids ? "" : "leaf"}" ${hasKids ? `data-twist="${esc(f.id)}" aria-expanded="${open}"` : 'tabindex="-1" aria-hidden="true"'}
|
|
551
|
+
aria-label="${esc(t.expand)}">▶</button>
|
|
552
|
+
<button type="button" data-field="category" data-value="${esc(f.id)}" aria-pressed="${state.category === f.id}" title="${esc(f.description)}">
|
|
553
|
+
<span>${esc(catLabel(f.id))}</span><span class="count">${subtotal(f) || ""}</span></button>
|
|
554
|
+
<button type="button" class="icon more" data-edit="${esc(f.id)}" title="${esc(t.editFolder)}" aria-label="${esc(t.editFolder)}: ${esc(catLabel(f.id))}">⋯</button>
|
|
555
|
+
</div>` + (open ? folderRows(f.id, depth + 1) : "");
|
|
556
|
+
}).join("");
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** "Path › Name" for a folder, used in the picker and toasts. */
|
|
560
|
+
const folderPath = (id) => { const f = folderById(id); return f?.parent ? `${folderPath(f.parent)} › ${catLabel(id)}` : catLabel(id); };
|
|
561
|
+
|
|
562
|
+
// ── Folder dialog: new / rename / describe / move / delete ───────────────
|
|
563
|
+
let editing = null;
|
|
564
|
+
function openFolderDialog(id, parent = null) {
|
|
565
|
+
const t = T();
|
|
566
|
+
const f = id ? folderById(id) : null;
|
|
567
|
+
editing = id;
|
|
568
|
+
$("fd-title").textContent = id ? t.editFolder : parent ? `${t.newSub} ${catLabel(parent)}` : t.newFolder;
|
|
569
|
+
$("fd-name-l").textContent = t.folderName;
|
|
570
|
+
$("fd-desc-l").textContent = t.folderDesc;
|
|
571
|
+
$("fd-parent-l").textContent = t.folderParent;
|
|
572
|
+
$("fd-name").value = f ? catLabel(f.id) : "";
|
|
573
|
+
$("fd-desc").value = f?.description ?? "";
|
|
574
|
+
// A folder can't move inside itself or its own sub-folders.
|
|
575
|
+
const banned = new Set();
|
|
576
|
+
if (id) for (const q = [id]; q.length;) { const x = q.pop(); banned.add(x); q.push(...kids(x).map((k) => k.id)); }
|
|
577
|
+
const opts = (p, depth) => kids(p).filter((k) => !banned.has(k.id))
|
|
578
|
+
.map((k) => `<option value="${esc(k.id)}">${"\u00a0\u00a0".repeat(depth)}${esc(catLabel(k.id))}</option>` + opts(k.id, depth + 1)).join("");
|
|
579
|
+
$("fd-parent").innerHTML = `<option value="">${esc(t.topLevel)}</option>` + opts(null, 0);
|
|
580
|
+
$("fd-parent").value = (f ? f.parent : parent) ?? "";
|
|
581
|
+
const del = $("fd-delete");
|
|
582
|
+
del.hidden = !id || id === "other";
|
|
583
|
+
del.textContent = t.del;
|
|
584
|
+
del.classList.remove("armed");
|
|
585
|
+
$("fd-cancel").textContent = t.cancel;
|
|
586
|
+
$("fd-save").textContent = t.save;
|
|
587
|
+
$("fd-error").textContent = "";
|
|
588
|
+
$("folder-dlg").showModal();
|
|
589
|
+
$("fd-name").focus();
|
|
590
|
+
}
|
|
591
|
+
$("fd-cancel").onclick = () => $("folder-dlg").close();
|
|
592
|
+
// Delete asks twice inside the dialog (no browser confirm box).
|
|
593
|
+
$("fd-delete").onclick = async () => {
|
|
594
|
+
const del = $("fd-delete");
|
|
595
|
+
if (!del.classList.contains("armed")) { del.classList.add("armed"); del.textContent = T().delSure; return; }
|
|
596
|
+
if (await folderWrite(`/api/folders/${encodeURIComponent(editing)}`, "DELETE")) {
|
|
597
|
+
if (state.category === editing) state.category = "";
|
|
598
|
+
$("folder-dlg").close();
|
|
599
|
+
load();
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
$("folder-form").onsubmit = async (e) => {
|
|
603
|
+
e.preventDefault();
|
|
604
|
+
const f = editing ? folderById(editing) : null;
|
|
605
|
+
const name = $("fd-name").value.trim();
|
|
606
|
+
const body = { description: $("fd-desc").value.trim(), parent: $("fd-parent").value || null };
|
|
607
|
+
// Built-in folders keep their translated label until the reader renames them.
|
|
608
|
+
if (!f || name !== catLabel(f.id)) body.name = name;
|
|
609
|
+
const ok = editing
|
|
610
|
+
? await folderWrite(`/api/folders/${encodeURIComponent(editing)}`, "PATCH", body)
|
|
611
|
+
: await folderWrite("/api/folders", "POST", body);
|
|
612
|
+
if (ok) { $("folder-dlg").close(); load(); }
|
|
613
|
+
};
|
|
614
|
+
/** Write to the folder API; a refusal (empty name, a loop) shows in the dialog. */
|
|
615
|
+
async function folderWrite(path, method, body) {
|
|
616
|
+
const token = store.get("driftnet-token");
|
|
617
|
+
try {
|
|
618
|
+
const res = await fetch(path, { method, headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
619
|
+
...(body ? { body: JSON.stringify(body) } : {}) });
|
|
620
|
+
if (res.status === 401) { $("folder-dlg").close(); askToken(); return null; }
|
|
621
|
+
const data = await res.json().catch(() => ({}));
|
|
622
|
+
if (!res.ok) { $("fd-error").textContent = data.error ?? T().failed; return null; }
|
|
623
|
+
return data;
|
|
624
|
+
} catch {
|
|
625
|
+
$("fd-error").textContent = T().failed;
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ── Move a card: picker (phones) or drag onto the sidebar (desktop) ───────
|
|
631
|
+
let moving = null;
|
|
632
|
+
function openMovePicker(id) {
|
|
633
|
+
const item = find(id);
|
|
634
|
+
if (!item) return;
|
|
635
|
+
moving = id;
|
|
636
|
+
const t = T();
|
|
637
|
+
$("mv-title").textContent = t.moveTitle(nameOf(item));
|
|
638
|
+
const rows = (p, depth) => kids(p).map((f) => `<button type="button" data-to="${esc(f.id)}" style="--depth:${depth}"
|
|
639
|
+
aria-current="${f.id === item.category}"><span>${esc(catLabel(f.id))}</span><span class="count">${subtotal(f) || ""}</span></button>` + rows(f.id, depth + 1)).join("");
|
|
640
|
+
$("mv-list").innerHTML = rows(null, 0);
|
|
641
|
+
$("mv-cancel").textContent = t.cancel;
|
|
642
|
+
$("move-dlg").showModal();
|
|
643
|
+
$("mv-list").querySelector('[aria-current="true"]')?.focus();
|
|
644
|
+
}
|
|
645
|
+
$("mv-cancel").onclick = () => $("move-dlg").close();
|
|
646
|
+
$("move-dlg").addEventListener("click", (e) => { if (e.target === $("move-dlg")) $("move-dlg").close(); });
|
|
647
|
+
$("folder-dlg").addEventListener("click", (e) => { if (e.target === $("folder-dlg")) $("folder-dlg").close(); });
|
|
648
|
+
$("mv-list").onclick = (e) => {
|
|
649
|
+
const b = e.target.closest("[data-to]");
|
|
650
|
+
if (!b) return;
|
|
651
|
+
$("move-dlg").close();
|
|
652
|
+
moveItem(moving, b.dataset.to);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
async function moveItem(id, to, quiet = false) {
|
|
656
|
+
const item = find(id);
|
|
657
|
+
if (!item || item.category === to) return;
|
|
658
|
+
const from = item.category;
|
|
659
|
+
const token = store.get("driftnet-token");
|
|
660
|
+
const res = await fetch(`/api/items/${id}/move`, { method: "POST", body: JSON.stringify({ folder: to }),
|
|
661
|
+
headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) } }).catch(() => null);
|
|
662
|
+
if (res?.status === 401) return askToken();
|
|
663
|
+
if (!res?.ok) return toast(T().failed);
|
|
664
|
+
item.category = to;
|
|
665
|
+
const f = folderById(to); if (f) f.count++;
|
|
666
|
+
const old = folderById(from); if (old) old.count--;
|
|
667
|
+
const el = document.getElementById(`item-${id}`);
|
|
668
|
+
// Still inside the folder being viewed? Update the badge; otherwise it leaves the list.
|
|
669
|
+
const visible = !state.category || subtreeOf(state.category).has(to);
|
|
670
|
+
if (el && !visible) dismiss(el);
|
|
671
|
+
else if (el) { el.outerHTML = card(item); attachSwipe(document.getElementById(`item-${id}`)); }
|
|
672
|
+
refreshTree();
|
|
673
|
+
if (!quiet) toast(T().moved(nameOf(item), folderPath(to)), async () => { await moveItem(id, from, true); render(); });
|
|
674
|
+
}
|
|
675
|
+
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; };
|
|
676
|
+
/** Re-draw just the tree's counts after a move. */
|
|
677
|
+
function refreshTree() {
|
|
678
|
+
const tree = $("nav").querySelector(".tree");
|
|
679
|
+
if (tree) { tree.innerHTML = folderRows(null, 0); attachDrops(); }
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** Drop targets: a card (by its ⠿ grip) or a folder onto a folder; a folder onto the heading = top level. */
|
|
683
|
+
function attachDrops() {
|
|
684
|
+
for (const row of $("nav").querySelectorAll(".folder")) {
|
|
685
|
+
row.ondragstart = (e) => {
|
|
686
|
+
e.dataTransfer.setData("text/x-driftnet-folder", row.dataset.folder);
|
|
687
|
+
e.dataTransfer.effectAllowed = "move";
|
|
688
|
+
row.classList.add("dragged");
|
|
689
|
+
};
|
|
690
|
+
row.ondragend = () => row.classList.remove("dragged");
|
|
691
|
+
}
|
|
692
|
+
for (const target of $("nav").querySelectorAll(".folder, [data-drop-root]")) {
|
|
693
|
+
target.ondragover = (e) => {
|
|
694
|
+
const types = e.dataTransfer.types;
|
|
695
|
+
if (!types.includes("text/x-driftnet-item") && !types.includes("text/x-driftnet-folder")) return;
|
|
696
|
+
if (target.dataset.dropRoot !== undefined && !types.includes("text/x-driftnet-folder")) return;
|
|
697
|
+
e.preventDefault();
|
|
698
|
+
e.dataTransfer.dropEffect = "move";
|
|
699
|
+
target.classList.add("drop-over");
|
|
700
|
+
};
|
|
701
|
+
target.ondragleave = () => target.classList.remove("drop-over");
|
|
702
|
+
target.ondrop = async (e) => {
|
|
703
|
+
e.preventDefault();
|
|
704
|
+
target.classList.remove("drop-over");
|
|
705
|
+
const to = target.dataset.folder ?? null;
|
|
706
|
+
const item = e.dataTransfer.getData("text/x-driftnet-item");
|
|
707
|
+
const folder = e.dataTransfer.getData("text/x-driftnet-folder");
|
|
708
|
+
if (item && to) return moveItem(Number(item), to);
|
|
709
|
+
if (folder && folder !== to && !(to && subtreeOf(folder).has(to))) {
|
|
710
|
+
const ok = await folderWrite(`/api/folders/${encodeURIComponent(folder)}`, "PATCH", { parent: to });
|
|
711
|
+
if (ok) { toast(T().folderMoved(catLabel(folder), to ? folderPath(to) : T().topLevelShort)); load(); }
|
|
712
|
+
else toast($("fd-error").textContent || T().failed);
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// ── Display preferences (this browser only) ──────────────────────────────
|
|
719
|
+
const prefs = Object.assign({ sort: "best", compact: false, tags: true, said: true, theme: "auto" },
|
|
720
|
+
(() => { try { return JSON.parse(store.get("driftnet-prefs") ?? "{}"); } catch { return {}; } })());
|
|
721
|
+
function applyPrefs() {
|
|
722
|
+
document.body.classList.toggle("compact", !!prefs.compact);
|
|
723
|
+
document.body.classList.toggle("hide-tags", !prefs.tags);
|
|
724
|
+
document.body.classList.toggle("hide-said", !prefs.said);
|
|
725
|
+
if (prefs.theme === "auto") document.documentElement.removeAttribute("data-theme");
|
|
726
|
+
else document.documentElement.dataset.theme = prefs.theme;
|
|
727
|
+
}
|
|
728
|
+
applyPrefs();
|
|
729
|
+
|
|
730
|
+
// ── Settings ─────────────────────────────────────────────────────────────
|
|
731
|
+
let serverSettings = null;
|
|
732
|
+
async function openSettings(welcome = false) {
|
|
733
|
+
const t = T(), st = t.st;
|
|
734
|
+
const token = store.get("driftnet-token");
|
|
735
|
+
const res = await fetch("/api/settings", { headers: token ? { authorization: `Bearer ${token}` } : {} }).catch(() => null);
|
|
736
|
+
serverSettings = res?.ok ? await res.json() : null;
|
|
737
|
+
const opt = (v, label, cur) => `<option value="${esc(v)}" ${v === cur ? "selected" : ""}>${esc(label)}</option>`;
|
|
738
|
+
const local = `<fieldset class="set-group"><legend>${esc(st.display)}</legend>
|
|
739
|
+
<label class="set-row"><span>${esc(st.sort)}</span><select data-pref="sort">${Object.entries(st.sorts).map(([k, v]) => opt(k, v, prefs.sort)).join("")}</select></label>
|
|
740
|
+
<label class="set-row"><span>${esc(st.theme)}</span><select data-pref="theme">${Object.entries(st.themes).map(([k, v]) => opt(k, v, prefs.theme)).join("")}</select></label>
|
|
741
|
+
<label class="set-row check"><input type="checkbox" data-pref="compact" ${prefs.compact ? "checked" : ""}><span>${esc(st.compact)}</span></label>
|
|
742
|
+
<label class="set-row check"><input type="checkbox" data-pref="tags" ${prefs.tags ? "checked" : ""}><span>${esc(st.tags)}</span></label>
|
|
743
|
+
<label class="set-row check"><input type="checkbox" data-pref="said" ${prefs.said ? "checked" : ""}><span>${esc(st.said)}</span></label></fieldset>`;
|
|
744
|
+
let server = `<p class="set-status">${esc(st.forbidden)}</p>`;
|
|
745
|
+
if (serverSettings) {
|
|
746
|
+
const field = (s) => {
|
|
747
|
+
const [label, help] = st.labels[s.key] ?? [s.key, ""];
|
|
748
|
+
const dis = s.locked ? "disabled" : "";
|
|
749
|
+
const hint = s.locked ? st.locked : help;
|
|
750
|
+
let input;
|
|
751
|
+
if (s.choices) input = `<select data-key="${s.key}" ${dis}>${s.choices.map((c) => opt(c, st.choices[s.key]?.[c] ?? c, s.value ?? "")).join("")}</select>`;
|
|
752
|
+
else if (s.multiline) input = `<textarea data-key="${s.key}" rows="3" ${dis}>${esc(s.value)}</textarea>`;
|
|
753
|
+
else if (s.secret) input = `<input data-key="${s.key}" type="password" autocomplete="off" placeholder="${esc(s.set ? st.keep : st.unset)}" ${dis}>`;
|
|
754
|
+
else input = `<input data-key="${s.key}" value="${esc(s.value)}" autocomplete="off" ${dis}>`;
|
|
755
|
+
return `<label class="set-row"><span>${esc(label)}${s.key.startsWith("DRIFTNET") || s.secret ? ` <small>${esc(s.key)}</small>` : ""}</span>${input}${hint ? `<small>${esc(hint)}</small>` : ""}</label>`;
|
|
756
|
+
};
|
|
757
|
+
const group = (g) => `<fieldset class="set-group"><legend>${esc(st[g])}</legend>${serverSettings.settings.filter((s) => s.group === g).map(field).join("")}</fieldset>`;
|
|
758
|
+
const plugins = serverSettings.plugins?.length ? serverSettings.plugins.map((p) => `<div>🧩 ${esc(p)}</div>`).join("")
|
|
759
|
+
: esc(st.pluginsNone(serverSettings.file.replace(/\.env$/, "plugins/")));
|
|
760
|
+
server = `<p class="set-status" id="st-status">${esc(st.status(serverSettings.engines))}</p>` +
|
|
761
|
+
group("model") + group("language") + group("rules") +
|
|
762
|
+
`<fieldset class="set-group"><legend>${esc(st.plugins)}</legend><div class="set-row">${plugins}</div></fieldset>`;
|
|
763
|
+
}
|
|
764
|
+
$("st-title").textContent = st.title;
|
|
765
|
+
$("st-error").textContent = "";
|
|
766
|
+
$("st-body").innerHTML = (welcome ? `<p class="welcome">${esc(st.welcome)}</p>` : "") + (welcome ? server + local : local + server);
|
|
767
|
+
$("st-cancel").textContent = t.cancel;
|
|
768
|
+
$("st-save").textContent = st.save;
|
|
769
|
+
$("settings-dlg").showModal();
|
|
770
|
+
}
|
|
771
|
+
$("st-cancel").onclick = () => $("settings-dlg").close();
|
|
772
|
+
$("settings-form").onsubmit = async (e) => {
|
|
773
|
+
e.preventDefault();
|
|
774
|
+
const body = $("st-body");
|
|
775
|
+
for (const el of body.querySelectorAll("[data-pref]")) prefs[el.dataset.pref] = el.type === "checkbox" ? el.checked : el.value;
|
|
776
|
+
store.set("driftnet-prefs", JSON.stringify(prefs));
|
|
777
|
+
applyPrefs();
|
|
778
|
+
let serverSaved = false;
|
|
779
|
+
if (serverSettings) {
|
|
780
|
+
const values = {};
|
|
781
|
+
for (const el of body.querySelectorAll("[data-key]:not([disabled])")) {
|
|
782
|
+
const s = serverSettings.settings.find((x) => x.key === el.dataset.key);
|
|
783
|
+
if (s.secret ? el.value.trim() : el.value.trim() !== (s.value ?? "").trim()) values[s.key] = el.value.trim() === "" ? null : el.value;
|
|
784
|
+
}
|
|
785
|
+
if (Object.keys(values).length) {
|
|
786
|
+
const token = store.get("driftnet-token");
|
|
787
|
+
const res = await fetch("/api/settings", { method: "PUT", body: JSON.stringify({ values }),
|
|
788
|
+
headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) } }).catch(() => null);
|
|
789
|
+
const data = await res?.json().catch(() => ({}));
|
|
790
|
+
if (!res?.ok) { $("st-error").textContent = data?.error ?? T().failed; return; }
|
|
791
|
+
serverSaved = true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
$("settings-dlg").close();
|
|
795
|
+
toast(serverSaved ? T().st.savedServer : T().saved);
|
|
796
|
+
load();
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// ── Notes ────────────────────────────────────────────────────────────────
|
|
800
|
+
/** Write with the token; on a refusal show `errorEl` or a toast. */
|
|
801
|
+
async function write(path, method, body) {
|
|
802
|
+
const token = store.get("driftnet-token");
|
|
803
|
+
const res = await fetch(path, { method, headers: { "content-type": "application/json", ...(token ? { authorization: `Bearer ${token}` } : {}) },
|
|
804
|
+
...(body ? { body: JSON.stringify(body) } : {}) }).catch(() => null);
|
|
805
|
+
if (res?.status === 401) { document.querySelectorAll("dialog[open]").forEach((d) => d.close()); askToken(); return null; }
|
|
806
|
+
if (!res?.ok) { toast(T().failed); return null; }
|
|
807
|
+
return res.json();
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
let noting = null;
|
|
811
|
+
function openItemNote(id) {
|
|
812
|
+
const item = find(id);
|
|
813
|
+
if (!item) return;
|
|
814
|
+
noting = id;
|
|
815
|
+
const t = T();
|
|
816
|
+
$("in-title").textContent = t.noteFor(nameOf(item));
|
|
817
|
+
$("in-help").textContent = t.noteHelp;
|
|
818
|
+
$("in-text").value = item.note ?? "";
|
|
819
|
+
$("in-cancel").textContent = t.cancel;
|
|
820
|
+
$("in-save").textContent = t.save;
|
|
821
|
+
$("note-dlg").showModal();
|
|
822
|
+
$("in-text").focus();
|
|
823
|
+
}
|
|
824
|
+
$("in-cancel").onclick = () => $("note-dlg").close();
|
|
825
|
+
$("note-form").onsubmit = async (e) => {
|
|
826
|
+
e.preventDefault();
|
|
827
|
+
const saved = await write(`/api/items/${noting}/note`, "PUT", { note: $("in-text").value });
|
|
828
|
+
if (!saved) return;
|
|
829
|
+
$("note-dlg").close();
|
|
830
|
+
const item = find(noting);
|
|
831
|
+
item.note = saved.note;
|
|
832
|
+
const el = document.getElementById(`item-${noting}`);
|
|
833
|
+
if (el) { el.outerHTML = card(item); attachSwipe(document.getElementById(`item-${noting}`)); }
|
|
834
|
+
toast(T().saved);
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
/** A small, escape-first Markdown: headings, lists, quotes, code, bold, italics, links, and #12 → card 12. */
|
|
838
|
+
function md(src) {
|
|
839
|
+
const inline = (s) => esc(s)
|
|
840
|
+
.replace(/`([^`]+)`/g, "<code>$1</code>")
|
|
841
|
+
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
842
|
+
.replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>")
|
|
843
|
+
.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, (m, text, href) => `<a href="${href}" target="_blank" rel="noopener noreferrer">${text}</a>`)
|
|
844
|
+
.replace(/(^|[\s(])(https?:\/\/[^\s<]+)/g, (m, pre, href) => `${pre}<a href="${href}" target="_blank" rel="noopener noreferrer">${href}</a>`)
|
|
845
|
+
.replace(/(^|[^\w&;/])#(\d+)\b/g, (m, pre, id) => `${pre}<a href="#item-${id}" data-card="${id}">#${id}</a>`);
|
|
846
|
+
const out = [];
|
|
847
|
+
let list = false, code = null;
|
|
848
|
+
for (const line of String(src ?? "").split("\n")) {
|
|
849
|
+
if (code !== null) {
|
|
850
|
+
if (/^```/.test(line)) { out.push(`<pre><code>${esc(code)}</code></pre>`); code = null; } else code += (code ? "\n" : "") + line;
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (/^```/.test(line)) { code = ""; continue; }
|
|
854
|
+
const item = /^\s*[-*]\s+(.*)/.exec(line);
|
|
855
|
+
if (item) { if (!list) { out.push("<ul>"); list = true; } out.push(`<li>${inline(item[1])}</li>`); continue; }
|
|
856
|
+
if (list) { out.push("</ul>"); list = false; }
|
|
857
|
+
const h = /^(#{1,3})\s+(.*)/.exec(line);
|
|
858
|
+
if (h) out.push(`<h${h[1].length}>${inline(h[2])}</h${h[1].length}>`);
|
|
859
|
+
else if (/^>\s?/.test(line)) out.push(`<blockquote>${inline(line.replace(/^>\s?/, ""))}</blockquote>`);
|
|
860
|
+
else if (line.trim()) out.push(`<p>${inline(line)}</p>`);
|
|
861
|
+
}
|
|
862
|
+
if (list) out.push("</ul>");
|
|
863
|
+
if (code !== null) out.push(`<pre><code>${esc(code)}</code></pre>`);
|
|
864
|
+
return out.join("");
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
async function renderNotes() {
|
|
868
|
+
const t = T();
|
|
869
|
+
notes = await api(`/api/notes${state.q ? `?q=${encodeURIComponent(state.q)}` : ""}`);
|
|
870
|
+
$("list").innerHTML = `<div class="bar"><span class="hint">${esc(t.noteBody)}</span><span class="spacer"></span>
|
|
871
|
+
<button class="btn primary" type="button" id="new-note">${esc(t.newNote)}</button></div>` +
|
|
872
|
+
(notes.length
|
|
873
|
+
? notes.map((n) => `<button type="button" class="note-card" data-note="${n.id}"><h3>${esc(n.title || t.untitled)}</h3>
|
|
874
|
+
<div class="md">${md(n.body)}</div><div class="meta"><span>${esc(n.updatedAt.slice(0, 10))}</span></div></button>`).join("")
|
|
875
|
+
: `<div class="empty">${esc(t.emptyNotes)}</div>`);
|
|
876
|
+
}
|
|
877
|
+
let editingNote = null;
|
|
878
|
+
function openNote(id) {
|
|
879
|
+
const t = T();
|
|
880
|
+
const n = notes.find((x) => x.id === id);
|
|
881
|
+
editingNote = n ? n.id : null;
|
|
882
|
+
$("nd-title-l").textContent = t.noteTitle;
|
|
883
|
+
$("nd-body-l").textContent = t.noteBody;
|
|
884
|
+
$("nd-title").value = n?.title ?? "";
|
|
885
|
+
$("nd-body").value = n?.body ?? "";
|
|
886
|
+
const del = $("nd-delete");
|
|
887
|
+
del.hidden = !n; del.textContent = t.delNote; del.classList.remove("armed");
|
|
888
|
+
$("nd-cancel").textContent = t.cancel;
|
|
889
|
+
$("nd-save").textContent = t.save;
|
|
890
|
+
$("nd-error").textContent = "";
|
|
891
|
+
$("notes-dlg").showModal();
|
|
892
|
+
(n ? $("nd-body") : $("nd-title")).focus();
|
|
893
|
+
}
|
|
894
|
+
$("list").addEventListener("click", (e) => {
|
|
895
|
+
if (e.target.closest("#new-note")) return openNote(null);
|
|
896
|
+
// A #12 link inside a note opens the card, not the note.
|
|
897
|
+
const cardLink = e.target.closest("a[data-card]");
|
|
898
|
+
if (cardLink) { e.preventDefault(); e.stopPropagation(); return jumpTo(Number(cardLink.dataset.card)); }
|
|
899
|
+
if (e.target.closest("a")) return;
|
|
900
|
+
const n = e.target.closest("[data-note]");
|
|
901
|
+
if (n) openNote(Number(n.dataset.note));
|
|
902
|
+
});
|
|
903
|
+
$("nd-cancel").onclick = () => $("notes-dlg").close();
|
|
904
|
+
$("nd-delete").onclick = async () => {
|
|
905
|
+
const del = $("nd-delete");
|
|
906
|
+
if (!del.classList.contains("armed")) { del.classList.add("armed"); del.textContent = T().delNoteSure; return; }
|
|
907
|
+
if (await write(`/api/notes/${editingNote}`, "DELETE")) { $("notes-dlg").close(); load(); }
|
|
908
|
+
};
|
|
909
|
+
$("nd-form").onsubmit = async (e) => {
|
|
910
|
+
e.preventDefault();
|
|
911
|
+
const body = { title: $("nd-title").value, body: $("nd-body").value };
|
|
912
|
+
const saved = editingNote ? await write(`/api/notes/${editingNote}`, "PUT", body) : await write("/api/notes", "POST", body);
|
|
913
|
+
if (saved) { $("notes-dlg").close(); load(); }
|
|
914
|
+
};
|
|
915
|
+
/** Show every card, then scroll to this one. */
|
|
916
|
+
function jumpTo(id) {
|
|
917
|
+
Object.assign(state, { view: "all", category: "", kind: "", q: "" });
|
|
918
|
+
$("q").value = "";
|
|
919
|
+
history.replaceState(null, "", `#item-${id}`);
|
|
920
|
+
load();
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** Downloads go through fetch so a private instance's token comes along. */
|
|
924
|
+
async function download(format) {
|
|
925
|
+
const token = store.get("driftnet-token");
|
|
926
|
+
const res = await fetch(`/api/export?format=${format}&lang=${locale}`, { headers: token ? { authorization: `Bearer ${token}` } : {} }).catch(() => null);
|
|
927
|
+
if (res?.status === 401) return askToken();
|
|
928
|
+
if (!res?.ok) return toast(T().failed);
|
|
929
|
+
const name = /filename="([^"]+)"/.exec(res.headers.get("content-disposition") ?? "")?.[1] ?? "driftnet-export";
|
|
930
|
+
const a = Object.assign(document.createElement("a"), { href: URL.createObjectURL(await res.blob()), download: name });
|
|
931
|
+
document.body.append(a); a.click(); a.remove();
|
|
932
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
async function render() {
|
|
936
|
+
updateCrumb();
|
|
937
|
+
if (state.view === "notes") return renderNotes();
|
|
938
|
+
const p = new URLSearchParams({ limit: "300" });
|
|
939
|
+
if (prefs.sort !== "best") p.set("sort", prefs.sort);
|
|
940
|
+
if (state.view !== "all") p.set("view", state.view);
|
|
941
|
+
for (const k of ["category", "kind", "q"]) if (state[k]) p.set(k, state[k]);
|
|
942
|
+
items = await api(`/api/items?${p}`);
|
|
943
|
+
const t = T();
|
|
944
|
+
const empty = state.view === "trash" ? t.emptyTrash : state.view === "favorites" ? t.emptyFav : t.empty;
|
|
945
|
+
$("list").innerHTML = items.length
|
|
946
|
+
? `<p class="hint">${esc(state.view === "trash" ? t.hintTrash : t.hint)}</p>` + items.map(card).join("")
|
|
947
|
+
: `<div class="empty">${esc(empty)}</div>`;
|
|
948
|
+
for (const el of $("list").querySelectorAll(".swipe")) attachSwipe(el);
|
|
949
|
+
// Only #item-<n> is ours; anything else in the hash must not break the page.
|
|
950
|
+
if (/^#item-\d+$/.test(location.hash)) document.getElementById(location.hash.slice(1))?.scrollIntoView();
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function card(i) {
|
|
954
|
+
const s = i.summary;
|
|
955
|
+
const t = T();
|
|
956
|
+
const url = safeUrl(s?.primaryUrl || i.url);
|
|
957
|
+
const inTrash = state.view === "trash";
|
|
958
|
+
const tools = inTrash
|
|
959
|
+
? `<button class="tool" type="button" data-act="restore" title="${esc(t.restore)}" aria-label="${esc(t.restore)}">↩</button>`
|
|
960
|
+
: `<button class="tool grip" type="button" draggable="true" data-grip="${i.id}" title="${esc(t.dragHint)}" aria-hidden="true" tabindex="-1">⠿</button>
|
|
961
|
+
<button class="tool" type="button" data-act="move" title="${esc(t.moveTo)}" aria-label="${esc(t.moveTo)}">📁</button>
|
|
962
|
+
<button class="tool ${i.favorite ? "on" : ""}" type="button" data-act="favorite" aria-pressed="${i.favorite}"
|
|
963
|
+
title="${esc(i.favorite ? t.unfavorite : t.favorite)}" aria-label="${esc(i.favorite ? t.unfavorite : t.favorite)}">${i.favorite ? "★" : "☆"}</button>
|
|
964
|
+
<button class="tool" type="button" data-act="trash" title="${esc(t.remove)}" aria-label="${esc(t.remove)}">🗑</button>`;
|
|
965
|
+
return `<div class="swipe" id="item-${i.id}" data-id="${i.id}">
|
|
966
|
+
<div class="act right ${inTrash ? "restore" : ""}"><span>${esc(inTrash ? t.swipeRestore : i.favorite ? t.swipeUnfav : t.swipeFav)}</span></div>
|
|
967
|
+
<div class="act left"><span>${esc(inTrash ? "" : t.swipeTrash)}</span></div>
|
|
968
|
+
<article class="card">
|
|
969
|
+
<div class="top">
|
|
970
|
+
<a class="name" href="${esc(url)}" target="_blank" rel="noopener noreferrer">${esc(s?.name ?? i.title)}</a>
|
|
971
|
+
<span class="badge">${esc(catLabel(i.category))}</span>
|
|
972
|
+
<span class="badge worth-${esc(i.worth)}">${esc(t.worth[i.worth] ?? i.worth)}</span>
|
|
973
|
+
${i.pending ? `<span class="badge">${esc(t.pending)}</span>` : ""}
|
|
974
|
+
</div>
|
|
975
|
+
${s ? `<p>${esc(s.oneLiner)}</p>` : ""}
|
|
976
|
+
${s?.highlights?.length ? `<ul>${s.highlights.map((h) => `<li>${esc(h)}</li>`).join("")}</ul>` : ""}
|
|
977
|
+
${(i.said ?? []).slice(0, 2).map((x) => `<div class="said">${esc(x)}</div>`).join("")}
|
|
978
|
+
${i.note ? `<div class="mynote">${esc(i.note)}</div>` : ""}
|
|
979
|
+
${i.found?.length ? `<div class="found"><span>${esc(t.foundIn)}</span>${i.found.map((c) => `<a href="#item-${c.id}">${esc(c.name)}</a>`).join("")}</div>` : ""}
|
|
980
|
+
${i.flags.length ? `<div class="flag">⚠ ${esc(i.flags.map((f) => t.flags[f] ?? f).join(", "))}</div>` : ""}
|
|
981
|
+
<div class="meta">
|
|
982
|
+
<span>#${i.id}</span><span>${esc(t.kinds[i.kind] ?? i.kind)}</span>${i.shareCount ? `<span>${esc(t.shared(i.shareCount))}</span>` : ""}
|
|
983
|
+
<span>${esc(i.createdAt.slice(0, 10))}</span>
|
|
984
|
+
${i.enrichedBy ? `<span>${esc(t.enrichedBy(i.enrichedBy.replace(/^agent:/, "")))}</span>` : ""}
|
|
985
|
+
${s?.tags?.length ? `<span class="tags">${s.tags.map((x) => "#" + esc(x)).join(" ")}</span>` : ""}
|
|
986
|
+
${inTrash ? "" : `<button class="link-btn" type="button" data-act="note">${esc(i.note ? t.editNote : t.addNote)}</button>`}
|
|
987
|
+
</div>
|
|
988
|
+
<div class="tools">${tools}</div>
|
|
989
|
+
</article>
|
|
990
|
+
</div>`;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
// ── Actions ──────────────────────────────────────────────────────────────
|
|
994
|
+
const find = (id) => items.find((x) => x.id === id);
|
|
995
|
+
const nameOf = (i) => (i.summary?.name ?? i.title).slice(0, 40);
|
|
996
|
+
|
|
997
|
+
async function act(id, action) {
|
|
998
|
+
try {
|
|
999
|
+
return await api(`/api/items/${id}/${action}`, { method: "POST" });
|
|
1000
|
+
} catch (err) {
|
|
1001
|
+
if (err.unauthorized) return new Promise((resolve) => askToken(async () => { await load(); resolve(null); }));
|
|
1002
|
+
toast(T().failed);
|
|
1003
|
+
throw err;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/** Collapse a card out of the list, then refresh the counts. */
|
|
1008
|
+
function dismiss(el) {
|
|
1009
|
+
el.style.height = `${el.offsetHeight}px`;
|
|
1010
|
+
requestAnimationFrame(() => {
|
|
1011
|
+
el.classList.add("gone");
|
|
1012
|
+
el.style.height = "0px";
|
|
1013
|
+
el.style.marginBottom = "-12px";
|
|
1014
|
+
});
|
|
1015
|
+
setTimeout(() => el.remove(), 260);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
async function run(el, action) {
|
|
1019
|
+
const id = Number(el.dataset.id);
|
|
1020
|
+
const item = find(id);
|
|
1021
|
+
if (!item) return;
|
|
1022
|
+
const t = T();
|
|
1023
|
+
if (action === "trash" || action === "restore") {
|
|
1024
|
+
el.querySelector(".card").style.transform = `translateX(${action === "trash" ? "-110%" : "110%"})`;
|
|
1025
|
+
dismiss(el);
|
|
1026
|
+
await act(id, action);
|
|
1027
|
+
const back = action === "trash" ? "restore" : "trash";
|
|
1028
|
+
toast(action === "trash" ? t.removed(nameOf(item)) : t.restored(nameOf(item)), async () => { await act(id, back); load(); });
|
|
1029
|
+
} else {
|
|
1030
|
+
const on = !item.favorite;
|
|
1031
|
+
await act(id, on ? "favorite" : "unfavorite");
|
|
1032
|
+
item.favorite = on;
|
|
1033
|
+
if (state.view === "favorites" && !on) dismiss(el);
|
|
1034
|
+
else el.outerHTML = card(item), attachSwipe(document.getElementById(`item-${id}`));
|
|
1035
|
+
if (on) toast(t.faved(nameOf(item)));
|
|
1036
|
+
}
|
|
1037
|
+
refreshCounts();
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
async function refreshCounts() {
|
|
1041
|
+
const stats = await api("/api/stats").catch(() => null);
|
|
1042
|
+
if (!stats) return;
|
|
1043
|
+
$("stats").textContent = T().stats(stats.items, stats.shares);
|
|
1044
|
+
const set = (v, n) => { const c = $("nav").querySelector(`[data-field="view"][data-value="${v}"] .count`); if (c) c.textContent = n || (v === "all" ? "0" : ""); };
|
|
1045
|
+
set("all", stats.items); set("favorites", stats.favorites); set("trash", stats.trash);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
$("list").addEventListener("click", (e) => {
|
|
1049
|
+
const n = e.target.closest('.link-btn[data-act="note"]');
|
|
1050
|
+
if (n) return openItemNote(Number(n.closest(".swipe").dataset.id));
|
|
1051
|
+
const b = e.target.closest(".tool");
|
|
1052
|
+
if (!b || b.dataset.grip) return;
|
|
1053
|
+
if (b.dataset.act === "move") return openMovePicker(Number(b.closest(".swipe").dataset.id));
|
|
1054
|
+
run(b.closest(".swipe"), b.dataset.act);
|
|
1055
|
+
});
|
|
1056
|
+
$("list").addEventListener("dragstart", (e) => {
|
|
1057
|
+
const grip = e.target.closest?.("[data-grip]");
|
|
1058
|
+
if (!grip) return;
|
|
1059
|
+
e.dataTransfer.setData("text/x-driftnet-item", grip.dataset.grip);
|
|
1060
|
+
e.dataTransfer.effectAllowed = "move";
|
|
1061
|
+
const cardEl = grip.closest(".card");
|
|
1062
|
+
e.dataTransfer.setDragImage(cardEl, 24, 24);
|
|
1063
|
+
});
|
|
1064
|
+
// A "found in" link to a card outside the current filter: show everything, then jump.
|
|
1065
|
+
addEventListener("hashchange", () => {
|
|
1066
|
+
if (/^#item-\d+$/.test(location.hash) && !document.getElementById(location.hash.slice(1))) {
|
|
1067
|
+
Object.assign(state, { view: "all", category: "", kind: "", q: "" });
|
|
1068
|
+
$("q").value = "";
|
|
1069
|
+
load();
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
// ── Swipe: right = favorite (restore in the trash), left = trash ─────────
|
|
1074
|
+
function attachSwipe(el) {
|
|
1075
|
+
if (!el) return;
|
|
1076
|
+
const cardEl = el.querySelector(".card");
|
|
1077
|
+
let x0 = 0, y0 = 0, dx = 0, active = false, horizontal = null;
|
|
1078
|
+
const limit = () => Math.min(140, el.offsetWidth * 0.32);
|
|
1079
|
+
const inTrash = state.view === "trash";
|
|
1080
|
+
cardEl.addEventListener("pointerdown", (e) => {
|
|
1081
|
+
if (e.button !== 0 || e.target.closest("a, button")) return;
|
|
1082
|
+
x0 = e.clientX; y0 = e.clientY; dx = 0; active = true; horizontal = null;
|
|
1083
|
+
});
|
|
1084
|
+
cardEl.addEventListener("pointermove", (e) => {
|
|
1085
|
+
if (!active) return;
|
|
1086
|
+
const mx = e.clientX - x0, my = e.clientY - y0;
|
|
1087
|
+
if (horizontal === null) {
|
|
1088
|
+
if (Math.abs(mx) < 8 && Math.abs(my) < 8) return;
|
|
1089
|
+
horizontal = Math.abs(mx) > Math.abs(my);
|
|
1090
|
+
if (!horizontal) return void (active = false); // a scroll, not a swipe
|
|
1091
|
+
cardEl.setPointerCapture(e.pointerId);
|
|
1092
|
+
cardEl.classList.add("dragging");
|
|
1093
|
+
}
|
|
1094
|
+
// In the trash only a right swipe means something; resist the other way.
|
|
1095
|
+
dx = inTrash && mx < 0 ? mx / 5 : mx;
|
|
1096
|
+
cardEl.style.transform = `translateX(${dx}px)`;
|
|
1097
|
+
el.dataset.dir = dx > 0 ? "right" : "left";
|
|
1098
|
+
el.classList.toggle("armed", Math.abs(dx) > limit());
|
|
1099
|
+
});
|
|
1100
|
+
const end = () => {
|
|
1101
|
+
if (!active) return;
|
|
1102
|
+
active = false;
|
|
1103
|
+
cardEl.classList.remove("dragging");
|
|
1104
|
+
const armed = Math.abs(dx) > limit() && horizontal;
|
|
1105
|
+
el.classList.remove("armed");
|
|
1106
|
+
if (armed && dx < 0 && !inTrash) return run(el, "trash");
|
|
1107
|
+
if (armed && dx > 0) {
|
|
1108
|
+
if (inTrash) return run(el, "restore");
|
|
1109
|
+
cardEl.style.transform = "";
|
|
1110
|
+
delete el.dataset.dir;
|
|
1111
|
+
return run(el, "favorite");
|
|
1112
|
+
}
|
|
1113
|
+
cardEl.style.transform = "";
|
|
1114
|
+
setTimeout(() => delete el.dataset.dir, 220);
|
|
1115
|
+
};
|
|
1116
|
+
cardEl.addEventListener("pointerup", end);
|
|
1117
|
+
cardEl.addEventListener("pointercancel", end);
|
|
1118
|
+
// A drag that ends on a link must not open it.
|
|
1119
|
+
cardEl.addEventListener("click", (e) => { if (Math.abs(dx) > 8) { e.preventDefault(); e.stopPropagation(); } }, true);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// ── Toast with undo ──────────────────────────────────────────────────────
|
|
1123
|
+
let toastTimer;
|
|
1124
|
+
function toast(text, undo) {
|
|
1125
|
+
$("toast-text").textContent = text;
|
|
1126
|
+
const u = $("toast-undo");
|
|
1127
|
+
u.hidden = !undo;
|
|
1128
|
+
u.textContent = T().undo;
|
|
1129
|
+
u.onclick = async () => { $("toast").classList.remove("show"); await undo?.(); };
|
|
1130
|
+
$("toast").classList.add("show");
|
|
1131
|
+
clearTimeout(toastTimer);
|
|
1132
|
+
toastTimer = setTimeout(() => $("toast").classList.remove("show"), 5000);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
$("lang").onclick = () => {
|
|
1136
|
+
locale = locale === "en" ? "zh-TW" : "en";
|
|
1137
|
+
store.set("driftnet-locale", locale);
|
|
1138
|
+
load();
|
|
1139
|
+
};
|
|
1140
|
+
let timer;
|
|
1141
|
+
$("q").oninput = (e) => { clearTimeout(timer); timer = setTimeout(() => { state.q = e.target.value.trim(); render(); }, 200); };
|
|
1142
|
+
load();
|
|
1143
|
+
</script>
|
|
1144
|
+
</body>
|
|
1145
|
+
</html>
|