mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
d2974a9ff6
* refactor(adapters): convert adapter layer from TypeScript to JavaScript Core framework stays TypeScript; adapter layer moves to JS-first. Adapters are essentially "executable config + browser scripts" that barely use TS features — this simplifies the build/distribution pipeline by removing the dist/clis/ intermediate compilation step. Changes: - Convert all 753 adapter files in clis/ from .ts to .js - Update tsconfig to exclude clis/ from compilation - Simplify build-manifest to scan clis/*.js directly (no dist/clis/) - Update discovery, main, fetch-adapters to load JS adapters from clis/ - Update generate-verified to output .js artifacts - Update package.json files field: dist/clis/ → clis/ - Fix all test files for the .ts → .js transition * fix(main): use findPackageRoot for BUILTIN_CLIS path The previous relative path (../../clis from __dirname) only worked for dist/src/main.js but broke dev mode (tsx src/main.ts) where __dirname is <repo>/src — resolving to /clis instead of <repo>/clis. Use findPackageRoot() which works for both dev and prod paths.
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
import { cli } from '@jackwener/opencli/registry';
|
|
cli({
|
|
site: 'facebook',
|
|
name: 'friends',
|
|
description: 'Get Facebook friend suggestions',
|
|
domain: 'www.facebook.com',
|
|
args: [
|
|
{ name: 'limit', type: 'int', default: 10, help: 'Number of friend suggestions' },
|
|
],
|
|
columns: ['index', 'name', 'mutual'],
|
|
pipeline: [
|
|
{ navigate: { url: 'https://www.facebook.com/friends', settleMs: 3000 } },
|
|
{ evaluate: `(() => {
|
|
const limit = \${{ args.limit }};
|
|
const items = document.querySelectorAll('[role="listitem"]');
|
|
return Array.from(items)
|
|
.slice(0, limit)
|
|
.map((el, i) => {
|
|
const text = el.textContent.trim().replace(/\\s+/g, ' ');
|
|
// Extract mutual info if present (before name extraction to avoid pollution)
|
|
const mutualMatch = text.match(/([\\d,]+)\\s*位.*(?:关注|共同|mutual)/);
|
|
// Extract name: remove mutual info, action buttons, etc.
|
|
let name = text
|
|
.replace(/[\\d,]+\\s*位.*(?:关注了|共同好友|mutual friends?)/, '')
|
|
.replace(/加好友.*/, '').replace(/Add [Ff]riend.*/, '')
|
|
.replace(/移除$/, '').replace(/Remove$/, '')
|
|
.trim();
|
|
return {
|
|
index: i + 1,
|
|
name: name.substring(0, 50),
|
|
mutual: mutualMatch ? mutualMatch[1] : '-',
|
|
};
|
|
})
|
|
.filter(item => item.name.length > 0);
|
|
})()
|
|
` },
|
|
],
|
|
});
|