@jackwener/opencli 0.6.3 → 0.7.2

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 (81) hide show
  1. package/LICENSE +190 -28
  2. package/README.md +4 -4
  3. package/README.zh-CN.md +4 -4
  4. package/SKILL.md +22 -6
  5. package/dist/browser.js +2 -3
  6. package/dist/build-manifest.js +2 -0
  7. package/dist/cli-manifest.json +604 -24
  8. package/dist/clis/reddit/comment.d.ts +1 -0
  9. package/dist/clis/reddit/comment.js +57 -0
  10. package/dist/clis/reddit/popular.yaml +40 -0
  11. package/dist/clis/reddit/read.yaml +76 -0
  12. package/dist/clis/reddit/save.d.ts +1 -0
  13. package/dist/clis/reddit/save.js +51 -0
  14. package/dist/clis/reddit/saved.d.ts +1 -0
  15. package/dist/clis/reddit/saved.js +46 -0
  16. package/dist/clis/reddit/search.yaml +37 -11
  17. package/dist/clis/reddit/subreddit.yaml +14 -4
  18. package/dist/clis/reddit/subscribe.d.ts +1 -0
  19. package/dist/clis/reddit/subscribe.js +50 -0
  20. package/dist/clis/reddit/upvote.d.ts +1 -0
  21. package/dist/clis/reddit/upvote.js +64 -0
  22. package/dist/clis/reddit/upvoted.d.ts +1 -0
  23. package/dist/clis/reddit/upvoted.js +46 -0
  24. package/dist/clis/reddit/user-comments.yaml +45 -0
  25. package/dist/clis/reddit/user-posts.yaml +43 -0
  26. package/dist/clis/reddit/user.yaml +39 -0
  27. package/dist/clis/twitter/article.d.ts +1 -0
  28. package/dist/clis/twitter/article.js +157 -0
  29. package/dist/clis/twitter/bookmark.d.ts +1 -0
  30. package/dist/clis/twitter/bookmark.js +63 -0
  31. package/dist/clis/twitter/follow.d.ts +1 -0
  32. package/dist/clis/twitter/follow.js +65 -0
  33. package/dist/clis/twitter/profile.js +110 -42
  34. package/dist/clis/twitter/thread.d.ts +1 -0
  35. package/dist/clis/twitter/thread.js +150 -0
  36. package/dist/clis/twitter/unbookmark.d.ts +1 -0
  37. package/dist/clis/twitter/unbookmark.js +62 -0
  38. package/dist/clis/twitter/unfollow.d.ts +1 -0
  39. package/dist/clis/twitter/unfollow.js +71 -0
  40. package/dist/engine.js +2 -1
  41. package/dist/main.js +41 -10
  42. package/dist/output.js +2 -1
  43. package/dist/registry.d.ts +2 -8
  44. package/dist/snapshotFormatter.d.ts +9 -0
  45. package/dist/snapshotFormatter.js +352 -15
  46. package/dist/snapshotFormatter.test.d.ts +7 -0
  47. package/dist/snapshotFormatter.test.js +521 -0
  48. package/dist/validate.d.ts +14 -2
  49. package/dist/verify.d.ts +14 -2
  50. package/package.json +2 -2
  51. package/src/browser.ts +2 -4
  52. package/src/build-manifest.ts +3 -0
  53. package/src/clis/reddit/comment.ts +60 -0
  54. package/src/clis/reddit/popular.yaml +40 -0
  55. package/src/clis/reddit/read.yaml +76 -0
  56. package/src/clis/reddit/save.ts +54 -0
  57. package/src/clis/reddit/saved.ts +48 -0
  58. package/src/clis/reddit/search.yaml +37 -11
  59. package/src/clis/reddit/subreddit.yaml +14 -4
  60. package/src/clis/reddit/subscribe.ts +53 -0
  61. package/src/clis/reddit/upvote.ts +67 -0
  62. package/src/clis/reddit/upvoted.ts +48 -0
  63. package/src/clis/reddit/user-comments.yaml +45 -0
  64. package/src/clis/reddit/user-posts.yaml +43 -0
  65. package/src/clis/reddit/user.yaml +39 -0
  66. package/src/clis/twitter/article.ts +161 -0
  67. package/src/clis/twitter/bookmark.ts +67 -0
  68. package/src/clis/twitter/follow.ts +69 -0
  69. package/src/clis/twitter/profile.ts +113 -45
  70. package/src/clis/twitter/thread.ts +181 -0
  71. package/src/clis/twitter/unbookmark.ts +66 -0
  72. package/src/clis/twitter/unfollow.ts +75 -0
  73. package/src/engine.ts +4 -1
  74. package/src/main.ts +34 -7
  75. package/src/output.ts +2 -1
  76. package/src/registry.ts +2 -8
  77. package/src/snapshotFormatter.test.ts +579 -0
  78. package/src/snapshotFormatter.ts +399 -13
  79. package/src/validate.ts +19 -4
  80. package/src/verify.ts +17 -3
  81. package/vitest.config.ts +15 -1
