Files
wehub-resource-sync 9b395f5cc3
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
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

56 lines
1.8 KiB
JavaScript

import { cli } from '@jackwener/opencli/registry';
cli({
site: 'tiktok',
name: 'profile',
access: 'read',
description: 'Get TikTok user profile info',
domain: 'www.tiktok.com',
args: [
{
name: 'username',
required: true,
positional: true,
help: 'TikTok username (without @)',
},
],
columns: [
'username',
'name',
'followers',
'following',
'likes',
'videos',
'verified',
'bio',
],
pipeline: [
{ navigate: { url: 'https://www.tiktok.com/explore', settleMs: 5000 } },
{ evaluate: `(async () => {
const username = \${{ args.username | json }};
const res = await fetch('https://www.tiktok.com/@' + encodeURIComponent(username), { credentials: 'include' });
if (!res.ok) throw new Error('User not found: ' + username);
const html = await res.text();
const idx = html.indexOf('__UNIVERSAL_DATA_FOR_REHYDRATION__');
if (idx === -1) throw new Error('Could not parse profile data');
const start = html.indexOf('>', idx) + 1;
const end = html.indexOf('</script>', start);
const data = JSON.parse(html.substring(start, end));
const ud = data['__DEFAULT_SCOPE__'] && data['__DEFAULT_SCOPE__']['webapp.user-detail'];
const u = ud && ud.userInfo && ud.userInfo.user;
const s = ud && ud.userInfo && ud.userInfo.stats;
if (!u) throw new Error('User not found: ' + username);
return [{
username: u.uniqueId || username,
name: u.nickname || '',
bio: (u.signature || '').replace(/\\n/g, ' ').substring(0, 120),
followers: s && s.followerCount || 0,
following: s && s.followingCount || 0,
likes: s && s.heartCount || 0,
videos: s && s.videoCount || 0,
verified: u.verified ? 'Yes' : 'No',
}];
})()
` },
],
});