@jackwener/opencli 1.4.0 → 1.4.1

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.
Files changed (209) hide show
  1. package/.github/actions/setup-chrome/action.yml +5 -4
  2. package/.github/workflows/ci.yml +17 -3
  3. package/.github/workflows/e2e-headed.yml +16 -3
  4. package/CHANGELOG.md +23 -0
  5. package/PRIVACY.md +57 -0
  6. package/README.md +1 -1
  7. package/README.zh-CN.md +1 -1
  8. package/SKILL.md +101 -2
  9. package/dist/cli-manifest.json +720 -32
  10. package/dist/clis/apple-podcasts/search.js +2 -1
  11. package/dist/clis/arxiv/search.js +2 -2
  12. package/dist/clis/bbc/news.js +0 -1
  13. package/dist/clis/ctrip/search.js +0 -1
  14. package/dist/clis/douyin/_shared/browser-fetch.d.ts +10 -0
  15. package/dist/clis/douyin/_shared/browser-fetch.js +30 -0
  16. package/dist/clis/douyin/_shared/browser-fetch.test.d.ts +1 -0
  17. package/dist/clis/douyin/_shared/browser-fetch.test.js +31 -0
  18. package/dist/clis/douyin/_shared/creation-id.d.ts +1 -0
  19. package/dist/clis/douyin/_shared/creation-id.js +5 -0
  20. package/dist/clis/douyin/_shared/creation-id.test.d.ts +1 -0
  21. package/dist/clis/douyin/_shared/creation-id.test.js +22 -0
  22. package/dist/clis/douyin/_shared/imagex-upload.d.ts +20 -0
  23. package/dist/clis/douyin/_shared/imagex-upload.js +53 -0
  24. package/dist/clis/douyin/_shared/imagex-upload.test.d.ts +1 -0
  25. package/dist/clis/douyin/_shared/imagex-upload.test.js +87 -0
  26. package/dist/clis/douyin/_shared/sts2.d.ts +8 -0
  27. package/dist/clis/douyin/_shared/sts2.js +15 -0
  28. package/dist/clis/douyin/_shared/text-extra.d.ts +18 -0
  29. package/dist/clis/douyin/_shared/text-extra.js +15 -0
  30. package/dist/clis/douyin/_shared/text-extra.test.d.ts +1 -0
  31. package/dist/clis/douyin/_shared/text-extra.test.js +37 -0
  32. package/dist/clis/douyin/_shared/timing.d.ts +2 -0
  33. package/dist/clis/douyin/_shared/timing.js +22 -0
  34. package/dist/clis/douyin/_shared/timing.test.d.ts +1 -0
  35. package/dist/clis/douyin/_shared/timing.test.js +28 -0
  36. package/dist/clis/douyin/_shared/tos-upload-short-read.test.d.ts +11 -0
  37. package/dist/clis/douyin/_shared/tos-upload-short-read.test.js +83 -0
  38. package/dist/clis/douyin/_shared/tos-upload.d.ts +53 -0
  39. package/dist/clis/douyin/_shared/tos-upload.js +295 -0
  40. package/dist/clis/douyin/_shared/tos-upload.test.d.ts +1 -0
  41. package/dist/clis/douyin/_shared/tos-upload.test.js +229 -0
  42. package/dist/clis/douyin/_shared/transcode.d.ts +27 -0
  43. package/dist/clis/douyin/_shared/transcode.js +45 -0
  44. package/dist/clis/douyin/_shared/transcode.test.d.ts +1 -0
  45. package/dist/clis/douyin/_shared/transcode.test.js +93 -0
  46. package/dist/clis/douyin/_shared/types.d.ts +26 -0
  47. package/dist/clis/douyin/_shared/types.js +1 -0
  48. package/dist/clis/douyin/activities.d.ts +1 -0
  49. package/dist/clis/douyin/activities.js +20 -0
  50. package/dist/clis/douyin/activities.test.d.ts +1 -0
  51. package/dist/clis/douyin/activities.test.js +22 -0
  52. package/dist/clis/douyin/collections.d.ts +1 -0
  53. package/dist/clis/douyin/collections.js +22 -0
  54. package/dist/clis/douyin/collections.test.d.ts +1 -0
  55. package/dist/clis/douyin/collections.test.js +23 -0
  56. package/dist/clis/douyin/delete.d.ts +1 -0
  57. package/dist/clis/douyin/delete.js +18 -0
  58. package/dist/clis/douyin/delete.test.d.ts +1 -0
  59. package/dist/clis/douyin/delete.test.js +11 -0
  60. package/dist/clis/douyin/draft.d.ts +14 -0
  61. package/dist/clis/douyin/draft.js +237 -0
  62. package/dist/clis/douyin/draft.test.d.ts +1 -0
  63. package/dist/clis/douyin/draft.test.js +11 -0
  64. package/dist/clis/douyin/drafts.d.ts +1 -0
  65. package/dist/clis/douyin/drafts.js +23 -0
  66. package/dist/clis/douyin/drafts.test.d.ts +1 -0
  67. package/dist/clis/douyin/drafts.test.js +11 -0
  68. package/dist/clis/douyin/hashtag.d.ts +1 -0
  69. package/dist/clis/douyin/hashtag.js +45 -0
  70. package/dist/clis/douyin/hashtag.test.d.ts +1 -0
  71. package/dist/clis/douyin/hashtag.test.js +25 -0
  72. package/dist/clis/douyin/location.d.ts +1 -0
  73. package/dist/clis/douyin/location.js +24 -0
  74. package/dist/clis/douyin/location.test.d.ts +1 -0
  75. package/dist/clis/douyin/location.test.js +23 -0
  76. package/dist/clis/douyin/profile.d.ts +1 -0
  77. package/dist/clis/douyin/profile.js +28 -0
  78. package/dist/clis/douyin/profile.test.d.ts +1 -0
  79. package/dist/clis/douyin/profile.test.js +11 -0
  80. package/dist/clis/douyin/publish.d.ts +14 -0
  81. package/dist/clis/douyin/publish.js +288 -0
  82. package/dist/clis/douyin/publish.test.d.ts +1 -0
  83. package/dist/clis/douyin/publish.test.js +38 -0
  84. package/dist/clis/douyin/stats.d.ts +1 -0
  85. package/dist/clis/douyin/stats.js +27 -0
  86. package/dist/clis/douyin/stats.test.d.ts +1 -0
  87. package/dist/clis/douyin/stats.test.js +22 -0
  88. package/dist/clis/douyin/update.d.ts +1 -0
  89. package/dist/clis/douyin/update.js +31 -0
  90. package/dist/clis/douyin/update.test.d.ts +1 -0
  91. package/dist/clis/douyin/update.test.js +11 -0
  92. package/dist/clis/douyin/videos.d.ts +1 -0
  93. package/dist/clis/douyin/videos.js +34 -0
  94. package/dist/clis/douyin/videos.test.d.ts +1 -0
  95. package/dist/clis/douyin/videos.test.js +11 -0
  96. package/dist/clis/hackernews/search.yaml +1 -1
  97. package/dist/clis/instagram/search.yaml +2 -1
  98. package/dist/clis/linux-do/search.yaml +3 -1
  99. package/dist/clis/medium/search.js +1 -1
  100. package/dist/clis/reuters/search.js +0 -1
  101. package/dist/clis/twitter/search.js +5 -3
  102. package/dist/clis/twitter/search.test.js +54 -2
  103. package/dist/clis/weibo/comments.d.ts +1 -0
  104. package/dist/clis/weibo/comments.js +53 -0
  105. package/dist/clis/weibo/feed.d.ts +1 -0
  106. package/dist/clis/weibo/feed.js +56 -0
  107. package/dist/clis/weibo/hot.js +0 -1
  108. package/dist/clis/weibo/me.d.ts +1 -0
  109. package/dist/clis/weibo/me.js +76 -0
  110. package/dist/clis/weibo/post.d.ts +1 -0
  111. package/dist/clis/weibo/post.js +75 -0
  112. package/dist/clis/weibo/user.d.ts +1 -0
  113. package/dist/clis/weibo/user.js +63 -0
  114. package/dist/clis/weibo/utils.d.ts +6 -0
  115. package/dist/clis/weibo/utils.js +30 -0
  116. package/dist/clis/weread/search.js +3 -2
  117. package/dist/clis/xueqiu/search.yaml +2 -1
  118. package/dist/clis/yahoo-finance/quote.js +0 -1
  119. package/dist/clis/youtube/channel.d.ts +1 -0
  120. package/dist/clis/youtube/channel.js +150 -0
  121. package/dist/clis/youtube/comments.d.ts +1 -0
  122. package/dist/clis/youtube/comments.js +95 -0
  123. package/dist/clis/youtube/search.js +0 -1
  124. package/dist/clis/zhihu/search.yaml +2 -1
  125. package/dist/external-clis.yaml +0 -17
  126. package/dist/weread-search-regression.test.d.ts +1 -0
  127. package/dist/weread-search-regression.test.js +39 -0
  128. package/docs/.vitepress/config.mts +13 -0
  129. package/docs/adapters/browser/douyin.md +75 -0
  130. package/docs/adapters/browser/twitter.md +6 -0
  131. package/docs/adapters/index.md +6 -1
  132. package/extension/dist/background.js +508 -518
  133. package/extension/manifest.json +6 -2
  134. package/extension/package.json +1 -1
  135. package/extension/popup.html +84 -0
  136. package/extension/popup.js +25 -0
  137. package/extension/src/background.ts +20 -1
  138. package/package.json +1 -1
  139. package/src/clis/apple-podcasts/search.ts +2 -1
  140. package/src/clis/arxiv/search.ts +2 -2
  141. package/src/clis/bbc/news.ts +0 -1
  142. package/src/clis/ctrip/search.ts +0 -1
  143. package/src/clis/douyin/_shared/browser-fetch.test.ts +38 -0
  144. package/src/clis/douyin/_shared/browser-fetch.ts +45 -0
  145. package/src/clis/douyin/_shared/creation-id.test.ts +26 -0
  146. package/src/clis/douyin/_shared/creation-id.ts +8 -0
  147. package/src/clis/douyin/_shared/imagex-upload.test.ts +113 -0
  148. package/src/clis/douyin/_shared/imagex-upload.ts +76 -0
  149. package/src/clis/douyin/_shared/sts2.ts +20 -0
  150. package/src/clis/douyin/_shared/text-extra.test.ts +42 -0
  151. package/src/clis/douyin/_shared/text-extra.ts +33 -0
  152. package/src/clis/douyin/_shared/timing.test.ts +38 -0
  153. package/src/clis/douyin/_shared/timing.ts +22 -0
  154. package/src/clis/douyin/_shared/tos-upload-short-read.test.ts +102 -0
  155. package/src/clis/douyin/_shared/tos-upload.test.ts +281 -0
  156. package/src/clis/douyin/_shared/tos-upload.ts +444 -0
  157. package/src/clis/douyin/_shared/transcode.test.ts +117 -0
  158. package/src/clis/douyin/_shared/transcode.ts +78 -0
  159. package/src/clis/douyin/_shared/types.ts +29 -0
  160. package/src/clis/douyin/activities.test.ts +25 -0
  161. package/src/clis/douyin/activities.ts +23 -0
  162. package/src/clis/douyin/collections.test.ts +26 -0
  163. package/src/clis/douyin/collections.ts +25 -0
  164. package/src/clis/douyin/delete.test.ts +12 -0
  165. package/src/clis/douyin/delete.ts +20 -0
  166. package/src/clis/douyin/draft.test.ts +12 -0
  167. package/src/clis/douyin/draft.ts +282 -0
  168. package/src/clis/douyin/drafts.test.ts +12 -0
  169. package/src/clis/douyin/drafts.ts +27 -0
  170. package/src/clis/douyin/hashtag.test.ts +28 -0
  171. package/src/clis/douyin/hashtag.ts +56 -0
  172. package/src/clis/douyin/location.test.ts +26 -0
  173. package/src/clis/douyin/location.ts +27 -0
  174. package/src/clis/douyin/profile.test.ts +12 -0
  175. package/src/clis/douyin/profile.ts +37 -0
  176. package/src/clis/douyin/publish.test.ts +45 -0
  177. package/src/clis/douyin/publish.ts +340 -0
  178. package/src/clis/douyin/stats.test.ts +25 -0
  179. package/src/clis/douyin/stats.ts +30 -0
  180. package/src/clis/douyin/update.test.ts +12 -0
  181. package/src/clis/douyin/update.ts +43 -0
  182. package/src/clis/douyin/videos.test.ts +12 -0
  183. package/src/clis/douyin/videos.ts +49 -0
  184. package/src/clis/hackernews/search.yaml +1 -1
  185. package/src/clis/instagram/search.yaml +2 -1
  186. package/src/clis/linux-do/search.yaml +3 -1
  187. package/src/clis/medium/search.ts +1 -1
  188. package/src/clis/reuters/search.ts +0 -1
  189. package/src/clis/twitter/search.test.ts +69 -2
  190. package/src/clis/twitter/search.ts +5 -3
  191. package/src/clis/weibo/comments.ts +54 -0
  192. package/src/clis/weibo/feed.ts +57 -0
  193. package/src/clis/weibo/hot.ts +0 -1
  194. package/src/clis/weibo/me.ts +77 -0
  195. package/src/clis/weibo/post.ts +77 -0
  196. package/src/clis/weibo/user.ts +64 -0
  197. package/src/clis/weibo/utils.ts +32 -0
  198. package/src/clis/weread/search.ts +3 -2
  199. package/src/clis/xueqiu/search.yaml +2 -1
  200. package/src/clis/yahoo-finance/quote.ts +0 -1
  201. package/src/clis/youtube/channel.ts +155 -0
  202. package/src/clis/youtube/comments.ts +97 -0
  203. package/src/clis/youtube/search.ts +0 -1
  204. package/src/clis/zhihu/search.yaml +2 -1
  205. package/src/external-clis.yaml +0 -17
  206. package/src/weread-search-regression.test.ts +44 -0
  207. package/tests/e2e/browser-public-extended.test.ts +162 -0
  208. package/tests/e2e/browser-public.test.ts +7 -146
  209. package/vitest.config.ts +24 -17