@@ -0,0 +1,60 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'comment',
6
+ description: 'Post a comment on a Reddit post',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'post_id', type: 'string', required: true, help: 'Post ID (e.g. 1abc123) or fullname (t3_xxx)' },
12
+ { name: 'text', type: 'string', required: true, help: 'Comment text' },
13
+ ],
14
+ columns: ['status', 'message'],
15
+ func: async (page, kwargs) => {
16
+ if (!page) throw new Error('Requires browser');
17
+
18
+ await page.goto('https://www.reddit.com');
19
+ await page.wait(3);
20
+
21
+ const result = await page.evaluate(`(async () => {
22
+ try {
23
+ let postId = ${JSON.stringify(kwargs.post_id)};
24
+ const urlMatch = postId.match(/comments\\/([a-z0-9]+)/);
25
+ if (urlMatch) postId = urlMatch[1];
26
+ const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')
27
+ ? postId : 't3_' + postId;
28
+
29
+ const text = ${JSON.stringify(kwargs.text)};
30
+
31
+ // Get modhash
32
+ const meRes = await fetch('/api/me.json', { credentials: 'include' });
33
+ const me = await meRes.json();
34
+ const modhash = me?.data?.modhash || '';
35
+
36
+ const res = await fetch('/api/comment', {
37
+ method: 'POST',
38
+ credentials: 'include',
39
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
40
+ body: 'parent=' + encodeURIComponent(fullname)
41
+ + '&text=' + encodeURIComponent(text)
42
+ + '&api_type=json'
43
+ + (modhash ? '&uh=' + encodeURIComponent(modhash) : ''),
44
+ });
45
+
46
+ if (!res.ok) return { ok: false, message: 'HTTP ' + res.status };
47
+ const data = await res.json();
48
+ const errors = data?.json?.errors;
49
+ if (errors && errors.length > 0) {
50
+ return { ok: false, message: errors.map(e => e.join(': ')).join('; ') };
51
+ }
52
+ return { ok: true, message: 'Comment posted on ' + fullname };
53
+ } catch (e) {
54
+ return { ok: false, message: e.toString() };
55
+ }
56
+ })()`);
57
+
58
+ return [{ status: result.ok ? 'success' : 'failed', message: result.message }];
59
+ }
60
+ });
@@ -0,0 +1,40 @@
1
+ site: reddit
2
+ name: popular
3
+ description: Reddit Popular posts (/r/popular)
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ limit:
10
+ type: int
11
+ default: 20
12
+
13
+ columns: [rank, title, subreddit, score, comments, url]
14
+
15
+ pipeline:
16
+ - navigate: https://www.reddit.com
17
+ - evaluate: |
18
+ (async () => {
19
+ const limit = ${{ args.limit }};
20
+ const res = await fetch('/r/popular.json?limit=' + limit + '&raw_json=1', {
21
+ credentials: 'include'
22
+ });
23
+ const d = await res.json();
24
+ return (d?.data?.children || []).map(c => ({
25
+ title: c.data.title,
26
+ subreddit: c.data.subreddit_name_prefixed,
27
+ score: c.data.score,
28
+ comments: c.data.num_comments,
29
+ author: c.data.author,
30
+ url: 'https://www.reddit.com' + c.data.permalink,
31
+ }));
32
+ })()
33
+ - map:
34
+ rank: ${{ index + 1 }}
35
+ title: ${{ item.title }}
36
+ subreddit: ${{ item.subreddit }}
37
+ score: ${{ item.score }}
38
+ comments: ${{ item.comments }}
39
+ url: ${{ item.url }}
40
+ - limit: ${{ args.limit }}
@@ -0,0 +1,76 @@
1
+ site: reddit
2
+ name: read
3
+ description: Read a Reddit post and its comments
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ post_id:
10
+ type: string
11
+ required: true
12
+ description: "Post ID (e.g. 1abc123) or full URL"
13
+ sort:
14
+ type: string
15
+ default: best
16
+ description: "Comment sort: best, top, new, controversial, old, qa"
17
+ limit:
18
+ type: int
19
+ default: 25
20
+ description: Number of top-level comments to fetch
21
+
22
+ columns: [type, author, score, text]
23
+
24
+ pipeline:
25
+ - navigate: https://www.reddit.com
26
+ - evaluate: |
27
+ (async () => {
28
+ let postId = ${{ args.post_id | json }};
29
+ const urlMatch = postId.match(/comments\/([a-z0-9]+)/);
30
+ if (urlMatch) postId = urlMatch[1];
31
+
32
+ const sort = ${{ args.sort | json }};
33
+ const limit = ${{ args.limit }};
34
+ const res = await fetch('/comments/' + postId + '.json?sort=' + sort + '&limit=' + limit + '&raw_json=1', {
35
+ credentials: 'include'
36
+ });
37
+ const data = await res.json();
38
+ if (!Array.isArray(data) || data.length < 1) return [];
39
+
40
+ const results = [];
41
+
42
+ // First element: post itself
43
+ const post = data[0]?.data?.children?.[0]?.data;
44
+ if (post) {
45
+ let body = post.selftext || '';
46
+ if (body.length > 2000) body = body.slice(0, 2000) + '\n... [truncated]';
47
+ results.push({
48
+ type: '📰 POST',
49
+ author: post.author,
50
+ score: post.score,
51
+ text: post.title + (body ? '\n\n' + body : '') + (post.url && !post.is_self ? '\n🔗 ' + post.url : ''),
52
+ });
53
+ }
54
+
55
+ // Second element: comments
56
+ const comments = data[1]?.data?.children || [];
57
+ for (const c of comments) {
58
+ if (c.kind !== 't1') continue;
59
+ const d = c.data;
60
+ let body = d.body || '';
61
+ if (body.length > 500) body = body.slice(0, 500) + '...';
62
+ results.push({
63
+ type: '💬 COMMENT',
64
+ author: d.author || '[deleted]',
65
+ score: d.score || 0,
66
+ text: body,
67
+ });
68
+ }
69
+
70
+ return results;
71
+ })()
72
+ - map:
73
+ type: ${{ item.type }}
74
+ author: ${{ item.author }}
75
+ score: ${{ item.score }}
76
+ text: ${{ item.text }}
@@ -0,0 +1,54 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'save',
6
+ description: 'Save or unsave a Reddit post',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'post_id', type: 'string', required: true, help: 'Post ID (e.g. 1abc123) or fullname (t3_xxx)' },
12
+ { name: 'undo', type: 'boolean', default: false, help: 'Unsave instead of save' },
13
+ ],
14
+ columns: ['status', 'message'],
15
+ func: async (page, kwargs) => {
16
+ if (!page) throw new Error('Requires browser');
17
+
18
+ await page.goto('https://www.reddit.com');
19
+ await page.wait(3);
20
+
21
+ const result = await page.evaluate(`(async () => {
22
+ try {
23
+ let postId = ${JSON.stringify(kwargs.post_id)};
24
+ const urlMatch = postId.match(/comments\\/([a-z0-9]+)/);
25
+ if (urlMatch) postId = urlMatch[1];
26
+ const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')
27
+ ? postId : 't3_' + postId;
28
+
29
+ const undo = ${kwargs.undo ? 'true' : 'false'};
30
+ const endpoint = undo ? '/api/unsave' : '/api/save';
31
+
32
+ // Get modhash
33
+ const meRes = await fetch('/api/me.json', { credentials: 'include' });
34
+ const me = await meRes.json();
35
+ const modhash = me?.data?.modhash || '';
36
+
37
+ const res = await fetch(endpoint, {
38
+ method: 'POST',
39
+ credentials: 'include',
40
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
41
+ body: 'id=' + encodeURIComponent(fullname)
42
+ + (modhash ? '&uh=' + encodeURIComponent(modhash) : ''),
43
+ });
44
+
45
+ if (!res.ok) return { ok: false, message: 'HTTP ' + res.status };
46
+ return { ok: true, message: (undo ? 'Unsaved' : 'Saved') + ' ' + fullname };
47
+ } catch (e) {
48
+ return { ok: false, message: e.toString() };
49
+ }
50
+ })()`);
51
+
52
+ return [{ status: result.ok ? 'success' : 'failed', message: result.message }];
53
+ }
54
+ });
@@ -0,0 +1,48 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'saved',
6
+ description: 'Browse your saved Reddit posts',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'limit', type: 'int', default: 15 },
12
+ ],
13
+ columns: ['title', 'subreddit', 'score', 'comments', 'url'],
14
+ func: async (page, kwargs) => {
15
+ if (!page) throw new Error('Requires browser');
16
+
17
+ await page.goto('https://www.reddit.com');
18
+ await page.wait(3);
19
+
20
+ const result = await page.evaluate(`(async () => {
21
+ try {
22
+ // Get current username
23
+ const meRes = await fetch('/api/me.json?raw_json=1', { credentials: 'include' });
24
+ const me = await meRes.json();
25
+ const username = me?.name || me?.data?.name;
26
+ if (!username) return { error: 'Not logged in — cannot determine username' };
27
+
28
+ const limit = ${kwargs.limit};
29
+ const res = await fetch('/user/' + username + '/saved.json?limit=' + limit + '&raw_json=1', {
30
+ credentials: 'include'
31
+ });
32
+ const d = await res.json();
33
+ return (d?.data?.children || []).map(c => ({
34
+ title: c.data.title || c.data.body?.slice(0, 100) || '-',
35
+ subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
36
+ score: c.data.score || 0,
37
+ comments: c.data.num_comments || 0,
38
+ url: 'https://www.reddit.com' + (c.data.permalink || ''),
39
+ }));
40
+ } catch (e) {
41
+ return { error: e.toString() };
42
+ }
43
+ })()`);
44
+
45
+ if (result?.error) throw new Error(result.error);
46
+ return (result || []).slice(0, kwargs.limit);
47
+ }
48
+ });
@@ -9,26 +9,52 @@ args:
9
9
  query:
