@luoyi-dsh/instagram-scroll 0.0.0-stage → 1.0.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/client.js ADDED
@@ -0,0 +1,1060 @@
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: '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 [report, setReport] = useState('')
560
+ const [loading, setLoading] = useState(true)
561
+ const [saving, setSaving] = useState(false)
562
+ const [runningRound, setRunningRound] = useState(false)
563
+ const [msg, setMsg] = useState(null)
564
+
565
+ const refresh = async () => {
566
+ try {
567
+ const [cfgRes, statusRes, reportRes] = await Promise.all([
568
+ jget('/config'),
569
+ jget('/status'),
570
+ jget('/report'),
571
+ ])
572
+ if (cfgRes?.ok) setCfg(normalizeScrollConfig(cfgRes.config))
573
+ if (statusRes?.ok) setStatus(statusRes)
574
+ if (reportRes?.ok) setReport(reportRes.report || '')
575
+ } catch (e) {
576
+ setMsg(`讀取狀態失敗: ${e.message}`)
577
+ } finally {
578
+ setLoading(false)
579
+ }
580
+ }
581
+
582
+ useEffect(() => {
583
+ refresh()
584
+ }, [])
585
+
586
+ const updateField = (k, v) => setCfg((prev) => ({ ...prev, [k]: v }))
587
+
588
+ const save = async () => {
589
+ setSaving(true)
590
+ setMsg(null)
591
+ try {
592
+ const cleanPayload = normalizeScrollConfig(cfg)
593
+ const res = await jpost('/config', cleanPayload)
594
+ if (res?.ok) {
595
+ setCfg(normalizeScrollConfig(res.config))
596
+ setMsg('✅ 滾動推坑設定已成功保存!')
597
+ }
598
+ } catch (e) {
599
+ setMsg(`保存失敗: ${e.message}`)
600
+ } finally {
601
+ setSaving(false)
602
+ }
603
+ }
604
+
605
+ const runNow = async () => {
606
+ setRunningRound(true)
607
+ setMsg(null)
608
+ try {
609
+ const res = await jpost('/run', {})
610
+ if (res?.ok) {
611
+ setMsg(res.message || '本輪滾動推坑完成!')
612
+ }
613
+ await refresh()
614
+ } catch (e) {
615
+ setMsg(`執行失敗: ${e.message}`)
616
+ } finally {
617
+ setRunningRound(false)
618
+ }
619
+ }
620
+
621
+ if (loading) {
622
+ return h('div', { className: 'ig-scr-root' }, '正在載入 Instagram 滾動推坑設定...')
623
+ }
624
+
625
+ const daily = status?.dailyStats || {}
626
+ const recommendedItems = daily.recommendedItems || []
627
+
628
+ return h(
629
+ 'div',
630
+ { className: 'ig-scr-root' },
631
+
632
+ // 頂部標頭列
633
+ h(
634
+ 'div',
635
+ { className: 'ig-scr-header' },
636
+ h(
637
+ 'div',
638
+ { className: 'ig-scr-brand-row' },
639
+ h('div', { className: 'ig-scr-brand-mark' }, h(Icon.Scroll, { size: 20 })),
640
+ h(
641
+ 'div',
642
+ null,
643
+ h('div', { className: 'ig-scr-brand-title' }, 'Instagram 滾動探索與主人推坑'),
644
+ h(
645
+ 'div',
646
+ { className: 'ig-scr-brand-sub' },
647
+ cfg.masterUsername ? `當前主人目標: @${cfg.masterUsername.replace(/^@/, '')}` : '尚未綁定主人帳號'
648
+ )
649
+ )
650
+ ),
651
+ h(
652
+ 'button',
653
+ {
654
+ className: 'ig-scr-btn primary',
655
+ disabled: runningRound,
656
+ onClick: runNow,
657
+ },
658
+ h(Icon.Play, { size: 12 }),
659
+ runningRound ? '正在替主人刷一輪...' : '🚀 現在替我刷一輪'
660
+ )
661
+ ),
662
+
663
+ // 分頁切換
664
+ h(
665
+ 'div',
666
+ { className: 'ig-scr-tabs' },
667
+ [
668
+ ['feed', Icon.Sparkles, '推薦與日報'],
669
+ ['master', Icon.User, '主人與偏好'],
670
+ ['schedule', Icon.Clock, '排程與配額'],
671
+ ].map(([id, IconCmp, label]) =>
672
+ h(
673
+ 'button',
674
+ {
675
+ key: id,
676
+ className: `ig-scr-tab-btn ${tab === id ? 'active' : ''}`,
677
+ onClick: () => setTab(id),
678
+ },
679
+ h(IconCmp, { size: 14 }),
680
+ label
681
+ )
682
+ )
683
+ ),
684
+
685
+ // 訊息通知
686
+ msg
687
+ ? h(
688
+ 'div',
689
+ {
690
+ style: {
691
+ padding: '9px 14px',
692
+ borderRadius: '6px',
693
+ background: 'rgba(59, 130, 246, 0.1)',
694
+ color: '#93c5fd',
695
+ borderLeft: '3px solid #3b82f6',
696
+ fontSize: '12px',
697
+ },
698
+ },
699
+ msg
700
+ )
701
+ : null,
702
+
703
+ // ====================================================================
704
+ // TAB 1: 推薦與日報 (Today's Feed & Report)
705
+ // ====================================================================
706
+ tab === 'feed'
707
+ ? h(
708
+ 'div',
709
+ { className: 'ig-scr-panel' },
710
+ h(
711
+ 'div',
712
+ { className: 'ig-scr-section-head' },
713
+ h('div', { className: 'ig-scr-section-title' }, '今日替主人刷貼文成果與日報'),
714
+ h('div', { className: 'ig-scr-section-desc' }, '統計今日自動審閱量、精選出的高質內容、以及在貼文留言 @主人的推坑紀錄。')
715
+ ),
716
+
717
+ h(
718
+ 'div',
719
+ { className: 'ig-scr-kpi-grid' },
720
+ h(
721
+ 'div',
722
+ { className: 'ig-scr-kpi-card' },
723
+ h('div', { className: 'ig-scr-kpi-title' }, '今日掃描審閱貼文'),
724
+ h('div', { className: 'ig-scr-kpi-val' }, daily.scrolledCount || 0)
725
+ ),
726
+ h(
727
+ 'div',
728
+ { className: 'ig-scr-kpi-card' },
729
+ h('div', { className: 'ig-scr-kpi-title' }, '今日留言 @主人 推薦'),
730
+ h(
731
+ 'div',
732
+ { className: 'ig-scr-kpi-val' },
733
+ daily.recommendedCount || 0,
734
+ h('span', { className: 'ig-scr-kpi-denom' }, `/ ${cfg.dailyRecommendCap || 5} 上限`)
735
+ )
736
+ ),
737
+ h(
738
+ 'div',
739
+ { className: 'ig-scr-kpi-card' },
740
+ h('div', { className: 'ig-scr-kpi-title' }, '推坑門檻標準'),
741
+ h('div', { className: 'ig-scr-kpi-val' }, `${cfg.minScore || 75}`, h('span', { className: 'ig-scr-kpi-denom' }, '/ 100 分'))
742
+ )
743
+ ),
744
+
745
+ // 今日推薦條目
746
+ recommendedItems.length > 0
747
+ ? h(
748
+ 'div',
749
+ { style: { display: 'flex', flexDirection: 'column', gap: '8px', marginTop: '4px' } },
750
+ h('div', { style: { fontSize: '12px', fontWeight: 600, color: '#f1f5f9' } }, '今日已推坑貼文清單:'),
751
+ h(
752
+ 'div',
753
+ { className: 'ig-scr-rec-list' },
754
+ recommendedItems.map((item, idx) =>
755
+ h(
756
+ 'div',
757
+ { key: item.postPk || idx, className: 'ig-scr-rec-item' },
758
+ h(
759
+ 'div',
760
+ { className: 'ig-scr-rec-head' },
761
+ h('div', { className: 'ig-scr-rec-author' }, `@${item.author}`),
762
+ h('div', { className: 'ig-scr-rec-score' }, `評分: ${item.score}`)
763
+ ),
764
+ h('div', { className: 'ig-scr-rec-reason' }, item.reason),
765
+ h('div', { className: 'ig-scr-rec-comment' }, item.commentText),
766
+ item.url
767
+ ? h(
768
+ 'a',
769
+ {
770
+ href: item.url,
771
+ target: '_blank',
772
+ rel: 'noopener noreferrer',
773
+ style: {
774
+ fontSize: '11px',
775
+ color: '#60a5fa',
776
+ display: 'inline-flex',
777
+ alignItems: 'center',
778
+ gap: '4px',
779
+ textDecoration: 'none',
780
+ alignSelf: 'flex-start',
781
+ },
782
+ },
783
+ h(Icon.ExternalLink, { size: 12 }),
784
+ '開啟 Instagram 貼文'
785
+ )
786
+ : null
787
+ )
788
+ )
789
+ )
790
+ )
791
+ : h(
792
+ 'div',
793
+ {
794
+ style: {
795
+ padding: '24px 16px',
796
+ textAlign: 'center',
797
+ color: '#64748b',
798
+ fontSize: '12.5px',
799
+ background: 'rgba(255,255,255,0.015)',
800
+ borderRadius: '8px',
801
+ border: '1px dashed rgba(255,255,255,0.08)',
802
+ },
803
+ },
804
+ '今日尚未發現足夠高分的推坑貼文,點擊右上角「現在替我刷一輪」即刻開始探索!'
805
+ )
806
+ )
807
+ : null,
808
+
809
+ // ====================================================================
810
+ // TAB 2: 主人與偏好 (Master & Interests)
811
+ // ====================================================================
812
+ tab === 'master'
813
+ ? h(
814
+ 'div',
815
+ { className: 'ig-scr-panel' },
816
+ h(
817
+ 'div',
818
+ { className: 'ig-scr-section-head' },
819
+ h('div', { className: 'ig-scr-section-title' }, '主人身分與興趣偏好配置'),
820
+ h('div', { className: 'ig-scr-section-desc' }, '設定主人的 Instagram 帳號名與感興趣的標籤領域,AI 將依此進行嚴格內容篩選。')
821
+ ),
822
+
823
+ h(
824
+ 'div',
825
+ { className: 'ig-scr-field' },
826
+ h('label', { className: 'ig-scr-label' }, '🎯 主人 Instagram 帳號 (Master Username)'),
827
+ h('input', {
828
+ className: 'ig-scr-input',
829
+ value: cleanStr(cfg.masterUsername),
830
+ placeholder: '例如 your_main_account (可不帶 @)',
831
+ onChange: (e) => updateField('masterUsername', e.target.value.replace(/^@/, '').trim()),
832
+ }),
833
+ h('div', { className: 'ig-scr-hint' }, '發現值得推薦的貼文/影片時,會在留言區 @ 此帳號進行推薦')
834
+ ),
835
+
836
+ h(
837
+ 'div',
838
+ { className: 'ig-scr-field' },
839
+ h('label', { className: 'ig-scr-label' }, '🏷️ 主人感興趣的主題標籤 (Interest Tags)'),
840
+ h('input', {
841
+ className: 'ig-scr-input',
842
+ value: Array.isArray(cfg.interestTags) ? cfg.interestTags.join(', ') : '',
843
+ placeholder: 'ai, deepseek, coding, photography, gadgets, travel',
844
+ onChange: (e) =>
845
+ updateField(
846
+ 'interestTags',
847
+ e.target.value.split(',').map((s) => s.trim().replace(/^#/, '')).filter(Boolean)
848
+ ),
849
+ }),
850
+ h('div', { className: 'ig-scr-hint' }, '多個標籤請用逗號分隔,除時間軸外亦會輪流針對這些主題進行深度探索')
851
+ ),
852
+
853
+ h(
854
+ 'div',
855
+ { className: 'ig-scr-field' },
856
+ h('label', { className: 'ig-scr-label' }, '💡 貼文評估人設與推薦 Prompt'),
857
+ h('textarea', {
858
+ className: 'ig-scr-textarea',
859
+ value: cleanStr(cfg.personaPrompt),
860
+ onChange: (e) => updateField('personaPrompt', e.target.value),
861
+ }),
862
+ h('div', { className: 'ig-scr-hint' }, '定義如何研判貼文是否具備足夠乾貨、原創性與吸引力')
863
+ )
864
+ )
865
+ : null,
866
+
867
+ // ====================================================================
868
+ // TAB 3: 排程與配額 (Schedule & Limits)
869
+ // ====================================================================
870
+ tab === 'schedule'
871
+ ? h(
872
+ 'div',
873
+ { className: 'ig-scr-panel' },
874
+ h(
875
+ 'div',
876
+ { className: 'ig-scr-section-head' },
877
+ h('div', { className: 'ig-scr-section-title' }, '背景排程與安全風控配額'),
878
+ h('div', { className: 'ig-scr-section-desc' }, '限制推坑頻率與留言次數,保護 IG 帳號安全並避免對主人造成疲勞轟炸。')
879
+ ),
880
+
881
+ h(
882
+ 'div',
883
+ { className: 'ig-scr-switch' },
884
+ h(
885
+ 'div',
886
+ { className: 'ig-scr-switch-text' },
887
+ h('div', { className: 'ig-scr-switch-name' }, '啟用定時自動刷動態牆'),
888
+ h('div', { className: 'ig-scr-hint' }, '依照下方設定的週期在背景自動替主人刷貼文並推坑')
889
+ ),
890
+ h(
891
+ 'button',
892
+ {
893
+ className: `ig-scr-toggle ${cfg.autoScrollEnabled ? 'on' : ''}`,
894
+ onClick: () => updateField('autoScrollEnabled', !cfg.autoScrollEnabled),
895
+ },
896
+ h('span', { className: 'ig-scr-toggle-thumb' })
897
+ )
898
+ ),
899
+
900
+ h(
901
+ 'div',
902
+ { className: 'ig-scr-switch' },
903
+ h(
904
+ 'div',
905
+ { className: 'ig-scr-switch-text' },
906
+ h('div', { className: 'ig-scr-switch-name' }, '推薦貼文時自動按讚'),
907
+ h('div', { className: 'ig-scr-hint' }, '替主人留言推坑的同時,自動在貼文留下愛心點讚')
908
+ ),
909
+ h(
910
+ 'button',
911
+ {
912
+ className: `ig-scr-toggle ${cfg.likeOnRecommend ? 'on' : ''}`,
913
+ onClick: () => updateField('likeOnRecommend', !cfg.likeOnRecommend),
914
+ },
915
+ h('span', { className: 'ig-scr-toggle-thumb' })
916
+ )
917
+ ),
918
+
919
+ h(
920
+ 'div',
921
+ { className: 'ig-scr-grid-2' },
922
+ h(
923
+ 'div',
924
+ { className: 'ig-scr-field' },
925
+ h('label', { className: 'ig-scr-label' }, '巡查週期 (分鐘)'),
926
+ h('input', {
927
+ type: 'number',
928
+ className: 'ig-scr-input',
929
+ value: cfg.scrollIntervalMinutes ?? 60,
930
+ onChange: (e) => updateField('scrollIntervalMinutes', Number(e.target.value)),
931
+ }),
932
+ h('div', { className: 'ig-scr-hint' }, '背景自動執行的時間間隔')
933
+ ),
934
+ h(
935
+ 'div',
936
+ { className: 'ig-scr-field' },
937
+ h('label', { className: 'ig-scr-label' }, '每日向主人推坑上限 (則)'),
938
+ h('input', {
939
+ type: 'number',
940
+ className: 'ig-scr-input',
941
+ value: cfg.dailyRecommendCap ?? 5,
942
+ onChange: (e) => updateField('dailyRecommendCap', Number(e.target.value)),
943
+ }),
944
+ h('div', { className: 'ig-scr-hint' }, '每日達到此推坑則數後自動停止留評 @主人')
945
+ )
946
+ ),
947
+
948
+ h(
949
+ 'div',
950
+ { className: 'ig-scr-grid-2' },
951
+ h(
952
+ 'div',
953
+ { className: 'ig-scr-field' },
954
+ h('label', { className: 'ig-scr-label' }, '最低推薦分數門檻 (0-100)'),
955
+ h('input', {
956
+ type: 'number',
957
+ className: 'ig-scr-input',
958
+ value: cfg.minScore ?? 75,
959
+ onChange: (e) => updateField('minScore', Number(e.target.value)),
960
+ }),
961
+ h('div', { className: 'ig-scr-hint' }, '高於此分數的貼文才會在留言區 @主人')
962
+ ),
963
+ h(
964
+ 'div',
965
+ { className: 'ig-scr-field' },
966
+ h('label', { className: 'ig-scr-label' }, '每輪審閱抓取數量'),
967
+ h('input', {
968
+ type: 'number',
969
+ className: 'ig-scr-input',
970
+ value: cfg.batchSize ?? 15,
971
+ onChange: (e) => updateField('batchSize', Number(e.target.value)),
972
+ }),
973
+ h('div', { className: 'ig-scr-hint' }, '單次滾動審閱貼文筆數')
974
+ )
975
+ )
976
+ )
977
+ : null,
978
+
979
+ // 底部儲存動作列
980
+ h(
981
+ 'div',
982
+ { className: 'ig-scr-footer' },
983
+ h('div', { style: { fontSize: '11.5px', color: '#64748b' } }, '修改設定後請點擊儲存,新設定將即刻寫入配置檔並生效。'),
984
+ h(
985
+ 'button',
986
+ {
987
+ className: 'ig-scr-btn primary',
988
+ disabled: saving,
989
+ onClick: save,
990
+ },
991
+ h(Icon.Save, { size: 14 }),
992
+ saving ? '正在儲存...' : '儲存所有設定'
993
+ )
994
+ )
995
+ )
996
+ }
997
+
998
+ return {
999
+ inject: ['slots'],
1000
+ apply(ctx) {
1001
+ try {
1002
+ if (!document.querySelector('style[data-plugin-css="dsh-instagram-scroll"]')) {
1003
+ const style = document.createElement('style')
1004
+ style.setAttribute('data-plugin-css', 'dsh-instagram-scroll')
1005
+ style.textContent = CSS
1006
+ document.head.appendChild(style)
1007
+ if (typeof ctx?.effect === 'function') {
1008
+ ctx.effect(() => () => style.remove(), 'dsh-instagram-scroll: style')
1009
+ }
1010
+ }
1011
+ } catch (e) {}
1012
+
1013
+ const slots = (typeof ctx.get === 'function' ? ctx.get('slots') : undefined) || ctx.slots
1014
+ if (!slots) return
1015
+
1016
+ try {
1017
+ slots.inject('settings.section', () =>
1018
+ slots.register(
1019
+ {
1020
+ name: 'settings.section',
1021
+ id: 'instagram-scroll',
1022
+ order: 33,
1023
+ label: 'Instagram 滾動推坑',
1024
+ },
1025
+ () => h(ScrollPanel)
1026
+ )
1027
+ )
1028
+ } catch (e) {}
1029
+
1030
+ try {
1031
+ slots.inject('settings.plugins.tab', () =>
1032
+ slots.register(
1033
+ {
1034
+ name: 'settings.plugins.tab',
1035
+ id: 'instagram-scroll',
1036
+ order: 33,
1037
+ label: 'Instagram 滾動推坑',
1038
+ },
1039
+ () => h(ScrollPanel)
1040
+ )
1041
+ )
1042
+ } catch (e) {}
1043
+
1044
+ try {
1045
+ slots.inject('plugins.item', () =>
1046
+ slots.register(
1047
+ {
1048
+ name: 'plugins.item',
1049
+ id: 'instagram-scroll',
1050
+ order: 33,
1051
+ label: 'Instagram 滾動探索與推坑',
1052
+ },
1053
+ () => h(ScrollPanel)
1054
+ )
1055
+ )
1056
+ } catch (e) {}
1057
+ },
1058
+ }
1059
+ },
1060
+ })