Files
wehub-resource-sync 9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

51 lines
1.9 KiB
JavaScript

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
site: 'reddit',
name: 'upvoted',
access: 'read',
description: 'Browse your upvoted Reddit posts',
domain: 'reddit.com',
strategy: Strategy.COOKIE,
browser: true,
args: [
{ name: 'limit', type: 'int', default: 15 },
],
columns: ['title', 'subreddit', 'score', 'comments', 'url'],
func: async (page, kwargs) => {
if (!page)
throw new CommandExecutionError('Browser session required');
await page.goto('https://www.reddit.com');
const result = await page.evaluate(`(async () => {
try {
// Get current username
const meRes = await fetch('/api/me.json?raw_json=1', { credentials: 'include' });
const me = await meRes.json();
const username = me?.name || me?.data?.name;
if (!username) return { error: 'Not logged in — cannot determine username' };
const limit = ${kwargs.limit};
const res = await fetch('/user/' + username + '/upvoted.json?limit=' + limit + '&raw_json=1', {
credentials: 'include'
});
const d = await res.json();
return (d?.data?.children || []).map(c => ({
title: c.data.title || '',
subreddit: c.data.subreddit_name_prefixed || 'r/' + (c.data.subreddit || '?'),
score: c.data.score || 0,
comments: c.data.num_comments || 0,
url: 'https://www.reddit.com' + (c.data.permalink || ''),
}));
} catch (e) {
return { error: e.toString() };
}
})()`);
if (result?.error) {
if (String(result.error).includes('Not logged in'))
throw new AuthRequiredError('reddit.com', result.error);
throw new CommandExecutionError(result.error);
}
return (result || []).slice(0, kwargs.limit);
}
});