10
10
  type: string
11
11
  required: true
12
+ subreddit:
13
+ type: string
14
+ default: ""
15
+ description: "Search within a specific subreddit"
16
+ sort:
17
+ type: string
18
+ default: relevance
19
+ description: "Sort order: relevance, hot, top, new, comments"
20
+ time:
21
+ type: string
22
+ default: all
23
+ description: "Time filter: hour, day, week, month, year, all"
12
24
  limit:
13
25
  type: int
14
26
  default: 15
15
27
 
16
- columns: [title, subreddit, author, upvotes, comments, url]
28
+ columns: [title, subreddit, author, score, comments, url]
17
29
 
18
30
  pipeline:
19
31
  - navigate: https://www.reddit.com
20
32
  - evaluate: |
21
33
  (async () => {
22
- const q = encodeURIComponent('${{ args.query }}');
23
- const res = await fetch('/search.json?q=' + q + '&limit=${{ args.limit }}', { credentials: 'include' });
24
- const j = await res.json();
25
- return j?.data?.children || [];
34
+ const q = encodeURIComponent(${{ args.query | json }});
35
+ const sub = ${{ args.subreddit | json }};
36
+ const sort = ${{ args.sort | json }};
37
+ const time = ${{ args.time | json }};
38
+ const limit = ${{ args.limit }};
39
+ const basePath = sub ? '/r/' + sub + '/search.json' : '/search.json';
40
+ const params = 'q=' + q + '&sort=' + sort + '&t=' + time + '&limit=' + limit
41
+ + '&restrict_sr=' + (sub ? 'on' : 'off') + '&raw_json=1';
42
+ const res = await fetch(basePath + '?' + params, { credentials: 'include' });
43
+ const d = await res.json();
44
+ return (d?.data?.children || []).map(c => ({
45
+ title: c.data.title,
46
+ subreddit: c.data.subreddit_name_prefixed,
47
+ author: c.data.author,
48
+ score: c.data.score,
49
+ comments: c.data.num_comments,
50
+ url: 'https://www.reddit.com' + c.data.permalink,
51
+ }));
26
52
  })()
