@sovovs/bycli 2.1.52 → 2.1.53
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/clis/weixin/_wechat/user-info.js +79 -81
- package/package.json +1 -1
|
@@ -161,20 +161,73 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
|
|
|
161
161
|
}
|
|
162
162
|
return null;
|
|
163
163
|
};
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
164
|
+
const ignoredValueSelector = [
|
|
165
|
+
'a',
|
|
166
|
+
'button',
|
|
167
|
+
'[role="button"]',
|
|
168
|
+
'[role="tooltip"]',
|
|
169
|
+
'svg',
|
|
170
|
+
'.setting_opr',
|
|
171
|
+
'.weui-desktop-setting__status',
|
|
172
|
+
'.setting_status',
|
|
173
|
+
'.status',
|
|
174
|
+
'.frm_tips',
|
|
175
|
+
'.weui-desktop-form__tips',
|
|
176
|
+
'.weui-desktop-setting__desc',
|
|
177
|
+
'.setting_desc',
|
|
178
|
+
'.tips',
|
|
179
|
+
'.desc',
|
|
180
|
+
'.description',
|
|
181
|
+
'.help',
|
|
182
|
+
'.icon-question',
|
|
183
|
+
'[class*="question"]',
|
|
184
|
+
'[class*="help"]',
|
|
185
|
+
'[class*="popover"]',
|
|
186
|
+
'[class*="-ask"]',
|
|
187
|
+
].join(',');
|
|
188
|
+
const cleanValueText = node => {
|
|
189
|
+
if (!node) return null;
|
|
190
|
+
const copy = node.cloneNode(true);
|
|
191
|
+
copy.querySelectorAll(ignoredValueSelector).forEach(item => item.remove());
|
|
192
|
+
return compact(copy.textContent);
|
|
193
|
+
};
|
|
194
|
+
const primaryValueText = node => {
|
|
195
|
+
if (node && node.matches('.weui-desktop-setting__item__info')) {
|
|
196
|
+
const directText = compact(Array.from(node.childNodes)
|
|
197
|
+
.filter(child => child.nodeType === Node.TEXT_NODE)
|
|
198
|
+
.map(child => child.textContent)
|
|
199
|
+
.join(' '));
|
|
200
|
+
if (directText) return cleanValueText(node);
|
|
201
|
+
const primaryChild = Array.from(node.children)
|
|
202
|
+
.find(child => visible(child) && !child.matches(ignoredValueSelector));
|
|
203
|
+
if (primaryChild) return cleanValueText(primaryChild);
|
|
204
|
+
}
|
|
205
|
+
return cleanValueText(node);
|
|
206
|
+
};
|
|
207
|
+
const switchValue = row => {
|
|
208
|
+
const node = firstVisible(row, [
|
|
209
|
+
'input[type="checkbox"]',
|
|
210
|
+
'[role="switch"]',
|
|
211
|
+
'.weui-desktop-switch',
|
|
212
|
+
'.weui-switch',
|
|
213
|
+
'[class*="switch"]',
|
|
214
|
+
]);
|
|
215
|
+
if (!node) return null;
|
|
216
|
+
const input = node.matches('input[type="checkbox"]')
|
|
217
|
+
? node
|
|
218
|
+
: node.querySelector('input[type="checkbox"]');
|
|
219
|
+
if (input) return Boolean(input.checked);
|
|
220
|
+
const ariaNode = node.hasAttribute('aria-checked')
|
|
221
|
+
? node
|
|
222
|
+
: node.querySelector('[aria-checked]');
|
|
223
|
+
const ariaChecked = ariaNode && ariaNode.getAttribute('aria-checked');
|
|
224
|
+
if (ariaChecked === 'true') return true;
|
|
225
|
+
if (ariaChecked === 'false') return false;
|
|
226
|
+
const className = [node.className, node.parentElement && node.parentElement.className].join(' ');
|
|
227
|
+
if (/(^|[\\s_-])(checked|on|active)([\\s_-]|$)/i.test(className)) return true;
|
|
228
|
+
if (/(^|[\\s_-])(unchecked|off)([\\s_-]|$)/i.test(className)) return false;
|
|
229
|
+
return null;
|
|
230
|
+
};
|
|
178
231
|
const rowSelectors = [
|
|
179
232
|
'.setting_item',
|
|
180
233
|
'.weui-desktop-setting__item',
|
|
@@ -213,18 +266,13 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
|
|
|
213
266
|
let rows = Array.from(sectionNode.querySelectorAll(rowSelector)).filter(visible);
|
|
214
267
|
rows = rows.filter(node => !rows.some(other => other !== node && other.contains(node)));
|
|
215
268
|
const fields = [];
|
|
216
|
-
const actions = [];
|
|
217
269
|
const seenFields = new Set();
|
|
218
|
-
const seenActions = new Set();
|
|
219
270
|
const fieldRows = new Set();
|
|
220
271
|
const genericParts = node => Array.from(node.children).flatMap(child => {
|
|
221
272
|
if (!visible(child)
|
|
222
273
|
|| /^(H1|H2|H3|H4|H5|H6|A|BUTTON)$/.test(child.tagName)
|
|
223
274
|
|| child.getAttribute('role') === 'button') return [];
|
|
224
|
-
const
|
|
225
|
-
copy.querySelectorAll('a, button, [role="button"], svg, .setting_opr, .weui-desktop-setting__status, .setting_status, .status')
|
|
226
|
-
.forEach(item => item.remove());
|
|
227
|
-
const value = compact(copy.textContent);
|
|
275
|
+
const value = cleanValueText(child);
|
|
228
276
|
return value ? [value] : [];
|
|
229
277
|
});
|
|
230
278
|
|
|
@@ -235,56 +283,34 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
|
|
|
235
283
|
const labelNode = firstVisible(row, [
|
|
236
284
|
'.frm_label',
|
|
237
285
|
'.weui-desktop-setting__label',
|
|
286
|
+
'.weui-desktop-setting__item__label',
|
|
238
287
|
'.weui-desktop-form__label',
|
|
239
288
|
'dt',
|
|
240
289
|
'th',
|
|
241
290
|
]);
|
|
242
|
-
const fieldLabel =
|
|
243
|
-
const rowActions = actionNodes(row);
|
|
244
|
-
for (const node of rowActions) {
|
|
245
|
-
const item = action(node);
|
|
246
|
-
const key = JSON.stringify(item);
|
|
247
|
-
if (!seenActions.has(key)) {
|
|
248
|
-
seenActions.add(key);
|
|
249
|
-
actions.push(item);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
291
|
+
const fieldLabel = cleanValueText(labelNode);
|
|
252
292
|
if (!fieldLabel) continue;
|
|
253
293
|
const valueNode = firstVisible(row, [
|
|
254
294
|
'.weui-desktop-setting__value',
|
|
295
|
+
'.weui-desktop-setting__item__info',
|
|
255
296
|
'.setting_value',
|
|
256
297
|
'.frm_value',
|
|
257
298
|
'dd',
|
|
258
299
|
'td',
|
|
259
300
|
'.frm_controls',
|
|
260
301
|
]);
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
'.setting_status',
|
|
264
|
-
'.status',
|
|
265
|
-
]);
|
|
266
|
-
let fieldValue = null;
|
|
267
|
-
let fieldStatus = compact(statusNode && statusNode.textContent);
|
|
268
|
-
if (valueNode) {
|
|
269
|
-
const copy = valueNode.cloneNode(true);
|
|
270
|
-
copy.querySelectorAll('a, button, [role="button"], .setting_opr, .weui-desktop-setting__status, .setting_status, .status')
|
|
271
|
-
.forEach(node => node.remove());
|
|
272
|
-
fieldValue = compact(copy.textContent);
|
|
273
|
-
}
|
|
302
|
+
let fieldValue = switchValue(row);
|
|
303
|
+
if (fieldValue === null) fieldValue = primaryValueText(valueNode);
|
|
274
304
|
if (fieldValue === null) {
|
|
275
305
|
const parts = genericParts(row);
|
|
276
306
|
const labelIndex = parts.indexOf(fieldLabel);
|
|
277
307
|
if (labelIndex !== -1) {
|
|
278
308
|
fieldValue = parts[labelIndex + 1] || null;
|
|
279
|
-
if (fieldStatus === null && parts.length > labelIndex + 2) {
|
|
280
|
-
fieldStatus = parts.slice(labelIndex + 2).join(' ');
|
|
281
|
-
}
|
|
282
309
|
}
|
|
283
310
|
}
|
|
284
311
|
const item = {
|
|
285
312
|
label: fieldLabel,
|
|
286
313
|
value: fieldValue,
|
|
287
|
-
status: fieldStatus,
|
|
288
314
|
};
|
|
289
315
|
const key = JSON.stringify(item);
|
|
290
316
|
if (!seenFields.has(key)) {
|
|
@@ -305,7 +331,6 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
|
|
|
305
331
|
const item = {
|
|
306
332
|
label: parts[0],
|
|
307
333
|
value: parts[1] || null,
|
|
308
|
-
status: parts.length > 2 ? parts.slice(2).join(' ') : null,
|
|
309
334
|
};
|
|
310
335
|
const key = JSON.stringify(item);
|
|
311
336
|
if (!seenFields.has(key)) {
|
|
@@ -314,19 +339,9 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
|
|
|
314
339
|
}
|
|
315
340
|
}
|
|
316
341
|
|
|
317
|
-
|
|
318
|
-
for (const node of actionNodes(sectionNode)) {
|
|
319
|
-
if (rows.some(row => rowSet.has(row) && row.contains(node))) continue;
|
|
320
|
-
const item = action(node);
|
|
321
|
-
const key = JSON.stringify(item);
|
|
322
|
-
if (!seenActions.has(key)) {
|
|
323
|
-
seenActions.add(key);
|
|
324
|
-
actions.push(item);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (fields.length > 0 || actions.length > 0) return [{ label, fields, actions }];
|
|
342
|
+
if (fields.length > 0) return [{ label, fields }];
|
|
328
343
|
const empty = Boolean(sectionNode.querySelector('table thead th, table tr > th'));
|
|
329
|
-
return empty ? [{ label, fields,
|
|
344
|
+
return empty ? [{ label, fields, empty: true }] : [];
|
|
330
345
|
});
|
|
331
346
|
|
|
332
347
|
if (sections.length === 0 && /(无权限|暂无权限|暂不支持|不可用)/.test(document.body.textContent || '')) {
|
|
@@ -342,20 +357,7 @@ function normalizeField(field, tabLabel, sectionIndex, fieldIndex) {
|
|
|
342
357
|
execution(label, prefix);
|
|
343
358
|
return {
|
|
344
359
|
label,
|
|
345
|
-
value: text(field.value),
|
|
346
|
-
status: text(field.status),
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function normalizeAction(action, tabLabel, sectionIndex, actionIndex) {
|
|
351
|
-
const prefix = `WeChat ${tabLabel} returned an invalid action at section ${sectionIndex} index ${actionIndex}`;
|
|
352
|
-
execution(object(action), prefix);
|
|
353
|
-
const label = text(action.label);
|
|
354
|
-
execution(label, prefix);
|
|
355
|
-
return {
|
|
356
|
-
label,
|
|
357
|
-
enabled: action.enabled !== false,
|
|
358
|
-
path: sanitizeActionPath(action.href ?? action.path),
|
|
360
|
+
value: typeof field.value === 'boolean' ? field.value : text(field.value),
|
|
359
361
|
};
|
|
360
362
|
}
|
|
361
363
|
|
|
@@ -375,16 +377,12 @@ export function normalizeUserInfoTab(tabId, payload) {
|
|
|
375
377
|
const label = text(section.label);
|
|
376
378
|
execution(label, prefix);
|
|
377
379
|
const rawFields = section.fields ?? [];
|
|
378
|
-
|
|
379
|
-
execution(Array.isArray(rawFields) && Array.isArray(rawActions), prefix);
|
|
380
|
+
execution(Array.isArray(rawFields), prefix);
|
|
380
381
|
const fields = rawFields.map((field, fieldIndex) => (
|
|
381
382
|
normalizeField(field, definition.label, sectionIndex, fieldIndex)
|
|
382
383
|
));
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
));
|
|
386
|
-
return fields.length > 0 || actions.length > 0 || section.empty === true
|
|
387
|
-
? [{ label, fields, actions }]
|
|
384
|
+
return fields.length > 0 || section.empty === true
|
|
385
|
+
? [{ label, fields }]
|
|
388
386
|
: [];
|
|
389
387
|
});
|
|
390
388
|
|