Files
jackwener__opencli/clis/jike/like.js
jakevin d2974a9ff6 refactor(adapters): convert adapter layer from TypeScript to JavaScript (#928)
* 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.
2026-04-10 14:52:18 +08:00

61 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { cli, Strategy } from '@jackwener/opencli/registry';
/**
* 点赞即刻帖子
*
* 即刻帖子详情页的操作栏是 div 元素(非 button),
* 点赞按钮可通过 class 前缀 _likeButton_ 定位。
*/
cli({
site: 'jike',
name: 'like',
description: '点赞即刻帖子',
domain: 'web.okjike.com',
strategy: Strategy.UI,
browser: true,
args: [
{ name: 'id', type: 'string', required: true, positional: true, help: '帖子 ID' },
],
columns: ['status', 'message'],
func: async (page, kwargs) => {
// 1. 导航到帖子详情页
await page.goto(`https://web.okjike.com/originalPost/${kwargs.id}`);
// 2. 找到点赞按钮并点击
const result = await page.evaluate(`(async () => {
try {
// 点赞按钮:class 包含 _likeButton_,在 _actions_ 容器内
const likeBtn = document.querySelector('[class*="_likeButton_"]');
if (!likeBtn) {
return { ok: false, message: '未找到点赞按钮' };
}
// 检查是否已点赞(已赞按钮带有 _liked_ 类)
const cls = likeBtn.className || '';
if (cls.includes('_liked')) {
return { ok: true, message: '该帖子已赞过' };
}
// 记录点击前的类名
const beforeCls = likeBtn.className;
likeBtn.click();
await new Promise(r => setTimeout(r, 1500));
// 验证:类名变化表示点赞成功
const afterCls = likeBtn.className;
if (afterCls !== beforeCls) {
return { ok: true, message: '点赞成功' };
}
// 类名未变化,无法确认点赞是否成功
return { ok: false, message: '点赞状态未确认,请手动检查' };
} catch (e) {
return { ok: false, message: e.toString() };
}
})()`);
return [{
status: result.ok ? 'success' : 'failed',
message: result.message,
}];
},
});