27
53
  - map:
28
- title: ${{ item.data.title }}
29
- subreddit: ${{ item.data.subreddit_name_prefixed }}
30
- author: ${{ item.data.author }}
31
- upvotes: ${{ item.data.score }}
32
- comments: ${{ item.data.num_comments }}
33
- url: https://www.reddit.com${{ item.data.permalink }}
54
+ title: ${{ item.title }}
55
+ subreddit: ${{ item.subreddit }}
56
+ author: ${{ item.author }}
57
+ score: ${{ item.score }}
58
+ comments: ${{ item.comments }}
59
+ url: ${{ item.url }}
34
60
  - limit: ${{ args.limit }}
@@ -12,7 +12,11 @@ args:
12
12
  sort:
13
13
  type: string
14
14
  default: hot
15
- description: "Sorting method: hot, new, top, rising"
15
+ description: "Sorting method: hot, new, top, rising, controversial"
16
+ time:
17
+ type: string
18
+ default: all
19
+ description: "Time filter for top/controversial: hour, day, week, month, year, all"
16
20
  limit:
17
21
  type: int
18
22
  default: 15
@@ -23,10 +27,16 @@ pipeline:
23
27
  - navigate: https://www.reddit.com
24
28
  - evaluate: |
25
29
  (async () => {
26
- let sub = '${{ args.name }}';
30
+ let sub = ${{ args.name | json }};
27
31
  if (sub.startsWith('r/')) sub = sub.slice(2);
28
- const sort = '${{ args.sort }}';
29
- const res = await fetch('/r/' + sub + '/' + sort + '.json?limit=${{ args.limit }}', { credentials: 'include' });
32
+ const sort = ${{ args.sort | json }};
33
+ const time = ${{ args.time | json }};
34
+ const limit = ${{ args.limit }};
35
+ let url = '/r/' + sub + '/' + sort + '.json?limit=' + limit + '&raw_json=1';
36
+ if ((sort === 'top' || sort === 'controversial') && time) {
37
+ url += '&t=' + time;
38
+ }
39
+ const res = await fetch(url, { credentials: 'include' });
30
40
  const j = await res.json();
31
41
  return j?.data?.children || [];
32
42
  })()
