@luoyi-dsh/instagram-scroll 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js ADDED
@@ -0,0 +1,1146 @@
1
+ /**
2
+ * client.js —— DSH Web 瀏覽器端設定與動態日報面板 (dsh-instagram-scroll)
3
+ * ============================================================================
4
+ * 設計規範遵循:
5
+ * - .agents/skills/design-taste-frontend
6
+ * - references/app-screens.md (KPIs, Forms & Settings, Quiet Surfaces)
7
+ * 核心功能 (比照 dsh-bili-scroll):
8
+ * - 每天替主人刷一輪 Instagram 貼文與影片
9
+ * - 逐條讀內文判斷主人是否感興趣
10
+ * - 值得的就在該貼文留言 @主人 + 推薦詞,並產生 Markdown 日報
11
+ * - 提供「現在跑一輪」按鈕與完整參數配置
12
+ * ============================================================================
13
+ */
14
+
15
+ window.__ModuleLoader__.load({
16
+ id: '@luoyi-dsh/instagram-scroll',
17
+ factory: (require) => {
18
+ const React = require('react')
19
+ const h = React.createElement
20
+ const { useState, useEffect } = React
21
+
22
+ const API = '/api/instagram/scroll'
23
+
24
+ const asJson = async (res) => {
25
+ if (res.ok) return res.json()
26
+ const text = await res.text().catch(() => '')
27
+ throw new Error(`HTTP ${res.status}: ${text || res.statusText}`)
28
+ }
29
+
30
+ const jget = async (path) => asJson(await fetch(API + path, { credentials: 'same-origin' }))
31
+ const jpost = async (path, body) =>
32
+ asJson(
33
+ await fetch(API + path, {
34
+ method: 'POST',
35
+ credentials: 'same-origin',
36
+ headers: { 'content-type': 'application/json' },
37
+ body: JSON.stringify(body || {}),
38
+ })
39
+ )
40
+
41
+ // 精緻向量 SVG 圖標集合
42
+ const Icon = {
43
+ Scroll: ({ size = 18 }) =>
44
+ h(
45
+ 'svg',
46
+ {
47
+ width: size,
48
+ height: size,
49
+ viewBox: '0 0 24 24',
50
+ fill: 'none',
51
+ stroke: 'currentColor',
52
+ strokeWidth: 2,
53
+ strokeLinecap: 'round',
54
+ strokeLinejoin: 'round',
55
+ },
56
+ h('path', { d: 'M19 20H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v1' }),
57
+ h('path', { d: 'M19 4a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-1' }),
58
+ h('path', { d: 'M7 8h8' }),
59
+ h('path', { d: 'M7 12h6' })
60
+ ),
61
+ Play: ({ size = 13 }) =>
62
+ h(
63
+ 'svg',
64
+ {
65
+ width: size,
66
+ height: size,
67
+ viewBox: '0 0 24 24',
68
+ fill: 'currentColor',
69
+ stroke: 'currentColor',
70
+ strokeWidth: 1,
71
+ },
72
+ h('polygon', { points: '5 3 19 12 5 21 5 3' })
73
+ ),
74
+ Sparkles: ({ size = 15 }) =>
75
+ h(
76
+ 'svg',
77
+ {
78
+ width: size,
79
+ height: size,
80
+ viewBox: '0 0 24 24',
81
+ fill: 'none',
82
+ stroke: 'currentColor',
83
+ strokeWidth: 2,
84
+ strokeLinecap: 'round',
85
+ strokeLinejoin: 'round',
86
+ },
87
+ h('path', {
88
+ d: 'M12 3l1.912 5.885L19.798 10.8 13.912 12.715 12 18.6l-1.912-5.885L4.202 10.8l5.886-1.915L12 3z',
89
+ })
90
+ ),
91
+ User: ({ size = 15 }) =>
92
+ h(
93
+ 'svg',
94
+ {
95
+ width: size,
96
+ height: size,
97
+ viewBox: '0 0 24 24',
98
+ fill: 'none',
99
+ stroke: 'currentColor',
100
+ strokeWidth: 2,
101
+ strokeLinecap: 'round',
102
+ strokeLinejoin: 'round',
103
+ },
104
+ h('path', { d: 'M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2' }),
105
+ h('circle', { cx: 12, cy: 7, r: 4 })
106
+ ),
107
+ Clock: ({ size = 15 }) =>
108
+ h(
109
+ 'svg',
110
+ {
111
+ width: size,
112
+ height: size,
113
+ viewBox: '0 0 24 24',
114
+ fill: 'none',
115
+ stroke: 'currentColor',
116
+ strokeWidth: 2,
117
+ strokeLinecap: 'round',
118
+ strokeLinejoin: 'round',
119
+ },
120
+ h('circle', { cx: 12, cy: 12, r: 10 }),
121
+ h('polyline', { points: '12 6 12 12 16 14' })
122
+ ),
123
+ Refresh: ({ size = 14 }) =>
124
+ h(
125
+ 'svg',
126
+ {
127
+ width: size,
128
+ height: size,
129
+ viewBox: '0 0 24 24',
130
+ fill: 'none',
131
+ stroke: 'currentColor',
132
+ strokeWidth: 2,
133
+ strokeLinecap: 'round',
134
+ strokeLinejoin: 'round',
135
+ },
136
+ h('polyline', { points: '23 4 23 10 17 10' }),
137
+ h('polyline', { points: '1 20 1 14 7 14' }),
138
+ h('path', {
139
+ d: 'M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15',
140
+ })
141
+ ),
142
+ ExternalLink: ({ size = 12 }) =>
143
+ h(
144
+ 'svg',
145
+ {
146
+ width: size,
147
+ height: size,
148
+ viewBox: '0 0 24 24',
149
+ fill: 'none',
150
+ stroke: 'currentColor',
151
+ strokeWidth: 2,
152
+ strokeLinecap: 'round',
153
+ strokeLinejoin: 'round',
154
+ },
155
+ h('path', { d: 'M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6' }),
156
+ h('polyline', { points: '15 3 21 3 21 9' }),
157
+ h('line', { x1: 10, y1: 14, x2: 21, y2: 3 })
158
+ ),
159
+ Save: ({ size = 14 }) =>
160
+ h(
161
+ 'svg',
162
+ {
163
+ width: size,
164
+ height: size,
165
+ viewBox: '0 0 24 24',
166
+ fill: 'none',
167
+ stroke: 'currentColor',
168
+ strokeWidth: 2,
169
+ strokeLinecap: 'round',
170
+ strokeLinejoin: 'round',
171
+ },
172
+ h('path', {
173
+ d: 'M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z',
174
+ }),
175
+ h('polyline', { points: '17 21 17 13 7 13 7 21' }),
176
+ h('polyline', { points: '7 3 7 8 15 8' })
177
+ ),
178
+ }
179
+
180
+ const CSS = `
181
+ /* ==========================================================================
182
+ Instagram Scroll & Recommend — Design-Taste-Frontend Architecture
183
+ ========================================================================== */
184
+ .ig-scr-root {
185
+ display: flex;
186
+ flex-direction: column;
187
+ gap: 18px;
188
+ max-width: 760px;
189
+ padding: 6px 4px 40px;
190
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
191
+ color: var(--dsw-alias-label-primary, #f1f5f9);
192
+ line-height: 1.5;
193
+ box-sizing: border-box;
194
+ }
195
+
196
+ /* 頂部標頭列 (Header Shell) */
197
+ .ig-scr-header {
198
+ display: flex;
199
+ align-items: center;
200
+ justify-content: space-between;
201
+ padding-bottom: 16px;
202
+ border-bottom: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
203
+ }
204
+ .ig-scr-brand-row {
205
+ display: flex;
206
+ align-items: center;
207
+ gap: 12px;
208
+ }
209
+ .ig-scr-brand-mark {
210
+ width: 36px;
211
+ height: 36px;
212
+ border-radius: 8px;
213
+ background: #181b22;
214
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
215
+ display: flex;
216
+ align-items: center;
217
+ justify-content: center;
218
+ color: #3b82f6;
219
+ }
220
+ .ig-scr-brand-title {
221
+ font-size: 15px;
222
+ font-weight: 600;
223
+ letter-spacing: -0.01em;
224
+ color: #ffffff;
225
+ }
226
+ .ig-scr-brand-sub {
227
+ font-size: 12px;
228
+ color: var(--dsw-alias-label-secondary, #94a3b8);
229
+ margin-top: 1px;
230
+ }
231
+
232
+ /* 分頁導航列 (Tab Navigation Rail) */
233
+ .ig-scr-tabs {
234
+ display: flex;
235
+ gap: 2px;
236
+ background: var(--dsw-alias-bg-layer-2, rgba(255, 255, 255, 0.025));
237
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.07));
238
+ border-radius: 8px;
239
+ padding: 3px;
240
+ }
241
+ .ig-scr-tab-btn {
242
+ display: flex;
243
+ align-items: center;
244
+ gap: 7px;
245
+ padding: 7px 14px;
246
+ font-size: 12px;
247
+ font-weight: 500;
248
+ color: var(--dsw-alias-label-secondary, #94a3b8);
249
+ background: transparent;
250
+ border: 0;
251
+ border-radius: 6px;
252
+ cursor: pointer;
253
+ white-space: nowrap;
254
+ transition: all 0.15s ease-in-out;
255
+ }
256
+ .ig-scr-tab-btn:hover {
257
+ color: #ffffff;
258
+ background: rgba(255, 255, 255, 0.04);
259
+ }
260
+ .ig-scr-tab-btn.active {
261
+ color: #ffffff;
262
+ background: rgba(255, 255, 255, 0.08);
263
+ font-weight: 600;
264
+ }
265
+
266
+ /* 設定卡片容器 (Flat Panel, 1px Quiet Border) */
267
+ .ig-scr-panel {
268
+ background: var(--dsw-alias-bg-layer-2, rgba(255, 255, 255, 0.02));
269
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
270
+ border-radius: 10px;
271
+ padding: 18px 20px;
272
+ display: flex;
273
+ flex-direction: column;
274
+ gap: 16px;
275
+ }
276
+ .ig-scr-section-head {
277
+ display: flex;
278
+ flex-direction: column;
279
+ gap: 2px;
280
+ border-bottom: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.05));
281
+ padding-bottom: 10px;
282
+ }
283
+ .ig-scr-section-title {
284
+ font-size: 13.5px;
285
+ font-weight: 600;
286
+ color: #ffffff;
287
+ }
288
+ .ig-scr-section-desc {
289
+ font-size: 11.5px;
290
+ color: var(--dsw-alias-label-secondary, #94a3b8);
291
+ }
292
+
293
+ /* 雙欄網格與輸入項 */
294
+ .ig-scr-grid-2 {
295
+ display: grid;
296
+ grid-template-columns: 1fr 1fr;
297
+ gap: 14px;
298
+ }
299
+ .ig-scr-field {
300
+ display: flex;
301
+ flex-direction: column;
302
+ gap: 6px;
303
+ }
304
+ .ig-scr-label {
305
+ font-size: 12px;
306
+ font-weight: 500;
307
+ color: var(--dsw-alias-label-secondary, #cbd5e1);
308
+ }
309
+ .ig-scr-hint {
310
+ font-size: 11px;
311
+ color: var(--dsw-alias-label-tertiary, #64748b);
312
+ line-height: 1.4;
313
+ }
314
+ .ig-scr-input {
315
+ width: 100%;
316
+ height: 36px;
317
+ box-sizing: border-box;
318
+ padding: 0 12px;
319
+ border-radius: 6px;
320
+ font-size: 12px;
321
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
322
+ background: var(--dsw-alias-bg-layer-4, rgba(0, 0, 0, 0.25));
323
+ color: #f1f5f9;
324
+ font-family: inherit;
325
+ transition: border-color 0.15s, box-shadow 0.15s;
326
+ }
327
+ .ig-scr-input:focus {
328
+ outline: none;
329
+ border-color: #3b82f6;
330
+ box-shadow: 0 0 0 1px #3b82f6;
331
+ }
332
+ .ig-scr-textarea {
333
+ width: 100%;
334
+ min-height: 64px;
335
+ box-sizing: border-box;
336
+ padding: 8px 12px;
337
+ border-radius: 6px;
338
+ font-size: 12px;
339
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
340
+ background: var(--dsw-alias-bg-layer-4, rgba(0, 0, 0, 0.25));
341
+ color: #f1f5f9;
342
+ font-family: inherit;
343
+ resize: vertical;
344
+ }
345
+
346
+ /* 開關列 (Switch Cell) */
347
+ .ig-scr-switch {
348
+ display: flex;
349
+ align-items: center;
350
+ justify-content: space-between;
351
+ padding: 10px 14px;
352
+ background: rgba(255, 255, 255, 0.02);
353
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.05));
354
+ border-radius: 8px;
355
+ }
356
+ .ig-scr-switch-text {
357
+ display: flex;
358
+ flex-direction: column;
359
+ gap: 2px;
360
+ }
361
+ .ig-scr-switch-name {
362
+ font-size: 12.5px;
363
+ font-weight: 500;
364
+ color: #f1f5f9;
365
+ }
366
+ .ig-scr-toggle {
367
+ position: relative;
368
+ width: 36px;
369
+ height: 20px;
370
+ border-radius: 10px;
371
+ background: rgba(255, 255, 255, 0.15);
372
+ cursor: pointer;
373
+ border: 0;
374
+ padding: 0;
375
+ transition: background 0.2s ease;
376
+ flex-shrink: 0;
377
+ }
378
+ .ig-scr-toggle.on {
379
+ background: #10b981;
380
+ }
381
+ .ig-scr-toggle-thumb {
382
+ position: absolute;
383
+ top: 2px;
384
+ left: 2px;
385
+ width: 16px;
386
+ height: 16px;
387
+ border-radius: 50%;
388
+ background: #ffffff;
389
+ transition: left 0.2s ease;
390
+ }
391
+ .ig-scr-toggle.on .ig-scr-toggle-thumb {
392
+ left: 18px;
393
+ }
394
+
395
+ /* KPI 指標卡片 */
396
+ .ig-scr-kpi-grid {
397
+ display: grid;
398
+ grid-template-columns: repeat(3, 1fr);
399
+ gap: 12px;
400
+ }
401
+ .ig-scr-kpi-card {
402
+ background: rgba(255, 255, 255, 0.02);
403
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.06));
404
+ border-radius: 8px;
405
+ padding: 14px 16px;
406
+ display: flex;
407
+ flex-direction: column;
408
+ gap: 4px;
409
+ }
410
+ .ig-scr-kpi-title {
411
+ font-size: 11px;
412
+ font-weight: 500;
413
+ color: var(--dsw-alias-label-secondary, #94a3b8);
414
+ }
415
+ .ig-scr-kpi-val {
416
+ font-size: 22px;
417
+ font-weight: 600;
418
+ color: #ffffff;
419
+ font-variant-numeric: tabular-nums;
420
+ display: flex;
421
+ align-items: baseline;
422
+ gap: 4px;
423
+ }
424
+ .ig-scr-kpi-denom {
425
+ font-size: 12px;
426
+ font-weight: 400;
427
+ color: var(--dsw-alias-label-tertiary, #64748b);
428
+ }
429
+
430
+ /* 推薦貼文條目列表 */
431
+ .ig-scr-rec-list {
432
+ display: flex;
433
+ flex-direction: column;
434
+ gap: 10px;
435
+ }
436
+ .ig-scr-rec-item {
437
+ background: rgba(255, 255, 255, 0.02);
438
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.06));
439
+ border-radius: 8px;
440
+ padding: 12px 16px;
441
+ display: flex;
442
+ flex-direction: column;
443
+ gap: 6px;
444
+ }
445
+ .ig-scr-rec-head {
446
+ display: flex;
447
+ align-items: center;
448
+ justify-content: space-between;
449
+ }
450
+ .ig-scr-rec-author {
451
+ font-size: 12.5px;
452
+ font-weight: 600;
453
+ color: #60a5fa;
454
+ }
455
+ .ig-scr-rec-score {
456
+ font-size: 11px;
457
+ font-weight: 600;
458
+ padding: 2px 8px;
459
+ border-radius: 4px;
460
+ background: rgba(16, 185, 129, 0.12);
461
+ color: #34d399;
462
+ border: 1px solid rgba(16, 185, 129, 0.25);
463
+ font-variant-numeric: tabular-nums;
464
+ }
465
+ .ig-scr-rec-reason {
466
+ font-size: 11.5px;
467
+ color: var(--dsw-alias-label-secondary, #cbd5e1);
468
+ line-height: 1.4;
469
+ }
470
+ .ig-scr-rec-comment {
471
+ font-size: 11.5px;
472
+ font-family: monospace;
473
+ padding: 6px 10px;
474
+ border-radius: 4px;
475
+ background: rgba(0, 0, 0, 0.3);
476
+ border-left: 2px solid #3b82f6;
477
+ color: #93c5fd;
478
+ }
479
+
480
+ /* 按鈕樣式 */
481
+ .ig-scr-btn {
482
+ display: inline-flex;
483
+ align-items: center;
484
+ justify-content: center;
485
+ gap: 6px;
486
+ height: 34px;
487
+ padding: 0 14px;
488
+ border-radius: 6px;
489
+ font-size: 12px;
490
+ font-weight: 500;
491
+ cursor: pointer;
492
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
493
+ background: rgba(255, 255, 255, 0.05);
494
+ color: #f1f5f9;
495
+ transition: all 0.15s ease;
496
+ }
497
+ .ig-scr-btn:hover {
498
+ background: rgba(255, 255, 255, 0.1);
499
+ }
500
+ .ig-scr-btn.primary {
501
+ background: #2563eb;
502
+ border-color: #1d4ed8;
503
+ color: #ffffff;
504
+ font-weight: 600;
505
+ }
506
+ .ig-scr-btn.primary:hover {
507
+ background: #1d4ed8;
508
+ }
509
+ .ig-scr-btn:disabled {
510
+ opacity: 0.5;
511
+ cursor: not-allowed;
512
+ }
513
+
514
+ .ig-scr-footer {
515
+ display: flex;
516
+ align-items: center;
517
+ justify-content: space-between;
518
+ padding-top: 14px;
519
+ border-top: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
520
+ }
521
+ `
522
+
523
+ const cleanStr = (v, fallback = '') => {
524
+ if (typeof v === 'string') {
525
+ return v === '[object Object]' ? fallback : v
526
+ }
527
+ return fallback
528
+ }
529
+ const cleanNum = (v, fallback = 0) => {
530
+ if (typeof v === 'number' && !isNaN(v)) return v
531
+ if (typeof v === 'string') {
532
+ const n = Number(v)
533
+ if (!isNaN(n)) return n
534
+ }
535
+ return fallback
536
+ }
537
+ const cleanArr = (v, fallback = []) => (Array.isArray(v) ? v : fallback)
538
+ const cleanBool = (v, fallback = false) => (typeof v === 'boolean' ? v : fallback)
539
+
540
+ const normalizeScrollConfig = (raw) => {
541
+ const c = (raw && typeof raw === 'object' && !Array.isArray(raw)) ? raw : {}
542
+ return {
543
+ masterUsername: cleanStr(c.masterUsername, ''),
544
+ interestTags: cleanArr(c.interestTags, ['ai', 'deepseek', 'coding', 'tech', 'gadgets']),
545
+ personaPrompt: cleanStr(c.personaPrompt, '你是一位洞察力敏銳、品味高雅的社群特助。請評估這篇 Instagram 貼文/影片是否具有前沿乾貨、創意見解、實用價值或視覺驚艷。若是主人會感興趣的好內容,請給出大於80分的評價,並撰寫簡短自然、熱情真誠的推坑一句話。'),
546
+ minScore: cleanNum(c.minScore, 75),
547
+ dailyRecommendCap: cleanNum(c.dailyRecommendCap, 5),
548
+ scrollIntervalMinutes: cleanNum(c.scrollIntervalMinutes, 60),
549
+ autoScrollEnabled: cleanBool(c.autoScrollEnabled, true),
550
+ likeOnRecommend: cleanBool(c.likeOnRecommend, true),
551
+ batchSize: cleanNum(c.batchSize, 15),
552
+ }
553
+ }
554
+
555
+ function ScrollPanel() {
556
+ const [tab, setTab] = useState('feed')
557
+ const [cfg, setCfg] = useState(normalizeScrollConfig({}))
558
+ const [status, setStatus] = useState(null)
559
+ const [mcpStatus, setMcpStatus] = useState(null)
560
+ const [report, setReport] = useState('')
561
+ const [loading, setLoading] = useState(true)
562
+ const [saving, setSaving] = useState(false)
563
+ const [runningRound, setRunningRound] = useState(false)
564
+ const [msg, setMsg] = useState(null)
565
+
566
+ const refresh = async () => {
567
+ try {
568
+ const [cfgRes, statusRes, reportRes, mcpRes] = await Promise.all([
569
+ jget('/config').catch(() => null),
570
+ jget('/status').catch(() => null),
571
+ jget('/report').catch(() => null),
572
+ fetch('/api/instagram/mcp/status', { credentials: 'same-origin' })
573
+ .then((r) => r.json())
574
+ .catch(() => null),
575
+ ])
576
+ if (cfgRes?.ok) setCfg(normalizeScrollConfig(cfgRes.config))
577
+ if (statusRes?.ok) setStatus(statusRes)
578
+ if (reportRes?.ok) setReport(reportRes.report || '')
579
+ if (mcpRes?.ok) setMcpStatus(mcpRes)
580
+ } catch (e) {
581
+ setMsg(`讀取狀態失敗: ${e.message}`)
582
+ } finally {
583
+ setLoading(false)
584
+ }
585
+ }
586
+
587
+ useEffect(() => {
588
+ refresh()
589
+ }, [])
590
+
591
+ const updateField = (k, v) => setCfg((prev) => ({ ...prev, [k]: v }))
592
+
593
+ const save = async () => {
594
+ setSaving(true)
595
+ setMsg(null)
596
+ try {
597
+ const cleanPayload = normalizeScrollConfig(cfg)
598
+ const res = await jpost('/config', cleanPayload)
599
+ if (res?.ok) {
600
+ setCfg(normalizeScrollConfig(res.config))
601
+ setMsg('✅ 滾動推坑設定已成功保存!')
602
+ }
603
+ } catch (e) {
604
+ setMsg(`保存失敗: ${e.message}`)
605
+ } finally {
606
+ setSaving(false)
607
+ }
608
+ }
609
+
610
+ const runNow = async () => {
611
+ setRunningRound(true)
612
+ setMsg(null)
613
+ try {
614
+ const res = await jpost('/run', {})
615
+ if (res?.ok) {
616
+ setMsg(res.message || '本輪滾動推坑完成!')
617
+ }
618
+ await refresh()
619
+ } catch (e) {
620
+ setMsg(`執行失敗: ${e.message}`)
621
+ } finally {
622
+ setRunningRound(false)
623
+ }
624
+ }
625
+
626
+ if (loading) {
627
+ return h('div', { className: 'ig-scr-root' }, '正在載入 Instagram 滾動推坑設定...')
628
+ }
629
+
630
+ const daily = status?.dailyStats || {}
631
+ const recommendedItems = daily.recommendedItems || []
632
+
633
+ const isMcpConnected = Boolean(
634
+ status?.mcpReady ||
635
+ status?.loginStatus?.ok ||
636
+ mcpStatus?.mcpReady ||
637
+ mcpStatus?.loginStatus?.ok
638
+ )
639
+
640
+ const rawAccount =
641
+ status?.mcpAccount ||
642
+ status?.loginStatus?.username ||
643
+ mcpStatus?.loginStatus?.username ||
644
+ (mcpStatus?.loginStatus?.message?.match(/@([^\s)]+)/)?.[1]) ||
645
+ (isMcpConnected ? '已連線' : '')
646
+
647
+ const displayAccount = rawAccount ? rawAccount.replace(/^@/, '') : ''
648
+
649
+ return h(
650
+ 'div',
651
+ { className: 'ig-scr-root' },
652
+
653
+ // 頂部標頭列
654
+ h(
655
+ 'div',
656
+ { className: 'ig-scr-header' },
657
+ h(
658
+ 'div',
659
+ { className: 'ig-scr-brand-row' },
660
+ h('div', { className: 'ig-scr-brand-mark' }, h(Icon.Scroll, { size: 20 })),
661
+ h(
662
+ 'div',
663
+ null,
664
+ h('div', { className: 'ig-scr-brand-title' }, 'Instagram 滾動探索與主人推坑'),
665
+ h(
666
+ 'div',
667
+ { className: 'ig-scr-brand-sub', style: { display: 'flex', alignItems: 'center', gap: '8px' } },
668
+ cfg.masterUsername ? `目標主人: @${cfg.masterUsername.replace(/^@/, '')}` : '尚未綁定主人帳號',
669
+ h('span', { style: { color: 'rgba(255, 255, 255, 0.2)' } }, '|'),
670
+ isMcpConnected
671
+ ? h(
672
+ 'span',
673
+ { style: { color: '#34d399', fontSize: '11px', display: 'inline-flex', alignItems: 'center', gap: '4px' } },
674
+ h('span', { style: { width: '6px', height: '6px', borderRadius: '50%', background: '#10b981' } }),
675
+ `MCP 會話: @${displayAccount || '已連線'}`
676
+ )
677
+ : h(
678
+ 'span',
679
+ { style: { color: '#fbbf24', fontSize: '11px', display: 'inline-flex', alignItems: 'center', gap: '4px' } },
680
+ h('span', { style: { width: '6px', height: '6px', borderRadius: '50%', background: '#f59e0b' } }),
681
+ '等待 MCP 登入'
682
+ )
683
+ )
684
+ )
685
+ ),
686
+ h(
687
+ 'button',
688
+ {
689
+ className: 'ig-scr-btn primary',
690
+ disabled: runningRound || !isMcpConnected,
691
+ title: !isMcpConnected ? '等待 FastMCP 連線就緒後即可刷動態' : '立即替主人刷一輪動態',
692
+ onClick: runNow,
693
+ },
694
+ h(Icon.Play, { size: 12 }),
695
+ runningRound ? '正在替主人刷一輪...' : '🚀 現在替我刷一輪'
696
+ )
697
+ ),
698
+
699
+ // 分頁切換
700
+ h(
701
+ 'div',
702
+ { className: 'ig-scr-tabs' },
703
+ [
704
+ ['feed', Icon.Sparkles, '推薦與日報'],
705
+ ['master', Icon.User, '主人與偏好'],
706
+ ['schedule', Icon.Clock, '排程與配額'],
707
+ ].map(([id, IconCmp, label]) =>
708
+ h(
709
+ 'button',
710
+ {
711
+ key: id,
712
+ className: `ig-scr-tab-btn ${tab === id ? 'active' : ''}`,
713
+ onClick: () => setTab(id),
714
+ },
715
+ h(IconCmp, { size: 14 }),
716
+ label
717
+ )
718
+ )
719
+ ),
720
+
721
+ // 訊息通知
722
+ msg
723
+ ? h(
724
+ 'div',
725
+ {
726
+ style: {
727
+ padding: '9px 14px',
728
+ borderRadius: '6px',
729
+ background: 'rgba(59, 130, 246, 0.1)',
730
+ color: '#93c5fd',
731
+ borderLeft: '3px solid #3b82f6',
732
+ fontSize: '12px',
733
+ },
734
+ },
735
+ msg
736
+ )
737
+ : null,
738
+
739
+ // ====================================================================
740
+ // TAB 1: 推薦與日報 (Today's Feed & Report)
741
+ // ====================================================================
742
+ tab === 'feed'
743
+ ? h(
744
+ 'div',
745
+ { className: 'ig-scr-panel' },
746
+ h(
747
+ 'div',
748
+ { className: 'ig-scr-section-head' },
749
+ h('div', { className: 'ig-scr-section-title' }, '今日替主人刷貼文成果與日報'),
750
+ h('div', { className: 'ig-scr-section-desc' }, '統計今日自動審閱量、精選出的高質內容、以及在貼文留言 @主人的推坑紀錄。')
751
+ ),
752
+
753
+ h(
754
+ 'div',
755
+ { className: 'ig-scr-kpi-grid' },
756
+ h(
757
+ 'div',
758
+ { className: 'ig-scr-kpi-card' },
759
+ h('div', { className: 'ig-scr-kpi-title' }, '今日掃描審閱貼文'),
760
+ h('div', { className: 'ig-scr-kpi-val' }, daily.scrolledCount || 0)
761
+ ),
762
+ h(
763
+ 'div',
764
+ { className: 'ig-scr-kpi-card' },
765
+ h('div', { className: 'ig-scr-kpi-title' }, '今日留言 @主人 推薦'),
766
+ h(
767
+ 'div',
768
+ { className: 'ig-scr-kpi-val' },
769
+ daily.recommendedCount || 0,
770
+ h('span', { className: 'ig-scr-kpi-denom' }, `/ ${cfg.dailyRecommendCap || 5} 上限`)
771
+ )
772
+ ),
773
+ h(
774
+ 'div',
775
+ { className: 'ig-scr-kpi-card' },
776
+ h('div', { className: 'ig-scr-kpi-title' }, '推坑門檻標準'),
777
+ h('div', { className: 'ig-scr-kpi-val' }, `${cfg.minScore || 75}`, h('span', { className: 'ig-scr-kpi-denom' }, '/ 100 分'))
778
+ )
779
+ ),
780
+
781
+ // 今日推薦條目
782
+ recommendedItems.length > 0
783
+ ? h(
784
+ 'div',
785
+ { style: { display: 'flex', flexDirection: 'column', gap: '8px', marginTop: '4px' } },
786
+ h('div', { style: { fontSize: '12px', fontWeight: 600, color: '#f1f5f9' } }, '今日已推坑貼文清單:'),
787
+ h(
788
+ 'div',
789
+ { className: 'ig-scr-rec-list' },
790
+ recommendedItems.map((item, idx) =>
791
+ h(
792
+ 'div',
793
+ { key: item.postPk || idx, className: 'ig-scr-rec-item' },
794
+ h(
795
+ 'div',
796
+ { className: 'ig-scr-rec-head' },
797
+ h('div', { className: 'ig-scr-rec-author' }, `@${item.author}`),
798
+ h('div', { className: 'ig-scr-rec-score' }, `評分: ${item.score}`)
799
+ ),
800
+ h('div', { className: 'ig-scr-rec-reason' }, item.reason),
801
+ h('div', { className: 'ig-scr-rec-comment' }, item.commentText),
802
+ item.url
803
+ ? h(
804
+ 'a',
805
+ {
806
+ href: item.url,
807
+ target: '_blank',
808
+ rel: 'noopener noreferrer',
809
+ style: {
810
+ fontSize: '11px',
811
+ color: '#60a5fa',
812
+ display: 'inline-flex',
813
+ alignItems: 'center',
814
+ gap: '4px',
815
+ textDecoration: 'none',
816
+ alignSelf: 'flex-start',
817
+ },
818
+ },
819
+ h(Icon.ExternalLink, { size: 12 }),
820
+ '開啟 Instagram 貼文'
821
+ )
822
+ : null
823
+ )
824
+ )
825
+ )
826
+ )
827
+ : h(
828
+ 'div',
829
+ {
830
+ style: {
831
+ padding: '24px 16px',
832
+ textAlign: 'center',
833
+ color: '#64748b',
834
+ fontSize: '12.5px',
835
+ background: 'rgba(255,255,255,0.015)',
836
+ borderRadius: '8px',
837
+ border: '1px dashed rgba(255,255,255,0.08)',
838
+ },
839
+ },
840
+ '今日尚未發現足夠高分的推坑貼文,點擊右上角「現在替我刷一輪」即刻開始探索!'
841
+ )
842
+ )
843
+ : null,
844
+
845
+ // ====================================================================
846
+ // TAB 2: 主人與偏好 (Master & Interests)
847
+ // ====================================================================
848
+ tab === 'master'
849
+ ? h(
850
+ 'div',
851
+ { className: 'ig-scr-panel' },
852
+ h(
853
+ 'div',
854
+ { className: 'ig-scr-section-head' },
855
+ h('div', { className: 'ig-scr-section-title' }, '主人身分與興趣偏好配置'),
856
+ h('div', { className: 'ig-scr-section-desc' }, '設定主人的 Instagram 帳號名與感興趣的標籤領域,AI 將依此進行嚴格內容篩選。')
857
+ ),
858
+
859
+ // MCP Session 來源提示
860
+ h(
861
+ 'div',
862
+ {
863
+ style: {
864
+ background: 'rgba(59, 130, 246, 0.06)',
865
+ border: '1px solid rgba(59, 130, 246, 0.2)',
866
+ borderRadius: '8px',
867
+ padding: '10px 14px',
868
+ fontSize: '12px',
869
+ color: '#93c5fd',
870
+ display: 'flex',
871
+ alignItems: 'center',
872
+ gap: '8px',
873
+ },
874
+ },
875
+ h(Icon.Sparkles, { size: 14 }),
876
+ h(
877
+ 'span',
878
+ null,
879
+ isMcpConnected
880
+ ? `已沿用 @luoyi-dsh/instagram-mcp 的登入會話 (@${displayAccount || '已授權'}),本外掛無需填寫帳密。`
881
+ : '本外掛無需輸入帳密,直接沿用依賴的 dsh-instagram-mcp 獲取之 Session。目前 MCP 尚未登入,請先至 MCP 面板完成登入。'
882
+ )
883
+ ),
884
+
885
+ h(
886
+ 'div',
887
+ { className: 'ig-scr-field' },
888
+ h('label', { className: 'ig-scr-label' }, '🎯 主人 Instagram 帳號 (Master Username)'),
889
+ h('input', {
890
+ className: 'ig-scr-input',
891
+ value: cleanStr(cfg.masterUsername),
892
+ placeholder: '例如 your_main_account (可不帶 @)',
893
+ onChange: (e) => updateField('masterUsername', e.target.value.replace(/^@/, '').trim()),
894
+ }),
895
+ h('div', { className: 'ig-scr-hint' }, '發現值得推薦的貼文/影片時,會在留言區 @ 此帳號進行推薦')
896
+ ),
897
+
898
+ h(
899
+ 'div',
900
+ { className: 'ig-scr-field' },
901
+ h('label', { className: 'ig-scr-label' }, '🏷️ 主人感興趣的主題標籤 (Interest Tags)'),
902
+ h('input', {
903
+ className: 'ig-scr-input',
904
+ value: Array.isArray(cfg.interestTags) ? cfg.interestTags.join(', ') : '',
905
+ placeholder: 'ai, deepseek, coding, photography, gadgets, travel',
906
+ onChange: (e) =>
907
+ updateField(
908
+ 'interestTags',
909
+ e.target.value.split(',').map((s) => s.trim().replace(/^#/, '')).filter(Boolean)
910
+ ),
911
+ }),
912
+ h('div', { className: 'ig-scr-hint' }, '多個標籤請用逗號分隔,除時間軸外亦會輪流針對這些主題進行深度探索')
913
+ ),
914
+
915
+ h(
916
+ 'div',
917
+ { className: 'ig-scr-field' },
918
+ h('label', { className: 'ig-scr-label' }, '💡 貼文評估人設與推薦 Prompt'),
919
+ h('textarea', {
920
+ className: 'ig-scr-textarea',
921
+ value: cleanStr(cfg.personaPrompt),
922
+ onChange: (e) => updateField('personaPrompt', e.target.value),
923
+ }),
924
+ h('div', { className: 'ig-scr-hint' }, '定義如何研判貼文是否具備足夠乾貨、原創性與吸引力')
925
+ )
926
+ )
927
+ : null,
928
+
929
+ // ====================================================================
930
+ // TAB 3: 排程與配額 (Schedule & Limits)
931
+ // ====================================================================
932
+ tab === 'schedule'
933
+ ? h(
934
+ 'div',
935
+ { className: 'ig-scr-panel' },
936
+ h(
937
+ 'div',
938
+ { className: 'ig-scr-section-head' },
939
+ h('div', { className: 'ig-scr-section-title' }, '背景排程與安全風控配額'),
940
+ h('div', { className: 'ig-scr-section-desc' }, '限制推坑頻率與留言次數,保護 IG 帳號安全並避免對主人造成疲勞轟炸。')
941
+ ),
942
+
943
+ h(
944
+ 'div',
945
+ { className: 'ig-scr-switch' },
946
+ h(
947
+ 'div',
948
+ { className: 'ig-scr-switch-text' },
949
+ h('div', { className: 'ig-scr-switch-name' }, '啟用定時自動刷動態牆'),
950
+ h('div', { className: 'ig-scr-hint' }, '依照下方設定的週期在背景自動替主人刷貼文並推坑')
951
+ ),
952
+ h(
953
+ 'button',
954
+ {
955
+ className: `ig-scr-toggle ${cfg.autoScrollEnabled ? 'on' : ''}`,
956
+ onClick: () => updateField('autoScrollEnabled', !cfg.autoScrollEnabled),
957
+ },
958
+ h('span', { className: 'ig-scr-toggle-thumb' })
959
+ )
960
+ ),
961
+
962
+ h(
963
+ 'div',
964
+ { className: 'ig-scr-switch' },
965
+ h(
966
+ 'div',
967
+ { className: 'ig-scr-switch-text' },
968
+ h('div', { className: 'ig-scr-switch-name' }, '推薦貼文時自動按讚'),
969
+ h('div', { className: 'ig-scr-hint' }, '替主人留言推坑的同時,自動在貼文留下愛心點讚')
970
+ ),
971
+ h(
972
+ 'button',
973
+ {
974
+ className: `ig-scr-toggle ${cfg.likeOnRecommend ? 'on' : ''}`,
975
+ onClick: () => updateField('likeOnRecommend', !cfg.likeOnRecommend),
976
+ },
977
+ h('span', { className: 'ig-scr-toggle-thumb' })
978
+ )
979
+ ),
980
+
981
+ h(
982
+ 'div',
983
+ { className: 'ig-scr-grid-2' },
984
+ h(
985
+ 'div',
986
+ { className: 'ig-scr-field' },
987
+ h('label', { className: 'ig-scr-label' }, '巡查週期 (分鐘)'),
988
+ h('input', {
989
+ type: 'number',
990
+ className: 'ig-scr-input',
991
+ value: cfg.scrollIntervalMinutes ?? 60,
992
+ onChange: (e) => updateField('scrollIntervalMinutes', Number(e.target.value)),
993
+ }),
994
+ h('div', { className: 'ig-scr-hint' }, '背景自動執行的時間間隔')
995
+ ),
996
+ h(
997
+ 'div',
998
+ { className: 'ig-scr-field' },
999
+ h('label', { className: 'ig-scr-label' }, '每日向主人推坑上限 (則)'),
1000
+ h('input', {
1001
+ type: 'number',
1002
+ className: 'ig-scr-input',
1003
+ value: cfg.dailyRecommendCap ?? 5,
1004
+ onChange: (e) => updateField('dailyRecommendCap', Number(e.target.value)),
1005
+ }),
1006
+ h('div', { className: 'ig-scr-hint' }, '每日達到此推坑則數後自動停止留評 @主人')
1007
+ )
1008
+ ),
1009
+
1010
+ h(
1011
+ 'div',
1012
+ { className: 'ig-scr-grid-2' },
1013
+ h(
1014
+ 'div',
1015
+ { className: 'ig-scr-field' },
1016
+ h('label', { className: 'ig-scr-label' }, '最低推薦分數門檻 (0-100)'),
1017
+ h('input', {
1018
+ type: 'number',
1019
+ className: 'ig-scr-input',
1020
+ value: cfg.minScore ?? 75,
1021
+ onChange: (e) => updateField('minScore', Number(e.target.value)),
1022
+ }),
1023
+ h('div', { className: 'ig-scr-hint' }, '高於此分數的貼文才會在留言區 @主人')
1024
+ ),
1025
+ h(
1026
+ 'div',
1027
+ { className: 'ig-scr-field' },
1028
+ h('label', { className: 'ig-scr-label' }, '每輪審閱抓取數量'),
1029
+ h('input', {
1030
+ type: 'number',
1031
+ className: 'ig-scr-input',
1032
+ value: cfg.batchSize ?? 15,
1033
+ onChange: (e) => updateField('batchSize', Number(e.target.value)),
1034
+ }),
1035
+ h('div', { className: 'ig-scr-hint' }, '單次滾動審閱貼文筆數')
1036
+ )
1037
+ )
1038
+ )
1039
+ : null,
1040
+
1041
+ // 底部儲存動作列
1042
+ h(
1043
+ 'div',
1044
+ { className: 'ig-scr-footer' },
1045
+ h('div', { style: { fontSize: '11.5px', color: '#64748b' } }, '修改設定後請點擊儲存,新設定將即刻寫入配置檔並生效。'),
1046
+ h(
1047
+ 'button',
1048
+ {
1049
+ className: 'ig-scr-btn primary',
1050
+ disabled: saving,
1051
+ onClick: save,
1052
+ },
1053
+ h(Icon.Save, { size: 14 }),
1054
+ saving ? '正在儲存...' : '儲存所有設定'
1055
+ )
1056
+ )
1057
+ )
1058
+ }
1059
+
1060
+ return {
1061
+ inject: ['slots'],
1062
+ apply(ctx) {
1063
+ try {
1064
+ if (!document.querySelector('style[data-plugin-css="dsh-instagram-scroll"]')) {
1065
+ const style = document.createElement('style')
1066
+ style.setAttribute('data-plugin-css', 'dsh-instagram-scroll')
1067
+ style.textContent = CSS
1068
+ document.head.appendChild(style)
1069
+ if (typeof ctx?.effect === 'function') {
1070
+ ctx.effect(() => () => style.remove(), 'dsh-instagram-scroll: style')
1071
+ }
1072
+ }
1073
+ } catch (e) {}
1074
+
1075
+ const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
1076
+ if (!slots) return
1077
+
1078
+ // 1. 左側一級專屬導航槽位 (settings.section)
1079
+ const registerSection = () => {
1080
+ try {
1081
+ slots.register(
1082
+ {
1083
+ name: 'settings.section',
1084
+ id: 'instagram-scroll',
1085
+ order: 36,
1086
+ label: 'Instagram 滾動',
1087
+ },
1088
+ () => h(ScrollPanel)
1089
+ )
1090
+ } catch (e) {
1091
+ console.error('[@luoyi-dsh/instagram-scroll] 註冊 settings.section 異常:', e)
1092
+ }
1093
+ }
1094
+ if (typeof slots.inject === 'function') {
1095
+ slots.inject('settings.section', registerSection)
1096
+ } else if (typeof slots.register === 'function') {
1097
+ registerSection()
1098
+ }
1099
+
1100
+ // 2. 外掛程式頁面頂部頁籤 (settings.plugins.tab)
1101
+ const registerTab = () => {
1102
+ try {
1103
+ slots.register(
1104
+ {
1105
+ name: 'settings.plugins.tab',
1106
+ id: 'instagram-scroll',
1107
+ order: 36,
1108
+ label: 'Instagram 滾動',
1109
+ },
1110
+ () => h(ScrollPanel)
1111
+ )
1112
+ } catch (e) {
1113
+ console.error('[@luoyi-dsh/instagram-scroll] 註冊 settings.plugins.tab 異常:', e)
1114
+ }
1115
+ }
1116
+ if (typeof slots.inject === 'function') {
1117
+ slots.inject('settings.plugins.tab', registerTab)
1118
+ } else if (typeof slots.register === 'function') {
1119
+ registerTab()
1120
+ }
1121
+
1122
+ // 3. 外掛程式卡片列表槽位 (plugins.item)
1123
+ const registerItem = () => {
1124
+ try {
1125
+ slots.register(
1126
+ {
1127
+ name: 'plugins.item',
1128
+ id: 'instagram-scroll',
1129
+ order: 36,
1130
+ label: 'Instagram 滾動探索與推坑',
1131
+ },
1132
+ () => h(ScrollPanel)
1133
+ )
1134
+ } catch (e) {
1135
+ console.error('[@luoyi-dsh/instagram-scroll] 註冊 plugins.item 異常:', e)
1136
+ }
1137
+ }
1138
+ if (typeof slots.inject === 'function') {
1139
+ slots.inject('plugins.item', registerItem)
1140
+ } else if (typeof slots.register === 'function') {
1141
+ registerItem()
1142
+ }
1143
+ },
1144
+ }
1145
+ },
1146
+ })