@@ -68,7 +68,7 @@ describe('twitter search command', () => {
68
68
  ]),
69
69
  };
70
70
 
71
- const result = await command!.func!(page as any, { query: 'from:alice', limit: 5 });
71
+ const result = await command!.func!(page as any, { query: 'from:alice', filter: 'top', limit: 5 });
72
72
 
73
73
  expect(result).toEqual([
74
74
  {
@@ -84,6 +84,73 @@ describe('twitter search command', () => {
84
84
  expect(evaluate).toHaveBeenCalledTimes(4);
85
85
  });
86
86
 
87
+ it('uses f=live in search URL when filter is live', async () => {
88
+ const command = getRegistry().get('twitter/search');
89
+
90
+ const evaluate = vi.fn()
91
+ .mockResolvedValueOnce(undefined)
92
+ .mockResolvedValueOnce('/search');
93
+
94
+ const page = {
95
+ goto: vi.fn().mockResolvedValue(undefined),
96
+ wait: vi.fn().mockResolvedValue(undefined),
97
+ installInterceptor: vi.fn().mockResolvedValue(undefined),
98
+ evaluate,
99
+ autoScroll: vi.fn().mockResolvedValue(undefined),
100
+ getInterceptedRequests: vi.fn().mockResolvedValue([]),
101
+ };
102
+
103
+ await command!.func!(page as any, { query: 'breaking news', filter: 'live', limit: 5 });
104
+
105
+ const pushStateCall = evaluate.mock.calls[0][0] as string;
106
+ expect(pushStateCall).toContain('f=live');
107
+ expect(pushStateCall).toContain(encodeURIComponent('breaking news'));
108
+ });
109
+
110
+ it('uses f=top in search URL when filter is top', async () => {
111
+ const command = getRegistry().get('twitter/search');
112
+
113
+ const evaluate = vi.fn()
114
+ .mockResolvedValueOnce(undefined)
115
+ .mockResolvedValueOnce('/search');
116
+
117
+ const page = {
118
+ goto: vi.fn().mockResolvedValue(undefined),
119
+ wait: vi.fn().mockResolvedValue(undefined),
120
+ installInterceptor: vi.fn().mockResolvedValue(undefined),
121
+ evaluate,
122
+ autoScroll: vi.fn().mockResolvedValue(undefined),
123
+ getInterceptedRequests: vi.fn().mockResolvedValue([]),
124
+ };
125
+
126
+ await command!.func!(page as any, { query: 'test', filter: 'top', limit: 5 });
127
+
128
+ const pushStateCall = evaluate.mock.calls[0][0] as string;
129
+ expect(pushStateCall).toContain('f=top');
130
+ });
131
+
132
+ it('falls back to top when filter is omitted', async () => {
133
+ const command = getRegistry().get('twitter/search');
134
+
135
+ const evaluate = vi.fn()
136
+ .mockResolvedValueOnce(undefined)
137
+ .mockResolvedValueOnce('/search');
138
+
139
+ const page = {
140
+ goto: vi.fn().mockResolvedValue(undefined),
141
+ wait: vi.fn().mockResolvedValue(undefined),
142
+ installInterceptor: vi.fn().mockResolvedValue(undefined),
143
+ evaluate,
144
+ autoScroll: vi.fn().mockResolvedValue(undefined),
145
+ getInterceptedRequests: vi.fn().mockResolvedValue([]),
146
+ };
147
+
148
+ await command!.func!(page as any, { query: 'test', limit: 5 });
149
+
150
+ const pushStateCall = evaluate.mock.calls[0][0] as string;
151
+ expect(pushStateCall).toContain('f=top');
152
+ });
153
+
87
154
  it('throws with the final path after both attempts fail', async () => {
88
155
  const command = getRegistry().get('twitter/search');
89
156
  expect(command?.func).toBeTypeOf('function');
@@ -103,7 +170,7 @@ describe('twitter search command', () => {
103
170
  getInterceptedRequests: vi.fn(),
104
171
  };
105
172
 
106
- await expect(command!.func!(page as any, { query: 'from:alice', limit: 5 }))
173
+ await expect(command!.func!(page as any, { query: 'from:alice', filter: 'top', limit: 5 }))
107
174
  .rejects
108
175
  .toThrow('Final path: /login');
109
176
  expect(page.autoScroll).not.toHaveBeenCalled();
@@ -9,8 +9,8 @@ import type { IPage } from '../../types.js';
9
9
  * pushState + popstate. A second attempt is enough for the intermittent cases
10
10
  * reported in issue #353 while keeping the flow narrowly scoped.
11
11
  */
12
- async function navigateToSearch(page: Pick<IPage, 'evaluate' | 'wait'>, query: string): Promise<void> {
13
- const searchUrl = JSON.stringify(`/search?q=${encodeURIComponent(query)}&f=top`);
12
+ async function navigateToSearch(page: Pick<IPage, 'evaluate' | 'wait'>, query: string, filter: string): Promise<void> {
13
+ const searchUrl = JSON.stringify(`/search?q=${encodeURIComponent(query)}&f=${filter}`);
14
14
  let lastPath = '';
15
15
 
16
16
  for (let attempt = 1; attempt <= 2; attempt++) {
@@ -46,11 +46,13 @@ cli({
46
46
  browser: true,
47
47
  args: [
48
48
  { name: 'query', type: 'string', required: true, positional: true },
49
+ { name: 'filter', type: 'string', default: 'top', choices: ['top', 'live'] },
49
50
  { name: 'limit', type: 'int', default: 15 },
50
51
  ],
51
52
  columns: ['id', 'author', 'text', 'likes', 'views', 'url'],
52
53
  func: async (page, kwargs) => {
53
54
  const query = kwargs.query;
55
+ const filter = kwargs.filter === 'live' ? 'live' : 'top';
54
56
 
55
57
  // 1. Navigate to x.com/explore (has a search input at the top)
56
58
  await page.goto('https://x.com/explore');
@@ -66,7 +68,7 @@ cli({
66
68
  // a full page reload, so the interceptor stays alive.
67
69
  // Note: the previous approach (nativeSetter + Enter keydown on the
68
70
  // search input) does not reliably trigger Twitter's form submission.
69
- await navigateToSearch(page, query);
71
+ await navigateToSearch(page, query, filter);
70
72
 
71
73
  // 4. Scroll to trigger additional pagination
72
74
  await page.autoScroll({ times: 3, delayMs: 2000 });
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Weibo comments — get comments on a post.
3
+ */
4
+ import { cli, Strategy } from '../../registry.js';
5
+
6
+ cli({
7
+ site: 'weibo',
8
+ name: 'comments',
9
+ description: 'Get comments on a Weibo post',
10
+ domain: 'weibo.com',
11
+ strategy: Strategy.COOKIE,
12
+ args: [
13
+ { name: 'id', required: true, positional: true, help: 'Post ID (numeric idstr)' },
14
+ { name: 'limit', type: 'int', default: 20, help: 'Number of comments (max 50)' },
15
+ ],
16
+ columns: ['rank', 'author', 'text', 'likes', 'replies', 'time'],
17
+ func: async (page, kwargs) => {
18
+ const count = Math.min(kwargs.limit || 20, 50);
19
+ await page.goto('https://weibo.com');
20
+ await page.wait(2);
21
+
22
+ const id = String(kwargs.id);
23
+ const data = await page.evaluate(`
24
+ (async () => {
25
+ const id = ${JSON.stringify(id)};
26
+ const count = ${count};
27
+ const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').trim();
28
+
29
+ const url = '/ajax/statuses/buildComments?flow=0&is_reload=1&id=' + id + '&is_show_bulletin=2&is_mix=0&count=' + count;
30
+ const resp = await fetch(url, {credentials: 'include'});
31
+ if (!resp.ok) return {error: 'HTTP ' + resp.status};
32
+ const data = await resp.json();
33
+ if (!data.ok) return {error: 'API error: ' + (data.msg || 'unknown')};
34
+
35
+ return (data.data || []).map((c, i) => {
36
+ const item = {
37
+ rank: i + 1,
38
+ author: c.user?.screen_name || '',
39
+ text: strip(c.text || ''),
40
+ likes: c.like_count || 0,
41
+ replies: c.total_number || 0,
42
+ time: c.created_at || '',
43
+ };
44
+ if (c.reply_comment) {
45
+ item.reply_to = (c.reply_comment.user?.screen_name || '') + ': ' + strip(c.reply_comment.text || '').substring(0, 80);
46
+ }
47
+ return item;
48
+ });
49
+ })()
50
+ `);
51
+ if (!Array.isArray(data)) return [];
52
+ return data;
53
+ },
54
+ });
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Weibo feed — home timeline from followed users.
3
+ */
4
+ import { cli, Strategy } from '../../registry.js';
5
+ import { getSelfUid } from './utils.js';
6
+
7
+ cli({
8
+ site: 'weibo',
9
+ name: 'feed',
10
+ description: 'Weibo home timeline (posts from followed users)',
11
+ domain: 'weibo.com',
12
+ strategy: Strategy.COOKIE,
13
+ args: [
14
+ { name: 'limit', type: 'int', default: 15, help: 'Number of posts (max 50)' },
15
+ ],
16
+ columns: ['author', 'text', 'reposts', 'comments', 'likes', 'time', 'url'],
17
+ func: async (page, kwargs) => {
18
+ const count = Math.min(kwargs.limit || 15, 50);
19
+ await page.goto('https://weibo.com');
20
+ await page.wait(2);
21
+ const uid = await getSelfUid(page);
22
+
23
+ const data = await page.evaluate(`
24
+ (async () => {
25
+ const uid = ${JSON.stringify(uid)};
26
+ const count = ${count};
27
+ const listId = '10001' + uid;
28
+ const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').trim();
29
+
30
+ const resp = await fetch('/ajax/feed/unreadfriendstimeline?list_id=' + listId + '&refresh=4&since_id=0&count=' + count, {credentials: 'include'});
31
+ if (!resp.ok) return {error: 'HTTP ' + resp.status};
32
+ const data = await resp.json();
33
+ if (!data.ok) return {error: 'API error: ' + (data.msg || 'unknown')};
34
+
35
+ return (data.statuses || []).slice(0, count).map(s => {
36
+ const u = s.user || {};
37
+ const item = {
38
+ author: u.screen_name || '',
39
+ text: (s.text_raw || strip(s.text || '')).substring(0, 200),
40
+ reposts: s.reposts_count || 0,
41
+ comments: s.comments_count || 0,
42
+ likes: s.attitudes_count || 0,
43
+ time: s.created_at || '',
44
+ url: 'https://weibo.com/' + (u.id || '') + '/' + (s.mblogid || ''),
45
+ };
46
+ if (s.retweeted_status) {
47
+ const rt = s.retweeted_status;
48
+ item.retweeted = (rt.user?.screen_name || '[deleted]') + ': ' + (rt.text_raw || strip(rt.text || '')).substring(0, 100);
49
+ }
50
+ return item;
51
+ });
52
+ })()
53
+ `);
54
+ if (!Array.isArray(data)) return [];
55
+ return data;
56
+ },
57
+ });
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Weibo hot search — browser cookie API.
3
- * Source: bb-sites/weibo/hot.js
4
3
  */
5
4
  import { cli, Strategy } from '../../registry.js';
6
5
 
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Weibo me — current logged-in user profile.
3
+ */
4
+ import { cli, Strategy } from '../../registry.js';
5
+ import { CommandExecutionError } from '../../errors.js';
6
+ import { getSelfUid } from './utils.js';
7
+
8
+ cli({
9
+ site: 'weibo',
10
+ name: 'me',
11
+ description: 'My Weibo profile info',
12
+ domain: 'weibo.com',
13
+ strategy: Strategy.COOKIE,
14
+ args: [],
15
+ columns: ['screen_name', 'uid', 'followers', 'following', 'statuses', 'verified', 'location'],
16
+ func: async (page) => {
17
+ await page.goto('https://weibo.com');
18
+ await page.wait(2);
19
+ const uid = await getSelfUid(page);
20
+
21
+ const data = await page.evaluate(`
22
+ (async () => {
23
+ const uid = ${JSON.stringify(uid)};
24
+
25
+ // Try Vue store first
26
+ const app = document.querySelector('#app')?.__vue_app__;
27
+ const store = app?.config?.globalProperties?.$store;
28
+ const cfg = store?.state?.config?.config;
29
+ const u = cfg?.user;
30
+
31
+ // Fetch detail info
32
+ const detailResp = await fetch('/ajax/profile/detail?uid=' + uid, {credentials: 'include'});
33
+ const detail = detailResp.ok ? await detailResp.json() : null;
34
+ const d = detail?.data || {};
35
+
36
+ if (u && u.id) {
37
+ return {
38
+ screen_name: u.screen_name,
39
+ uid: u.id,
40
+ followers: u.followers_count,
41
+ following: u.friends_count,
42
+ statuses: u.statuses_count,
43
+ verified: u.verified || false,
44
+ location: u.location || '',
45
+ description: u.description || d.description || '',
46
+ avatar: u.avatar_hd || u.avatar_large || '',
47
+ profile_url: 'https://weibo.com' + (u.profile_url || '/u/' + u.id),
48
+ };
49
+ }
50
+
51
+ // Fallback: fetch profile API
52
+ const resp = await fetch('/ajax/profile/info?uid=' + uid, {credentials: 'include'});
53
+ if (!resp.ok) return {error: 'HTTP ' + resp.status};
54
+ const info = await resp.json();
55
+ if (!info.ok) return {error: 'API error'};
56
+ const p = info.data?.user;
57
+ if (!p) return {error: 'User data not found'};
58
+ return {
59
+ screen_name: p.screen_name,
60
+ uid: p.id,
61
+ followers: p.followers_count,
62
+ following: p.friends_count,
63
+ statuses: p.statuses_count,
64
+ verified: p.verified || false,
65
+ location: p.location || '',
66
+ description: p.description || d.description || '',
67
+ avatar: p.avatar_hd || p.avatar_large || '',
68
+ profile_url: 'https://weibo.com' + (p.profile_url || '/u/' + p.id),
69
+ };
70
+ })()
71
+ `);
72
+
73
+ if (!data || typeof data !== 'object') throw new CommandExecutionError('Failed to fetch profile');
74
+ if ((data as Record<string, unknown>).error) throw new CommandExecutionError(String((data as Record<string, unknown>).error));
75
+ return data as Record<string, unknown>;
76
+ },
77
+ });
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Weibo post — get a single post by ID.
3
+ */
4
+ import { cli, Strategy } from '../../registry.js';
5
+ import { CommandExecutionError } from '../../errors.js';
6
+
7
+ cli({
8
+ site: 'weibo',
9
+ name: 'post',
10
+ description: 'Get a single Weibo post',
11
+ domain: 'weibo.com',
12
+ strategy: Strategy.COOKIE,
13
+ args: [
14
+ { name: 'id', required: true, positional: true, help: 'Post ID (numeric idstr or mblogid from URL)' },
15
+ ],
16
+ columns: ['field', 'value'],
17
+ func: async (page, kwargs) => {
18
+ await page.goto('https://weibo.com');
19
+ await page.wait(2);
20
+
21
+ const id = String(kwargs.id);
22
+ const data = await page.evaluate(`
23
+ (async () => {
24
+ const id = ${JSON.stringify(id)};
25
+ const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').trim();
26
+
27
+ const resp = await fetch('/ajax/statuses/show?id=' + encodeURIComponent(id), {credentials: 'include'});
28
+ if (!resp.ok) return {error: 'HTTP ' + resp.status};
29
+ const s = await resp.json();
30
+ if (!s.ok && !s.idstr) return {error: 'Post not found'};
31
+
32
+ // Fetch long text if needed
33
+ let fullText = s.text_raw || strip(s.text || '');
34
+ if (s.isLongText || s.is_long_text) {
35
+ try {
36
+ const ltResp = await fetch('/ajax/statuses/longtext?id=' + s.idstr, {credentials: 'include'});
37
+ if (ltResp.ok) {
38
+ const lt = await ltResp.json();
39
+ if (lt.data?.longTextContent) fullText = strip(lt.data.longTextContent);
40
+ }
41
+ } catch {}
42
+ }
43
+
44
+ const u = s.user || {};
45
+ const result = {
46
+ id: s.idstr || String(s.id),
47
+ mblogid: s.mblogid,
48
+ author: u.screen_name || '',
49
+ text: fullText,
50
+ created_at: s.created_at,
51
+ source: strip(s.source || ''),
52
+ reposts: s.reposts_count || 0,
53
+ comments: s.comments_count || 0,
54
+ likes: s.attitudes_count || 0,
55
+ pic_count: s.pic_num || 0,
56
+ url: 'https://weibo.com/' + (u.id || '') + '/' + (s.mblogid || ''),
57
+ };
58
+
59
+ if (s.retweeted_status) {
60
+ const rt = s.retweeted_status;
61
+ result.retweeted_from = (rt.user?.screen_name || '[deleted]');
62
+ result.retweeted_text = rt.text_raw || strip(rt.text || '');
63
+ }
64
+
65
+ return result;
66
+ })()
67
+ `);
68
+
69
+ if (!data || typeof data !== 'object') throw new CommandExecutionError('Failed to fetch post');
70
+ if ((data as Record<string, unknown>).error) throw new CommandExecutionError(String((data as Record<string, unknown>).error));
71
+
72
+ return Object.entries(data as Record<string, unknown>).map(([field, value]) => ({
73
+ field,
74
+ value: String(value),
75
+ }));
76
+ },
77
+ });
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Weibo user — get user profile by uid or screen_name.
3
+ */
4
+ import { cli, Strategy } from '../../registry.js';
5
+ import { CommandExecutionError } from '../../errors.js';
6
+
7
+ cli({
8
+ site: 'weibo',
9
+ name: 'user',
10
+ description: 'Get Weibo user profile',
11
+ domain: 'weibo.com',
12
+ strategy: Strategy.COOKIE,
13
+ args: [
14
+ { name: 'id', required: true, positional: true, help: 'User ID (numeric uid) or screen name' },
15
+ ],
16
+ columns: ['screen_name', 'uid', 'followers', 'following', 'statuses', 'verified', 'description', 'location', 'url'],
17
+ func: async (page, kwargs) => {
18
+ await page.goto('https://weibo.com');
19
+ await page.wait(2);
20
+
21
+ const id = String(kwargs.id);
22
+ const data = await page.evaluate(`
23
+ (async () => {
24
+ const id = ${JSON.stringify(id)};
25
+ const isUid = /^\\d+$/.test(id);
26
+ const query = isUid ? 'uid=' + id : 'screen_name=' + encodeURIComponent(id);
27
+
28
+ const resp = await fetch('/ajax/profile/info?' + query, {credentials: 'include'});
29
+ if (!resp.ok) return {error: 'HTTP ' + resp.status};
30
+ const data = await resp.json();
31
+ if (!data.ok || !data.data?.user) return {error: 'User not found'};
32
+
33
+ const u = data.data.user;
34
+
35
+ // Fetch detail info
36
+ const detailResp = await fetch('/ajax/profile/detail?uid=' + u.id, {credentials: 'include'});
37
+ const detail = detailResp.ok ? await detailResp.json() : null;
38
+ const d = detail?.data || {};
39
+
40
+ return {
41
+ screen_name: u.screen_name,
42
+ uid: u.id,
43
+ followers: u.followers_count,
44
+ following: u.friends_count,
45
+ statuses: u.statuses_count,
46
+ verified: u.verified || false,
47
+ verified_reason: u.verified_reason || '',
48
+ description: u.description || d.description || '',
49
+ location: u.location || '',
50
+ gender: u.gender === 'm' ? 'male' : u.gender === 'f' ? 'female' : '',
51
+ avatar: u.avatar_hd || u.avatar_large || '',
52
+ url: 'https://weibo.com' + (u.profile_url || '/u/' + u.id),
53
+ birthday: d.birthday || '',
54
+ created_at: d.created_at || '',
55
+ ip_location: d.ip_location || '',
56
+ };
57
+ })()
58
+ `);
59
+
60
+ if (!data || typeof data !== 'object') throw new CommandExecutionError('Failed to fetch user profile');
61
+ if ((data as Record<string, unknown>).error) throw new CommandExecutionError(String((data as Record<string, unknown>).error));
62
+ return data as Record<string, unknown>;
63
+ },
64
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Shared Weibo utilities — uid extraction.
3
+ */
4
+
5
+ import type { IPage } from '../../types.js';
6
+ import { AuthRequiredError } from '../../errors.js';
7
+
8
+ /** Get the currently logged-in user's uid from Vue store or config API. */
9
+ export async function getSelfUid(page: IPage): Promise<string> {
10
+ const uid = await page.evaluate(`
11
+ (() => {
12
+ const app = document.querySelector('#app')?.__vue_app__;
13
+ const store = app?.config?.globalProperties?.$store;
14
+ const uid = store?.state?.config?.config?.uid;
15
+ if (uid) return String(uid);
16
+ return null;
17
+ })()
18
+ `);
19
+ if (uid) return uid as string;
20
+
21
+ // Fallback: config API
22
+ const config = await page.evaluate(`
23
+ (async () => {
24
+ const resp = await fetch('/ajax/config/get_config', {credentials: 'include'});
25
+ if (!resp.ok) return null;
26
+ const data = await resp.json();
27
+ return data.ok && data.data?.uid ? String(data.data.uid) : null;
28
+ })()
29
+ `);
30
+ if (config) return config as string;
31
+ throw new AuthRequiredError('weibo.com');
32
+ }
@@ -12,15 +12,16 @@ cli({
12
12
  { name: 'query', positional: true, required: true, help: 'Search keyword' },
13
13
  { name: 'limit', type: 'int', default: 10, help: 'Max results' },
14
14
  ],
15
- columns: ['rank', 'title', 'author', 'bookId'],
15
+ columns: ['rank', 'title', 'author', 'bookId', 'url'],
16
16
  func: async (_page, args) => {
17
- const data = await fetchWebApi('/search/global', { keyword: args.keyword });
17
+ const data = await fetchWebApi('/search/global', { keyword: args.query });
18
18
  const books: any[] = data?.books ?? [];
19
19
  return books.slice(0, Number(args.limit)).map((item: any, i: number) => ({
20
20
  rank: i + 1,
21
21
  title: item.bookInfo?.title ?? '',
22
22
  author: item.bookInfo?.author ?? '',
23
23
  bookId: item.bookInfo?.bookId ?? '',
24
+ url: item.bookInfo?.bookId ? 'https://weread.qq.com/web/bookDetail/' + item.bookInfo.bookId : '',
24
25
  }));
25
26
  },
26
27
  });
@@ -48,7 +48,8 @@ pipeline:
48
48
  exchange: ${{ item.exchange }}
49
49
  price: ${{ item.price }}
50
50
  changePercent: ${{ item.changePercent }}
51
+ url: ${{ item.url }}
51
52
 
52
53
  - limit: ${{ args.limit }}
53
54
 
54
- columns: [symbol, name, exchange, price, changePercent]
55
+ columns: [symbol, name, exchange, price, changePercent, url]
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Yahoo Finance stock quote — multi-strategy API fallback.
3
- * Source: bb-sites/yahoo-finance/quote.js
4
3
  */
5
4
  import { cli, Strategy } from '../../registry.js';
6
5