@@ -0,0 +1,53 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'subscribe',
6
+ description: 'Subscribe or unsubscribe to a subreddit',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'subreddit', type: 'string', required: true, help: 'Subreddit name (e.g. python)' },
12
+ { name: 'undo', type: 'boolean', default: false, help: 'Unsubscribe instead of subscribe' },
13
+ ],
14
+ columns: ['status', 'message'],
15
+ func: async (page, kwargs) => {
16
+ if (!page) throw new Error('Requires browser');
17
+
18
+ await page.goto('https://www.reddit.com');
19
+ await page.wait(3);
20
+
21
+ const result = await page.evaluate(`(async () => {
22
+ try {
23
+ let sub = ${JSON.stringify(kwargs.subreddit)};
24
+ if (sub.startsWith('r/')) sub = sub.slice(2);
25
+
26
+ const undo = ${kwargs.undo ? 'true' : 'false'};
27
+ const action = undo ? 'unsub' : 'sub';
28
+
29
+ // Get modhash
30
+ const meRes = await fetch('/api/me.json', { credentials: 'include' });
31
+ const me = await meRes.json();
32
+ const modhash = me?.data?.modhash || '';
33
+
34
+ const res = await fetch('/api/subscribe', {
35
+ method: 'POST',
36
+ credentials: 'include',
37
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
38
+ body: 'sr_name=' + encodeURIComponent(sub)
39
+ + '&action=' + action
40
+ + (modhash ? '&uh=' + encodeURIComponent(modhash) : ''),
41
+ });
42
+
43
+ if (!res.ok) return { ok: false, message: 'HTTP ' + res.status };
44
+ const label = undo ? 'Unsubscribed from' : 'Subscribed to';
45
+ return { ok: true, message: label + ' r/' + sub };
46
+ } catch (e) {
47
+ return { ok: false, message: e.toString() };
48
+ }
49
+ })()`);
50
+
51
+ return [{ status: result.ok ? 'success' : 'failed', message: result.message }];
52
+ }
53
+ });
@@ -0,0 +1,67 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'upvote',
6
+ description: 'Upvote or downvote a Reddit post',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'post_id', type: 'string', required: true, help: 'Post ID (e.g. 1abc123) or fullname (t3_xxx)' },
12
+ { name: 'direction', type: 'string', default: 'up', help: 'Vote direction: up, down, none' },
13
+ ],
14
+ columns: ['status', 'message'],
15
+ func: async (page, kwargs) => {
16
+ if (!page) throw new Error('Requires browser');
17
+
18
+ await page.goto('https://www.reddit.com');
19
+ await page.wait(3);
20
+
21
+ const result = await page.evaluate(`(async () => {
22
+ try {
23
+ let postId = ${JSON.stringify(kwargs.post_id)};
24
+ // Extract ID from URL if needed
25
+ const urlMatch = postId.match(/comments\\/([a-z0-9]+)/);
26
+ if (urlMatch) postId = urlMatch[1];
27
+ // Build fullname
28
+ const fullname = postId.startsWith('t3_') || postId.startsWith('t1_')
29
+ ? postId : 't3_' + postId;
30
+
31
+ const dir = ${JSON.stringify(kwargs.direction)};
32
+ const direction = dir === 'down' ? -1 : dir === 'none' ? 0 : 1;
33
+
34
+ // Get modhash from Reddit config
35
+ const configEl = document.getElementById('config');
36
+ let modhash = '';
37
+ if (configEl) {
38
+ modhash = configEl.querySelector('[name="uh"]')?.getAttribute('content') || '';
39
+ }
40
+ if (!modhash) {
41
+ // Try fetching from /api/me.json
42
+ const meRes = await fetch('/api/me.json', { credentials: 'include' });
43
+ const me = await meRes.json();
44
+ modhash = me?.data?.modhash || '';
45
+ }
46
+
47
+ const res = await fetch('/api/vote', {
48
+ method: 'POST',
49
+ credentials: 'include',
50
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
51
+ body: 'id=' + encodeURIComponent(fullname)
52
+ + '&dir=' + direction
53
+ + (modhash ? '&uh=' + encodeURIComponent(modhash) : ''),
54
+ });
55
+
56
+ if (!res.ok) return { ok: false, message: 'HTTP ' + res.status };
57
+
58
+ const labels = { '1': 'Upvoted', '-1': 'Downvoted', '0': 'Vote removed' };
59
+ return { ok: true, message: (labels[String(direction)] || 'Voted') + ' ' + fullname };
60
+ } catch (e) {
61
+ return { ok: false, message: e.toString() };
62
+ }
63
+ })()`);
64
+
65
+ return [{ status: result.ok ? 'success' : 'failed', message: result.message }];
66
+ }
67
+ });
@@ -0,0 +1,48 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'reddit',
5
+ name: 'upvoted',
6
+ description: 'Browse your upvoted Reddit posts',
7
+ domain: 'reddit.com',
8
+ strategy: Strategy.COOKIE,
9
+ browser: true,
10
+ args: [
11
+ { name: 'limit', type: 'int', default: 15 },
12
+ ],
13
+ columns: ['title', 'subreddit', 'score', 'comments', 'url'],
14
+ func: async (page, kwargs) => {
15
+ if (!page) throw new Error('Requires browser');
16
+
17
+ await page.goto('https://www.reddit.com');
18
+ await page.wait(3);
19
+
20
+ const result = await page.evaluate(`(async () => {
21
+ try {
22
+ // Get current username
23
+ const meRes = await fetch('/api/me.json?raw_json=1', { credentials: 'include' });
24
+ const me = await meRes.json();
25
+ const username = me?.name || me?.data?.name;
26
+ if (!username) return { error: 'Not logged in — cannot determine username' };
27
+
28
+ const limit = ${kwargs.limit};
29
+ const res = await fetch('/user/' + username + '/upvoted.json?limit=' + limit + '&raw_json=1', {
30
+ credentials: 'include'
31
+ });
32
+ const d = await res.json();
33
+ return (d?.data?.children || []).map(c => ({
34
+ title: c.data.title || '-',
35
+ subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
36
+ score: c.data.score || 0,
37
+ comments: c.data.num_comments || 0,
38
+ url: 'https://www.reddit.com' + (c.data.permalink || ''),
39
+ }));
40
+ } catch (e) {
41
+ return { error: e.toString() };
42
+ }
43
+ })()`);
44
+
45
+ if (result?.error) throw new Error(result.error);
46
+ return (result || []).slice(0, kwargs.limit);
47
+ }
48
+ });
@@ -0,0 +1,45 @@
1
+ site: reddit
2
+ name: user-comments
3
+ description: View a Reddit user's comment history
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ username:
10
+ type: string
11
+ required: true
12
+ limit:
13
+ type: int
14
+ default: 15
15
+
16
+ columns: [subreddit, score, body, url]
17
+
18
+ pipeline:
19
+ - navigate: https://www.reddit.com
20
+ - evaluate: |
21
+ (async () => {
22
+ const username = ${{ args.username | json }};
23
+ const name = username.startsWith('u/') ? username.slice(2) : username;
24
+ const limit = ${{ args.limit }};
25
+ const res = await fetch('/user/' + name + '/comments.json?limit=' + limit + '&raw_json=1', {
26
+ credentials: 'include'
27
+ });
28
+ const d = await res.json();
29
+ return (d?.data?.children || []).map(c => {
30
+ let body = c.data.body || '';
31
+ if (body.length > 300) body = body.slice(0, 300) + '...';
32
+ return {
33
+ subreddit: c.data.subreddit_name_prefixed,
34
+ score: c.data.score,
35
+ body: body,
36
+ url: 'https://www.reddit.com' + c.data.permalink,
37
+ };
38
+ });
39
+ })()
40
+ - map:
41
+ subreddit: ${{ item.subreddit }}
42
+ score: ${{ item.score }}
43
+ body: ${{ item.body }}
44
+ url: ${{ item.url }}
45
+ - limit: ${{ args.limit }}
@@ -0,0 +1,43 @@
1
+ site: reddit
2
+ name: user-posts
3
+ description: View a Reddit user's submitted posts
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ username:
10
+ type: string
11
+ required: true
12
+ limit:
13
+ type: int
14
+ default: 15
15
+
16
+ columns: [title, subreddit, score, comments, url]
17
+
18
+ pipeline:
19
+ - navigate: https://www.reddit.com
20
+ - evaluate: |
21
+ (async () => {
22
+ const username = ${{ args.username | json }};
23
+ const name = username.startsWith('u/') ? username.slice(2) : username;
24
+ const limit = ${{ args.limit }};
25
+ const res = await fetch('/user/' + name + '/submitted.json?limit=' + limit + '&raw_json=1', {
26
+ credentials: 'include'
27
+ });
28
+ const d = await res.json();
29
+ return (d?.data?.children || []).map(c => ({
30
+ title: c.data.title,
31
+ subreddit: c.data.subreddit_name_prefixed,
32
+ score: c.data.score,
33
+ comments: c.data.num_comments,
34
+ url: 'https://www.reddit.com' + c.data.permalink,
35
+ }));
36
+ })()
37
+ - map:
38
+ title: ${{ item.title }}
39
+ subreddit: ${{ item.subreddit }}
40
+ score: ${{ item.score }}
41
+ comments: ${{ item.comments }}
42
+ url: ${{ item.url }}
43
+ - limit: ${{ args.limit }}
@@ -0,0 +1,39 @@
1
+ site: reddit
2
+ name: user
3
+ description: View a Reddit user profile
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ username:
10
+ type: string
11
+ required: true
12
+
13
+ columns: [field, value]
14
+
15
+ pipeline:
16
+ - navigate: https://www.reddit.com
17
+ - evaluate: |
18
+ (async () => {
19
+ const username = ${{ args.username | json }};
20
+ const name = username.startsWith('u/') ? username.slice(2) : username;
21
+ const res = await fetch('/user/' + name + '/about.json?raw_json=1', {
22
+ credentials: 'include'
23
+ });
24
+ const d = await res.json();
25
+ const u = d?.data || d || {};
26
+ const created = u.created_utc ? new Date(u.created_utc * 1000).toISOString().split('T')[0] : '-';
27
+ return [
28
+ { field: 'Username', value: 'u/' + (u.name || name) },
29
+ { field: 'Post Karma', value: String(u.link_karma || 0) },
30
+ { field: 'Comment Karma', value: String(u.comment_karma || 0) },
31
+ { field: 'Total Karma', value: String(u.total_karma || (u.link_karma||0) + (u.comment_karma||0)) },
32
+ { field: 'Account Created', value: created },
33
+ { field: 'Gold', value: u.is_gold ? '⭐ Yes' : 'No' },
34
+ { field: 'Verified', value: u.verified ? '✅ Yes' : 'No' },
35
+ ];
36
+ })()
37
+ - map:
38
+ field: ${{ item.field }}
39
+ value: ${{ item.value }}