@web-auto/camo 0.1.2 → 0.1.4
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/README.md +137 -0
- package/package.json +7 -3
- package/scripts/check-file-size.mjs +80 -0
- package/scripts/file-size-policy.json +8 -0
- package/src/autoscript/action-providers/index.mjs +9 -0
- package/src/autoscript/action-providers/xhs/comments.mjs +412 -0
- package/src/autoscript/action-providers/xhs/common.mjs +77 -0
- package/src/autoscript/action-providers/xhs/detail.mjs +181 -0
- package/src/autoscript/action-providers/xhs/interaction.mjs +466 -0
- package/src/autoscript/action-providers/xhs/like-rules.mjs +57 -0
- package/src/autoscript/action-providers/xhs/persistence.mjs +167 -0
- package/src/autoscript/action-providers/xhs/search.mjs +174 -0
- package/src/autoscript/action-providers/xhs.mjs +133 -0
- package/src/autoscript/impact-engine.mjs +78 -0
- package/src/autoscript/runtime.mjs +1015 -0
- package/src/autoscript/schema.mjs +370 -0
- package/src/autoscript/xhs-unified-template.mjs +931 -0
- package/src/cli.mjs +190 -78
- package/src/commands/autoscript.mjs +1100 -0
- package/src/commands/browser.mjs +20 -4
- package/src/commands/container.mjs +401 -0
- package/src/commands/events.mjs +152 -0
- package/src/commands/lifecycle.mjs +17 -3
- package/src/commands/window.mjs +32 -1
- package/src/container/change-notifier.mjs +311 -0
- package/src/container/element-filter.mjs +143 -0
- package/src/container/index.mjs +3 -0
- package/src/container/runtime-core/checkpoint.mjs +195 -0
- package/src/container/runtime-core/index.mjs +21 -0
- package/src/container/runtime-core/operations/index.mjs +351 -0
- package/src/container/runtime-core/operations/selector-scripts.mjs +68 -0
- package/src/container/runtime-core/operations/tab-pool.mjs +544 -0
- package/src/container/runtime-core/operations/viewport.mjs +143 -0
- package/src/container/runtime-core/subscription.mjs +87 -0
- package/src/container/runtime-core/utils.mjs +94 -0
- package/src/container/runtime-core/validation.mjs +127 -0
- package/src/container/runtime-core.mjs +1 -0
- package/src/container/subscription-registry.mjs +459 -0
- package/src/core/actions.mjs +573 -0
- package/src/core/browser.mjs +270 -0
- package/src/core/index.mjs +53 -0
- package/src/core/utils.mjs +87 -0
- package/src/events/daemon-entry.mjs +33 -0
- package/src/events/daemon.mjs +80 -0
- package/src/events/progress-log.mjs +109 -0
- package/src/events/ws-server.mjs +239 -0
- package/src/lib/client.mjs +200 -0
- package/src/lifecycle/session-registry.mjs +8 -4
- package/src/lifecycle/session-watchdog.mjs +220 -0
- package/src/utils/browser-service.mjs +232 -9
- package/src/utils/help.mjs +28 -0
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
function toTrimmedString(value, fallback = '') {
|
|
2
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
3
|
+
return text || fallback;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function toBoolean(value, fallback) {
|
|
7
|
+
if (value === undefined || value === null || value === '') return fallback;
|
|
8
|
+
if (typeof value === 'boolean') return value;
|
|
9
|
+
const text = String(value).trim().toLowerCase();
|
|
10
|
+
if (['1', 'true', 'yes', 'on'].includes(text)) return true;
|
|
11
|
+
if (['0', 'false', 'no', 'off'].includes(text)) return false;
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function toPositiveInt(value, fallback, min = 1) {
|
|
16
|
+
if (value === null || value === undefined || value === '') return fallback;
|
|
17
|
+
const num = Number(value);
|
|
18
|
+
if (!Number.isFinite(num)) return fallback;
|
|
19
|
+
return Math.max(min, Math.floor(num));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function splitCsv(value) {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return value
|
|
25
|
+
.map((item) => toTrimmedString(item))
|
|
26
|
+
.filter(Boolean);
|
|
27
|
+
}
|
|
28
|
+
return String(value || '')
|
|
29
|
+
.split(',')
|
|
30
|
+
.map((item) => item.trim())
|
|
31
|
+
.filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function pickCloseDependency(options) {
|
|
35
|
+
if (options.doReply || options.doLikes) return 'comment_match_gate';
|
|
36
|
+
if (options.matchGateEnabled) return 'comment_match_gate';
|
|
37
|
+
if (options.commentsHarvestEnabled) return 'comments_harvest';
|
|
38
|
+
if (options.detailHarvestEnabled) return 'detail_harvest';
|
|
39
|
+
return 'open_first_detail';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function buildOpenFirstDetailScript(maxNotes, keyword) {
|
|
43
|
+
return `(async () => {
|
|
44
|
+
const STATE_KEY = '__camoXhsState';
|
|
45
|
+
const loadState = () => {
|
|
46
|
+
const inMemory = window.__camoXhsState && typeof window.__camoXhsState === 'object'
|
|
47
|
+
? window.__camoXhsState
|
|
48
|
+
: {};
|
|
49
|
+
try {
|
|
50
|
+
const stored = localStorage.getItem(STATE_KEY);
|
|
51
|
+
if (!stored) return { ...inMemory };
|
|
52
|
+
const parsed = JSON.parse(stored);
|
|
53
|
+
if (!parsed || typeof parsed !== 'object') return { ...inMemory };
|
|
54
|
+
return { ...parsed, ...inMemory };
|
|
55
|
+
} catch {
|
|
56
|
+
return { ...inMemory };
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const saveState = (nextState) => {
|
|
60
|
+
window.__camoXhsState = nextState;
|
|
61
|
+
try {
|
|
62
|
+
localStorage.setItem(STATE_KEY, JSON.stringify(nextState));
|
|
63
|
+
} catch {}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const state = loadState();
|
|
67
|
+
if (!Array.isArray(state.visitedNoteIds)) state.visitedNoteIds = [];
|
|
68
|
+
state.maxNotes = Number(${maxNotes});
|
|
69
|
+
state.keyword = ${JSON.stringify(keyword)};
|
|
70
|
+
|
|
71
|
+
const nodes = Array.from(document.querySelectorAll('.note-item'))
|
|
72
|
+
.map((item, index) => {
|
|
73
|
+
const cover = item.querySelector('a.cover');
|
|
74
|
+
if (!cover) return null;
|
|
75
|
+
const href = String(cover.getAttribute('href') || '').trim();
|
|
76
|
+
const noteId = href.split('/').filter(Boolean).pop() || ('idx_' + index);
|
|
77
|
+
return { item, cover, href, noteId };
|
|
78
|
+
})
|
|
79
|
+
.filter(Boolean);
|
|
80
|
+
|
|
81
|
+
if (nodes.length === 0) {
|
|
82
|
+
throw new Error('NO_SEARCH_RESULT_ITEM');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const next = nodes.find((row) => !state.visitedNoteIds.includes(row.noteId)) || nodes[0];
|
|
86
|
+
next.cover.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
87
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
88
|
+
next.cover.click();
|
|
89
|
+
if (!state.visitedNoteIds.includes(next.noteId)) state.visitedNoteIds.push(next.noteId);
|
|
90
|
+
state.currentNoteId = next.noteId;
|
|
91
|
+
state.currentHref = next.href;
|
|
92
|
+
saveState(state);
|
|
93
|
+
return {
|
|
94
|
+
opened: true,
|
|
95
|
+
source: 'open_first_detail',
|
|
96
|
+
noteId: next.noteId,
|
|
97
|
+
visited: state.visitedNoteIds.length,
|
|
98
|
+
maxNotes: state.maxNotes,
|
|
99
|
+
};
|
|
100
|
+
})()`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function buildOpenNextDetailScript(maxNotes) {
|
|
104
|
+
return `(async () => {
|
|
105
|
+
const STATE_KEY = '__camoXhsState';
|
|
106
|
+
const loadState = () => {
|
|
107
|
+
const inMemory = window.__camoXhsState && typeof window.__camoXhsState === 'object'
|
|
108
|
+
? window.__camoXhsState
|
|
109
|
+
: {};
|
|
110
|
+
try {
|
|
111
|
+
const stored = localStorage.getItem(STATE_KEY);
|
|
112
|
+
if (!stored) return { ...inMemory };
|
|
113
|
+
const parsed = JSON.parse(stored);
|
|
114
|
+
if (!parsed || typeof parsed !== 'object') return { ...inMemory };
|
|
115
|
+
return { ...parsed, ...inMemory };
|
|
116
|
+
} catch {
|
|
117
|
+
return { ...inMemory };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const saveState = (nextState) => {
|
|
121
|
+
window.__camoXhsState = nextState;
|
|
122
|
+
try {
|
|
123
|
+
localStorage.setItem(STATE_KEY, JSON.stringify(nextState));
|
|
124
|
+
} catch {}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const state = loadState();
|
|
128
|
+
if (!Array.isArray(state.visitedNoteIds)) state.visitedNoteIds = [];
|
|
129
|
+
state.maxNotes = Number(${maxNotes});
|
|
130
|
+
|
|
131
|
+
if (state.visitedNoteIds.length >= state.maxNotes) {
|
|
132
|
+
throw new Error('AUTOSCRIPT_DONE_MAX_NOTES');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const nodes = Array.from(document.querySelectorAll('.note-item'))
|
|
136
|
+
.map((item, index) => {
|
|
137
|
+
const cover = item.querySelector('a.cover');
|
|
138
|
+
if (!cover) return null;
|
|
139
|
+
const href = String(cover.getAttribute('href') || '').trim();
|
|
140
|
+
const noteId = href.split('/').filter(Boolean).pop() || ('idx_' + index);
|
|
141
|
+
return { item, cover, href, noteId };
|
|
142
|
+
})
|
|
143
|
+
.filter(Boolean);
|
|
144
|
+
|
|
145
|
+
const next = nodes.find((row) => !state.visitedNoteIds.includes(row.noteId));
|
|
146
|
+
if (!next) {
|
|
147
|
+
throw new Error('AUTOSCRIPT_DONE_NO_MORE_NOTES');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
next.cover.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
151
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
152
|
+
next.cover.click();
|
|
153
|
+
state.visitedNoteIds.push(next.noteId);
|
|
154
|
+
state.currentNoteId = next.noteId;
|
|
155
|
+
state.currentHref = next.href;
|
|
156
|
+
saveState(state);
|
|
157
|
+
return {
|
|
158
|
+
opened: true,
|
|
159
|
+
source: 'open_next_detail',
|
|
160
|
+
noteId: next.noteId,
|
|
161
|
+
visited: state.visitedNoteIds.length,
|
|
162
|
+
maxNotes: state.maxNotes,
|
|
163
|
+
};
|
|
164
|
+
})()`;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function buildSubmitSearchScript(keyword) {
|
|
168
|
+
return `(async () => {
|
|
169
|
+
const input = document.querySelector('#search-input, input.search-input');
|
|
170
|
+
if (!(input instanceof HTMLInputElement)) {
|
|
171
|
+
throw new Error('SEARCH_INPUT_NOT_FOUND');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const targetKeyword = ${JSON.stringify(keyword)};
|
|
175
|
+
if (targetKeyword && input.value !== targetKeyword) {
|
|
176
|
+
input.focus();
|
|
177
|
+
input.value = targetKeyword;
|
|
178
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
179
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const enterEvent = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true, cancelable: true };
|
|
183
|
+
const beforeUrl = window.location.href;
|
|
184
|
+
input.focus();
|
|
185
|
+
input.dispatchEvent(new KeyboardEvent('keydown', enterEvent));
|
|
186
|
+
input.dispatchEvent(new KeyboardEvent('keypress', enterEvent));
|
|
187
|
+
input.dispatchEvent(new KeyboardEvent('keyup', enterEvent));
|
|
188
|
+
|
|
189
|
+
const candidates = [
|
|
190
|
+
'.input-button .search-icon',
|
|
191
|
+
'.input-button',
|
|
192
|
+
'button.min-width-search-icon',
|
|
193
|
+
];
|
|
194
|
+
let clickedSelector = null;
|
|
195
|
+
for (const selector of candidates) {
|
|
196
|
+
const button = document.querySelector(selector);
|
|
197
|
+
if (!button) continue;
|
|
198
|
+
if (button instanceof HTMLElement) {
|
|
199
|
+
button.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
200
|
+
}
|
|
201
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
202
|
+
button.click();
|
|
203
|
+
clickedSelector = selector;
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const form = input.closest('form');
|
|
208
|
+
if (form) {
|
|
209
|
+
if (typeof form.requestSubmit === 'function') form.requestSubmit();
|
|
210
|
+
else form.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await new Promise((resolve) => setTimeout(resolve, 320));
|
|
214
|
+
return {
|
|
215
|
+
submitted: true,
|
|
216
|
+
via: clickedSelector || 'enter_or_form_submit',
|
|
217
|
+
beforeUrl,
|
|
218
|
+
afterUrl: window.location.href,
|
|
219
|
+
};
|
|
220
|
+
})()`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function buildDetailHarvestScript() {
|
|
224
|
+
return `(async () => {
|
|
225
|
+
const state = window.__camoXhsState || (window.__camoXhsState = {});
|
|
226
|
+
const scroller = document.querySelector('.note-scroller')
|
|
227
|
+
|| document.querySelector('.comments-el')
|
|
228
|
+
|| document.scrollingElement
|
|
229
|
+
|| document.documentElement;
|
|
230
|
+
for (let i = 0; i < 3; i += 1) {
|
|
231
|
+
scroller.scrollBy({ top: 360, behavior: 'auto' });
|
|
232
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
233
|
+
}
|
|
234
|
+
const title = (document.querySelector('.note-title') || {}).textContent || '';
|
|
235
|
+
const content = (document.querySelector('.note-content') || {}).textContent || '';
|
|
236
|
+
state.lastDetail = {
|
|
237
|
+
title: String(title).trim().slice(0, 200),
|
|
238
|
+
contentLength: String(content).trim().length,
|
|
239
|
+
capturedAt: new Date().toISOString(),
|
|
240
|
+
};
|
|
241
|
+
return { harvested: true, detail: state.lastDetail };
|
|
242
|
+
})()`;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function buildExpandRepliesScript() {
|
|
246
|
+
return `(async () => {
|
|
247
|
+
const buttons = Array.from(document.querySelectorAll('.show-more, .reply-expand, [class*="expand"]'));
|
|
248
|
+
let clicked = 0;
|
|
249
|
+
for (const button of buttons.slice(0, 8)) {
|
|
250
|
+
if (!(button instanceof HTMLElement)) continue;
|
|
251
|
+
const text = (button.textContent || '').trim();
|
|
252
|
+
if (!text) continue;
|
|
253
|
+
button.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
254
|
+
await new Promise((resolve) => setTimeout(resolve, 60));
|
|
255
|
+
button.click();
|
|
256
|
+
clicked += 1;
|
|
257
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
258
|
+
}
|
|
259
|
+
return { expanded: clicked, scanned: buttons.length };
|
|
260
|
+
})()`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function buildCommentsHarvestScript() {
|
|
264
|
+
return `(async () => {
|
|
265
|
+
const state = window.__camoXhsState || (window.__camoXhsState = {});
|
|
266
|
+
const comments = Array.from(document.querySelectorAll('.comment-item'))
|
|
267
|
+
.map((item, index) => {
|
|
268
|
+
const textNode = item.querySelector('.content, .comment-content, p');
|
|
269
|
+
const likeNode = item.querySelector('.like-wrapper');
|
|
270
|
+
return {
|
|
271
|
+
index,
|
|
272
|
+
text: String((textNode && textNode.textContent) || '').trim(),
|
|
273
|
+
liked: Boolean(likeNode && /like-active/.test(String(likeNode.className || ''))),
|
|
274
|
+
};
|
|
275
|
+
})
|
|
276
|
+
.filter((row) => row.text);
|
|
277
|
+
|
|
278
|
+
state.currentComments = comments;
|
|
279
|
+
state.commentsCollectedAt = new Date().toISOString();
|
|
280
|
+
return {
|
|
281
|
+
collected: comments.length,
|
|
282
|
+
firstComment: comments[0] || null,
|
|
283
|
+
};
|
|
284
|
+
})()`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function buildCommentMatchScript(matchKeywords, matchMode, matchMinHits) {
|
|
288
|
+
return `(async () => {
|
|
289
|
+
const state = window.__camoXhsState || (window.__camoXhsState = {});
|
|
290
|
+
const rows = Array.isArray(state.currentComments) ? state.currentComments : [];
|
|
291
|
+
const keywords = ${JSON.stringify(matchKeywords)};
|
|
292
|
+
const mode = ${JSON.stringify(matchMode)};
|
|
293
|
+
const minHits = Number(${matchMinHits});
|
|
294
|
+
|
|
295
|
+
const normalize = (value) => String(value || '').toLowerCase().replace(/\\s+/g, ' ').trim();
|
|
296
|
+
const tokens = keywords.map((item) => normalize(item)).filter(Boolean);
|
|
297
|
+
const matches = [];
|
|
298
|
+
for (const row of rows) {
|
|
299
|
+
const text = normalize(row.text);
|
|
300
|
+
if (!text || tokens.length === 0) continue;
|
|
301
|
+
const hits = tokens.filter((token) => text.includes(token));
|
|
302
|
+
if (mode === 'all' && hits.length < tokens.length) continue;
|
|
303
|
+
if (mode === 'atLeast' && hits.length < Math.max(1, minHits)) continue;
|
|
304
|
+
if (mode !== 'all' && mode !== 'atLeast' && hits.length === 0) continue;
|
|
305
|
+
matches.push({ index: row.index, hits });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
state.matchedComments = matches;
|
|
309
|
+
state.matchRule = { tokens, mode, minHits };
|
|
310
|
+
return {
|
|
311
|
+
matchCount: matches.length,
|
|
312
|
+
mode,
|
|
313
|
+
minHits: Math.max(1, minHits),
|
|
314
|
+
};
|
|
315
|
+
})()`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function buildCommentLikeScript(likeKeywords, maxLikesPerRound) {
|
|
319
|
+
return `(async () => {
|
|
320
|
+
const state = window.__camoXhsState || (window.__camoXhsState = {});
|
|
321
|
+
const keywords = ${JSON.stringify(likeKeywords)};
|
|
322
|
+
const maxLikes = Number(${maxLikesPerRound});
|
|
323
|
+
const nodes = Array.from(document.querySelectorAll('.comment-item'));
|
|
324
|
+
const matches = Array.isArray(state.matchedComments) ? state.matchedComments : [];
|
|
325
|
+
const targetIndexes = new Set(matches.map((row) => Number(row.index)));
|
|
326
|
+
|
|
327
|
+
let likedCount = 0;
|
|
328
|
+
let skippedActive = 0;
|
|
329
|
+
for (let idx = 0; idx < nodes.length; idx += 1) {
|
|
330
|
+
if (likedCount >= maxLikes) break;
|
|
331
|
+
if (targetIndexes.size > 0 && !targetIndexes.has(idx)) continue;
|
|
332
|
+
const item = nodes[idx];
|
|
333
|
+
const text = String((item.querySelector('.content, .comment-content, p') || {}).textContent || '').trim();
|
|
334
|
+
if (!text) continue;
|
|
335
|
+
if (keywords.length > 0) {
|
|
336
|
+
const lower = text.toLowerCase();
|
|
337
|
+
const hit = keywords.some((token) => lower.includes(String(token).toLowerCase()));
|
|
338
|
+
if (!hit) continue;
|
|
339
|
+
}
|
|
340
|
+
const likeWrapper = item.querySelector('.like-wrapper');
|
|
341
|
+
if (!likeWrapper) continue;
|
|
342
|
+
if (/like-active/.test(String(likeWrapper.className || ''))) {
|
|
343
|
+
skippedActive += 1;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
likeWrapper.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
347
|
+
await new Promise((resolve) => setTimeout(resolve, 90));
|
|
348
|
+
likeWrapper.click();
|
|
349
|
+
likedCount += 1;
|
|
350
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
state.lastLike = { likedCount, skippedActive, at: new Date().toISOString() };
|
|
354
|
+
return state.lastLike;
|
|
355
|
+
})()`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function buildCommentReplyScript(replyText) {
|
|
359
|
+
return `(async () => {
|
|
360
|
+
const state = window.__camoXhsState || (window.__camoXhsState = {});
|
|
361
|
+
const replyText = ${JSON.stringify(replyText)};
|
|
362
|
+
const matches = Array.isArray(state.matchedComments) ? state.matchedComments : [];
|
|
363
|
+
if (matches.length === 0) {
|
|
364
|
+
return { typed: false, reason: 'no_match' };
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const index = Number(matches[0].index);
|
|
368
|
+
const nodes = Array.from(document.querySelectorAll('.comment-item'));
|
|
369
|
+
const target = nodes[index];
|
|
370
|
+
if (!target) {
|
|
371
|
+
return { typed: false, reason: 'match_not_visible', index };
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
target.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
375
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
376
|
+
target.click();
|
|
377
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
378
|
+
|
|
379
|
+
const input = document.querySelector('textarea, input[placeholder*="说点"], [contenteditable="true"]');
|
|
380
|
+
if (!input) {
|
|
381
|
+
return { typed: false, reason: 'reply_input_not_found', index };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (input instanceof HTMLTextAreaElement || input instanceof HTMLInputElement) {
|
|
385
|
+
input.focus();
|
|
386
|
+
input.value = replyText;
|
|
387
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
388
|
+
} else {
|
|
389
|
+
input.focus();
|
|
390
|
+
input.textContent = replyText;
|
|
391
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
395
|
+
const sendButton = Array.from(document.querySelectorAll('button'))
|
|
396
|
+
.find((button) => /发送|回复/.test(String(button.textContent || '').trim()));
|
|
397
|
+
if (sendButton) {
|
|
398
|
+
sendButton.click();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
state.lastReply = { typed: true, index, at: new Date().toISOString() };
|
|
402
|
+
return state.lastReply;
|
|
403
|
+
})()`;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function buildCloseDetailScript() {
|
|
407
|
+
return `(async () => {
|
|
408
|
+
const modalSelectors = [
|
|
409
|
+
'.note-detail-mask',
|
|
410
|
+
'.note-detail',
|
|
411
|
+
'.detail-container',
|
|
412
|
+
'.media-container',
|
|
413
|
+
];
|
|
414
|
+
const isModalVisible = () => modalSelectors.some((selector) => {
|
|
415
|
+
const node = document.querySelector(selector);
|
|
416
|
+
if (!node || !(node instanceof HTMLElement)) return false;
|
|
417
|
+
const style = window.getComputedStyle(node);
|
|
418
|
+
if (!style) return false;
|
|
419
|
+
if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity || '1') === 0) {
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
|
+
const rect = node.getBoundingClientRect();
|
|
423
|
+
return rect.width > 1 && rect.height > 1;
|
|
424
|
+
});
|
|
425
|
+
const waitForClosed = async () => {
|
|
426
|
+
for (let i = 0; i < 30; i += 1) {
|
|
427
|
+
if (!isModalVisible()) return true;
|
|
428
|
+
await new Promise((resolve) => setTimeout(resolve, 120));
|
|
429
|
+
}
|
|
430
|
+
return !isModalVisible();
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
const selectors = [
|
|
434
|
+
'.note-detail-mask .close-box',
|
|
435
|
+
'.note-detail-mask .close-circle',
|
|
436
|
+
'a[href*="/explore?channel_id=homefeed_recommend"]',
|
|
437
|
+
];
|
|
438
|
+
for (const selector of selectors) {
|
|
439
|
+
const target = document.querySelector(selector);
|
|
440
|
+
if (!target) continue;
|
|
441
|
+
target.scrollIntoView({ behavior: 'auto', block: 'center' });
|
|
442
|
+
await new Promise((resolve) => setTimeout(resolve, 80));
|
|
443
|
+
target.click();
|
|
444
|
+
return { closed: await waitForClosed(), via: selector };
|
|
445
|
+
}
|
|
446
|
+
if (window.history.length > 1) {
|
|
447
|
+
window.history.back();
|
|
448
|
+
return { closed: await waitForClosed(), via: 'history.back' };
|
|
449
|
+
}
|
|
450
|
+
return { closed: false, via: null, modalVisible: isModalVisible() };
|
|
451
|
+
})()`;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function buildAbortScript(code) {
|
|
455
|
+
return `(async () => {
|
|
456
|
+
throw new Error(${JSON.stringify(code)});
|
|
457
|
+
})()`;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function buildXhsUnifiedAutoscript(rawOptions = {}) {
|
|
461
|
+
const profileId = toTrimmedString(rawOptions.profileId, 'xiaohongshu-batch-1');
|
|
462
|
+
const keyword = toTrimmedString(rawOptions.keyword, '手机膜');
|
|
463
|
+
const env = toTrimmedString(rawOptions.env, 'debug');
|
|
464
|
+
const outputRoot = toTrimmedString(rawOptions.outputRoot, '');
|
|
465
|
+
const throttle = toPositiveInt(rawOptions.throttle, 900, 100);
|
|
466
|
+
const tabCount = toPositiveInt(rawOptions.tabCount, 4, 1);
|
|
467
|
+
const noteIntervalMs = toPositiveInt(rawOptions.noteIntervalMs, 1200, 200);
|
|
468
|
+
const maxNotes = toPositiveInt(rawOptions.maxNotes, 30, 1);
|
|
469
|
+
const maxLikesPerRound = toPositiveInt(rawOptions.maxLikesPerRound, 2, 1);
|
|
470
|
+
const matchMode = toTrimmedString(rawOptions.matchMode, 'any');
|
|
471
|
+
const matchMinHits = toPositiveInt(rawOptions.matchMinHits, 1, 1);
|
|
472
|
+
const replyText = toTrimmedString(rawOptions.replyText, '感谢分享,已关注');
|
|
473
|
+
|
|
474
|
+
const doHomepage = toBoolean(rawOptions.doHomepage, true);
|
|
475
|
+
const doImages = toBoolean(rawOptions.doImages, false);
|
|
476
|
+
const doComments = toBoolean(rawOptions.doComments, true);
|
|
477
|
+
const doLikes = toBoolean(rawOptions.doLikes, false);
|
|
478
|
+
const doReply = toBoolean(rawOptions.doReply, false);
|
|
479
|
+
const doOcr = toBoolean(rawOptions.doOcr, false);
|
|
480
|
+
const persistComments = toBoolean(rawOptions.persistComments, true);
|
|
481
|
+
|
|
482
|
+
const matchKeywords = splitCsv(rawOptions.matchKeywords || keyword);
|
|
483
|
+
const likeKeywordsSeed = splitCsv(rawOptions.likeKeywords || '');
|
|
484
|
+
const likeKeywords = likeKeywordsSeed.length > 0 ? likeKeywordsSeed : matchKeywords;
|
|
485
|
+
|
|
486
|
+
const detailHarvestEnabled = doHomepage || doImages || doComments || doLikes || doReply || doOcr;
|
|
487
|
+
const commentsHarvestEnabled = doComments || doLikes || doReply;
|
|
488
|
+
const matchGateEnabled = doLikes || doReply;
|
|
489
|
+
const closeDependsOn = pickCloseDependency({
|
|
490
|
+
doReply,
|
|
491
|
+
doLikes,
|
|
492
|
+
matchGateEnabled,
|
|
493
|
+
commentsHarvestEnabled,
|
|
494
|
+
detailHarvestEnabled,
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
const recovery = {
|
|
498
|
+
attempts: 0,
|
|
499
|
+
actions: [],
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
return {
|
|
503
|
+
version: 1,
|
|
504
|
+
name: 'xhs-unified-harvest-autoscript',
|
|
505
|
+
source: '/Users/fanzhang/Documents/github/webauto/scripts/xiaohongshu/phase-unified-harvest.mjs',
|
|
506
|
+
profileId,
|
|
507
|
+
throttle,
|
|
508
|
+
defaults: {
|
|
509
|
+
retry: { attempts: 2, backoffMs: 500 },
|
|
510
|
+
impact: 'subscription',
|
|
511
|
+
onFailure: 'chain_stop',
|
|
512
|
+
validationMode: 'none',
|
|
513
|
+
recovery,
|
|
514
|
+
pacing: {
|
|
515
|
+
operationMinIntervalMs: 700,
|
|
516
|
+
eventCooldownMs: 300,
|
|
517
|
+
jitterMs: 220,
|
|
518
|
+
navigationMinIntervalMs: 1800,
|
|
519
|
+
timeoutMs: 180000,
|
|
520
|
+
},
|
|
521
|
+
timeoutMs: 180000,
|
|
522
|
+
},
|
|
523
|
+
metadata: {
|
|
524
|
+
keyword,
|
|
525
|
+
env,
|
|
526
|
+
outputRoot,
|
|
527
|
+
tabCount,
|
|
528
|
+
noteIntervalMs,
|
|
529
|
+
maxNotes,
|
|
530
|
+
doHomepage,
|
|
531
|
+
doImages,
|
|
532
|
+
doComments,
|
|
533
|
+
doLikes,
|
|
534
|
+
doReply,
|
|
535
|
+
doOcr,
|
|
536
|
+
persistComments,
|
|
537
|
+
matchMode,
|
|
538
|
+
matchMinHits,
|
|
539
|
+
matchKeywords,
|
|
540
|
+
likeKeywords,
|
|
541
|
+
replyText,
|
|
542
|
+
notes: [
|
|
543
|
+
'open_next_detail intentionally stops script by throwing AUTOSCRIPT_DONE_* when exhausted.',
|
|
544
|
+
'dev mode uses deterministic no-recovery policy (checkpoint recovery disabled).',
|
|
545
|
+
'when persistComments=true, xhs_comments_harvest emits full comments in operation result for downstream jsonl/file persistence.',
|
|
546
|
+
],
|
|
547
|
+
},
|
|
548
|
+
subscriptions: [
|
|
549
|
+
{ id: 'home_search_input', selector: '#search-input, input.search-input', events: ['appear', 'exist', 'disappear'] },
|
|
550
|
+
{ id: 'home_search_button', selector: '.input-button, .input-button .search-icon', events: ['exist'] },
|
|
551
|
+
{ id: 'search_result_item', selector: '.note-item', events: ['appear', 'exist', 'change'] },
|
|
552
|
+
{ id: 'detail_modal', selector: '.note-detail-mask, .note-detail-page, .note-detail-dialog, .note-detail-mask .detail-container, .note-detail-mask .media-container, .note-detail-mask .note-scroller, .note-detail-mask .note-content, .note-detail-mask .interaction-container, .note-detail-mask .comments-container', events: ['appear', 'exist', 'disappear'] },
|
|
553
|
+
{ id: 'detail_comment_item', selector: '.comment-item, [class*="comment-item"]', events: ['appear', 'exist', 'change'] },
|
|
554
|
+
{ id: 'detail_show_more', selector: '.note-detail-mask .show-more, .note-detail-mask .reply-expand, .note-detail-mask [class*="expand"], .note-detail-page .show-more, .note-detail-page .reply-expand, .note-detail-page [class*="expand"]', events: ['appear', 'exist'] },
|
|
555
|
+
{ id: 'detail_discover_button', selector: 'a[href*="/explore?channel_id=homefeed_recommend"]', events: ['appear', 'exist'] },
|
|
556
|
+
{ id: 'login_guard', selector: '.login-container, .login-dialog, #login-container', events: ['appear', 'exist'] },
|
|
557
|
+
{ id: 'risk_guard', selector: '.qrcode-box, .captcha-container, [class*="captcha"]', events: ['appear', 'exist'] },
|
|
558
|
+
],
|
|
559
|
+
operations: [
|
|
560
|
+
{
|
|
561
|
+
id: 'sync_window_viewport',
|
|
562
|
+
action: 'sync_window_viewport',
|
|
563
|
+
params: { followWindow: true, settleMs: 220, attempts: 2 },
|
|
564
|
+
trigger: 'startup',
|
|
565
|
+
once: true,
|
|
566
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
567
|
+
impact: 'op',
|
|
568
|
+
onFailure: 'continue',
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
id: 'goto_home',
|
|
572
|
+
action: 'goto',
|
|
573
|
+
params: { url: 'https://www.xiaohongshu.com/explore' },
|
|
574
|
+
trigger: 'startup',
|
|
575
|
+
dependsOn: ['sync_window_viewport'],
|
|
576
|
+
once: true,
|
|
577
|
+
retry: { attempts: 2, backoffMs: 300 },
|
|
578
|
+
validation: {
|
|
579
|
+
mode: 'post',
|
|
580
|
+
post: {
|
|
581
|
+
page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['home_ready', 'search_ready'] },
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
checkpoint: {
|
|
585
|
+
containerId: 'xiaohongshu_home.discover_button',
|
|
586
|
+
targetCheckpoint: 'home_ready',
|
|
587
|
+
recovery,
|
|
588
|
+
},
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
id: 'fill_keyword',
|
|
592
|
+
action: 'type',
|
|
593
|
+
params: { selector: '#search-input', text: keyword },
|
|
594
|
+
trigger: 'home_search_input.exist',
|
|
595
|
+
dependsOn: ['goto_home'],
|
|
596
|
+
once: true,
|
|
597
|
+
validation: {
|
|
598
|
+
mode: 'both',
|
|
599
|
+
pre: { page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['home_ready', 'search_ready'] } },
|
|
600
|
+
post: { container: { selector: '#search-input', mustExist: true, minCount: 1 } },
|
|
601
|
+
},
|
|
602
|
+
checkpoint: {
|
|
603
|
+
containerId: 'xiaohongshu_home.search_input',
|
|
604
|
+
targetCheckpoint: 'search_ready',
|
|
605
|
+
recovery,
|
|
606
|
+
},
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
id: 'submit_search',
|
|
610
|
+
action: 'xhs_submit_search',
|
|
611
|
+
params: { keyword },
|
|
612
|
+
trigger: 'home_search_input.exist',
|
|
613
|
+
dependsOn: ['fill_keyword'],
|
|
614
|
+
once: true,
|
|
615
|
+
timeoutMs: 120000,
|
|
616
|
+
validation: {
|
|
617
|
+
mode: 'post',
|
|
618
|
+
post: { page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['search_ready', 'home_ready'] } },
|
|
619
|
+
},
|
|
620
|
+
checkpoint: {
|
|
621
|
+
containerId: 'xiaohongshu_home.search_button',
|
|
622
|
+
targetCheckpoint: 'search_ready',
|
|
623
|
+
recovery,
|
|
624
|
+
},
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
id: 'open_first_detail',
|
|
628
|
+
action: 'xhs_open_detail',
|
|
629
|
+
params: { mode: 'first', maxNotes, keyword },
|
|
630
|
+
trigger: 'search_result_item.exist',
|
|
631
|
+
dependsOn: ['submit_search'],
|
|
632
|
+
once: true,
|
|
633
|
+
timeoutMs: 90000,
|
|
634
|
+
validation: {
|
|
635
|
+
mode: 'post',
|
|
636
|
+
post: { page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['detail_ready', 'comments_ready', 'search_ready'] } },
|
|
637
|
+
},
|
|
638
|
+
checkpoint: {
|
|
639
|
+
containerId: 'xiaohongshu_search.search_result_item',
|
|
640
|
+
targetCheckpoint: 'detail_ready',
|
|
641
|
+
recovery,
|
|
642
|
+
},
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
id: 'detail_harvest',
|
|
646
|
+
enabled: detailHarvestEnabled,
|
|
647
|
+
action: 'xhs_detail_harvest',
|
|
648
|
+
params: {},
|
|
649
|
+
trigger: 'detail_modal.exist',
|
|
650
|
+
dependsOn: ['open_first_detail'],
|
|
651
|
+
once: false,
|
|
652
|
+
oncePerAppear: true,
|
|
653
|
+
timeoutMs: 90000,
|
|
654
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
655
|
+
impact: 'op',
|
|
656
|
+
onFailure: 'continue',
|
|
657
|
+
pacing: { operationMinIntervalMs: 2000, eventCooldownMs: 1200, jitterMs: 260 },
|
|
658
|
+
validation: {
|
|
659
|
+
mode: 'both',
|
|
660
|
+
pre: {
|
|
661
|
+
page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['detail_ready', 'comments_ready'] },
|
|
662
|
+
container: { selector: '.note-detail-mask, .note-detail-page, .note-detail-dialog', mustExist: true, minCount: 1 },
|
|
663
|
+
},
|
|
664
|
+
post: {
|
|
665
|
+
page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['detail_ready', 'comments_ready'] },
|
|
666
|
+
container: { selector: '.note-content, .note-scroller, .media-container', mustExist: true, minCount: 1 },
|
|
667
|
+
},
|
|
668
|
+
},
|
|
669
|
+
checkpoint: {
|
|
670
|
+
containerId: 'xiaohongshu_detail.modal_shell',
|
|
671
|
+
targetCheckpoint: 'detail_ready',
|
|
672
|
+
recovery,
|
|
673
|
+
},
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
id: 'expand_replies',
|
|
677
|
+
enabled: commentsHarvestEnabled,
|
|
678
|
+
action: 'xhs_expand_replies',
|
|
679
|
+
params: {},
|
|
680
|
+
trigger: 'detail_show_more.exist',
|
|
681
|
+
dependsOn: [detailHarvestEnabled ? 'detail_harvest' : 'open_first_detail'],
|
|
682
|
+
conditions: [{ type: 'subscription_exist', subscriptionId: 'detail_modal' }],
|
|
683
|
+
once: false,
|
|
684
|
+
oncePerAppear: true,
|
|
685
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
686
|
+
onFailure: 'continue',
|
|
687
|
+
impact: 'op',
|
|
688
|
+
pacing: { operationMinIntervalMs: 2500, eventCooldownMs: 1500, jitterMs: 220 },
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
id: 'comments_harvest',
|
|
692
|
+
enabled: commentsHarvestEnabled,
|
|
693
|
+
action: 'xhs_comments_harvest',
|
|
694
|
+
params: {
|
|
695
|
+
env,
|
|
696
|
+
keyword,
|
|
697
|
+
outputRoot,
|
|
698
|
+
persistComments,
|
|
699
|
+
maxRounds: 48,
|
|
700
|
+
scrollStep: 360,
|
|
701
|
+
settleMs: 260,
|
|
702
|
+
stallRounds: 8,
|
|
703
|
+
recoveryNoProgressRounds: 3,
|
|
704
|
+
recoveryStuckRounds: 2,
|
|
705
|
+
recoveryUpRounds: 2,
|
|
706
|
+
recoveryDownRounds: 3,
|
|
707
|
+
maxRecoveries: 3,
|
|
708
|
+
adaptiveMaxRounds: true,
|
|
709
|
+
adaptiveExpectedPerRound: 6,
|
|
710
|
+
adaptiveBufferRounds: 22,
|
|
711
|
+
adaptiveMinBoostRounds: 36,
|
|
712
|
+
adaptiveMaxRoundsCap: 320,
|
|
713
|
+
requireBottom: true,
|
|
714
|
+
includeComments: persistComments,
|
|
715
|
+
},
|
|
716
|
+
trigger: 'detail_modal.exist',
|
|
717
|
+
dependsOn: [detailHarvestEnabled ? 'detail_harvest' : 'open_first_detail'],
|
|
718
|
+
once: false,
|
|
719
|
+
oncePerAppear: true,
|
|
720
|
+
timeoutMs: 90000,
|
|
721
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
722
|
+
impact: 'op',
|
|
723
|
+
onFailure: 'continue',
|
|
724
|
+
pacing: { operationMinIntervalMs: 2400, eventCooldownMs: 1500, jitterMs: 280 },
|
|
725
|
+
validation: {
|
|
726
|
+
mode: 'both',
|
|
727
|
+
pre: {
|
|
728
|
+
page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['detail_ready', 'comments_ready'] },
|
|
729
|
+
container: { selector: '.note-detail-mask, .note-detail-page, .note-detail-dialog', mustExist: true, minCount: 1 },
|
|
730
|
+
},
|
|
731
|
+
post: {
|
|
732
|
+
page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['detail_ready', 'comments_ready'] },
|
|
733
|
+
container: { selector: '.comment-item, [class*="comment-item"]', mustExist: false, minCount: 0 },
|
|
734
|
+
},
|
|
735
|
+
},
|
|
736
|
+
checkpoint: {
|
|
737
|
+
containerId: 'xiaohongshu_detail.comment_section.comment_item',
|
|
738
|
+
targetCheckpoint: 'comments_ready',
|
|
739
|
+
recovery,
|
|
740
|
+
},
|
|
741
|
+
},
|
|
742
|
+
{
|
|
743
|
+
id: 'comment_match_gate',
|
|
744
|
+
enabled: matchGateEnabled,
|
|
745
|
+
action: 'xhs_comment_match',
|
|
746
|
+
params: { keywords: matchKeywords, mode: matchMode, minHits: matchMinHits },
|
|
747
|
+
trigger: 'detail_modal.exist',
|
|
748
|
+
dependsOn: [commentsHarvestEnabled ? 'comments_harvest' : (detailHarvestEnabled ? 'detail_harvest' : 'open_first_detail')],
|
|
749
|
+
once: false,
|
|
750
|
+
oncePerAppear: true,
|
|
751
|
+
pacing: { operationMinIntervalMs: 2400, eventCooldownMs: 1200, jitterMs: 160 },
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
id: 'comment_like',
|
|
755
|
+
enabled: doLikes,
|
|
756
|
+
action: 'xhs_comment_like',
|
|
757
|
+
params: {
|
|
758
|
+
env,
|
|
759
|
+
keyword,
|
|
760
|
+
outputRoot,
|
|
761
|
+
persistLikeState: true,
|
|
762
|
+
saveEvidence: true,
|
|
763
|
+
keywords: likeKeywords,
|
|
764
|
+
maxLikes: maxLikesPerRound,
|
|
765
|
+
},
|
|
766
|
+
trigger: 'detail_modal.exist',
|
|
767
|
+
dependsOn: ['comment_match_gate'],
|
|
768
|
+
once: false,
|
|
769
|
+
oncePerAppear: true,
|
|
770
|
+
timeoutMs: 90000,
|
|
771
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
772
|
+
onFailure: 'continue',
|
|
773
|
+
impact: 'op',
|
|
774
|
+
pacing: { operationMinIntervalMs: 2600, eventCooldownMs: 1500, jitterMs: 300 },
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
id: 'comment_reply',
|
|
778
|
+
enabled: doReply,
|
|
779
|
+
action: 'xhs_comment_reply',
|
|
780
|
+
params: { replyText },
|
|
781
|
+
trigger: 'detail_modal.exist',
|
|
782
|
+
dependsOn: ['comment_match_gate'],
|
|
783
|
+
once: false,
|
|
784
|
+
oncePerAppear: true,
|
|
785
|
+
timeoutMs: 90000,
|
|
786
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
787
|
+
onFailure: 'continue',
|
|
788
|
+
impact: 'op',
|
|
789
|
+
pacing: { operationMinIntervalMs: 2600, eventCooldownMs: 1500, jitterMs: 300 },
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
id: 'close_detail',
|
|
793
|
+
action: 'xhs_close_detail',
|
|
794
|
+
params: {},
|
|
795
|
+
trigger: 'detail_modal.exist',
|
|
796
|
+
dependsOn: [closeDependsOn],
|
|
797
|
+
once: false,
|
|
798
|
+
oncePerAppear: true,
|
|
799
|
+
pacing: { operationMinIntervalMs: 2500, eventCooldownMs: 1300, jitterMs: 180 },
|
|
800
|
+
validation: {
|
|
801
|
+
mode: 'post',
|
|
802
|
+
post: { page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['home_ready', 'search_ready'] } },
|
|
803
|
+
},
|
|
804
|
+
checkpoint: {
|
|
805
|
+
containerId: 'xiaohongshu_detail.discover_button',
|
|
806
|
+
targetCheckpoint: 'search_ready',
|
|
807
|
+
recovery,
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
id: 'wait_between_notes',
|
|
812
|
+
action: 'wait',
|
|
813
|
+
params: { ms: noteIntervalMs },
|
|
814
|
+
trigger: 'search_result_item.exist',
|
|
815
|
+
dependsOn: ['close_detail'],
|
|
816
|
+
once: false,
|
|
817
|
+
oncePerAppear: true,
|
|
818
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
819
|
+
impact: 'op',
|
|
820
|
+
onFailure: 'continue',
|
|
821
|
+
pacing: { operationMinIntervalMs: noteIntervalMs, eventCooldownMs: Math.max(400, Math.floor(noteIntervalMs / 2)), jitterMs: 160 },
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
id: 'switch_tab_round_robin',
|
|
825
|
+
action: 'tab_pool_switch_next',
|
|
826
|
+
params: { settleMs: 450 },
|
|
827
|
+
trigger: 'search_result_item.exist',
|
|
828
|
+
dependsOn: ['wait_between_notes', 'ensure_tab_pool'],
|
|
829
|
+
once: false,
|
|
830
|
+
oncePerAppear: true,
|
|
831
|
+
timeoutMs: 180000,
|
|
832
|
+
retry: { attempts: 2, backoffMs: 500 },
|
|
833
|
+
impact: 'op',
|
|
834
|
+
onFailure: 'continue',
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
id: 'open_next_detail',
|
|
838
|
+
action: 'xhs_open_detail',
|
|
839
|
+
params: { mode: 'next', maxNotes },
|
|
840
|
+
trigger: 'search_result_item.exist',
|
|
841
|
+
dependsOn: ['switch_tab_round_robin'],
|
|
842
|
+
once: false,
|
|
843
|
+
oncePerAppear: true,
|
|
844
|
+
timeoutMs: 90000,
|
|
845
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
846
|
+
impact: 'script',
|
|
847
|
+
onFailure: 'stop_all',
|
|
848
|
+
checkpoint: {
|
|
849
|
+
containerId: 'xiaohongshu_search.search_result_item',
|
|
850
|
+
targetCheckpoint: 'detail_ready',
|
|
851
|
+
recovery: { attempts: 0, actions: [] },
|
|
852
|
+
},
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
id: 'abort_on_login_guard',
|
|
856
|
+
action: 'raise_error',
|
|
857
|
+
params: { code: 'LOGIN_GUARD_DETECTED' },
|
|
858
|
+
trigger: 'login_guard.appear',
|
|
859
|
+
once: false,
|
|
860
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
861
|
+
impact: 'script',
|
|
862
|
+
onFailure: 'stop_all',
|
|
863
|
+
checkpoint: {
|
|
864
|
+
containerId: 'xiaohongshu_login.login_guard',
|
|
865
|
+
targetCheckpoint: 'login_guard',
|
|
866
|
+
recovery: { attempts: 0, actions: [] },
|
|
867
|
+
},
|
|
868
|
+
},
|
|
869
|
+
{
|
|
870
|
+
id: 'abort_on_risk_guard',
|
|
871
|
+
action: 'raise_error',
|
|
872
|
+
params: { code: 'RISK_CONTROL_DETECTED' },
|
|
873
|
+
trigger: 'risk_guard.appear',
|
|
874
|
+
once: false,
|
|
875
|
+
retry: { attempts: 1, backoffMs: 0 },
|
|
876
|
+
impact: 'script',
|
|
877
|
+
onFailure: 'stop_all',
|
|
878
|
+
checkpoint: {
|
|
879
|
+
containerId: 'xiaohongshu_login.qrcode_guard',
|
|
880
|
+
targetCheckpoint: 'risk_control',
|
|
881
|
+
recovery: { attempts: 0, actions: [] },
|
|
882
|
+
},
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
id: 'ensure_tab_pool',
|
|
886
|
+
action: 'ensure_tab_pool',
|
|
887
|
+
params: {
|
|
888
|
+
tabCount,
|
|
889
|
+
openDelayMs: 1200,
|
|
890
|
+
normalizeTabs: false,
|
|
891
|
+
},
|
|
892
|
+
trigger: 'search_result_item.exist',
|
|
893
|
+
dependsOn: ['wait_between_notes'],
|
|
894
|
+
once: true,
|
|
895
|
+
timeoutMs: 180000,
|
|
896
|
+
retry: { attempts: 2, backoffMs: 500 },
|
|
897
|
+
impact: 'script',
|
|
898
|
+
onFailure: 'stop_all',
|
|
899
|
+
validation: {
|
|
900
|
+
mode: 'post',
|
|
901
|
+
post: { page: { hostIncludes: ['xiaohongshu.com'], checkpointIn: ['search_ready', 'home_ready'] } },
|
|
902
|
+
},
|
|
903
|
+
checkpoint: {
|
|
904
|
+
targetCheckpoint: 'search_ready',
|
|
905
|
+
recovery: {
|
|
906
|
+
attempts: 0,
|
|
907
|
+
actions: [],
|
|
908
|
+
},
|
|
909
|
+
},
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
id: 'verify_subscriptions_all_pages',
|
|
913
|
+
action: 'verify_subscriptions',
|
|
914
|
+
params: {
|
|
915
|
+
acrossPages: true,
|
|
916
|
+
settleMs: 320,
|
|
917
|
+
selectors: [
|
|
918
|
+
{ id: 'home_search_input', selector: '#search-input, input.search-input' },
|
|
919
|
+
{ id: 'search_result_item', selector: '.note-item', visible: false, minCount: 1 },
|
|
920
|
+
],
|
|
921
|
+
},
|
|
922
|
+
trigger: 'search_result_item.exist',
|
|
923
|
+
dependsOn: ['ensure_tab_pool'],
|
|
924
|
+
once: true,
|
|
925
|
+
timeoutMs: 90000,
|
|
926
|
+
impact: 'script',
|
|
927
|
+
onFailure: 'stop_all',
|
|
928
|
+
},
|
|
929
|
+
],
|
|
930
|
+
};
|
|
931
|
+
}
|