me.js
1 /** 2 * Weibo me — current logged-in user profile. 3 */ 4 import { cli, Strategy } from '@jackwener/opencli/registry'; 5 import { CommandExecutionError } from '@jackwener/opencli/errors'; 6 import { getSelfUid } from './utils.js'; 7 cli({ 8 site: 'weibo', 9 name: 'me', 10 description: 'My Weibo profile info', 11 domain: 'weibo.com', 12 strategy: Strategy.COOKIE, 13 args: [], 14 columns: ['screen_name', 'uid', 'followers', 'following', 'statuses', 'verified', 'location'], 15 func: async (page) => { 16 await page.goto('https://weibo.com'); 17 await page.wait(2); 18 const uid = await getSelfUid(page); 19 const data = await page.evaluate(` 20 (async () => { 21 const uid = ${JSON.stringify(uid)}; 22 23 // Try Vue store first 24 const app = document.querySelector('#app')?.__vue_app__; 25 const store = app?.config?.globalProperties?.$store; 26 const cfg = store?.state?.config?.config; 27 const u = cfg?.user; 28 29 // Fetch detail info 30 const detailResp = await fetch('/ajax/profile/detail?uid=' + uid, {credentials: 'include'}); 31 const detail = detailResp.ok ? await detailResp.json() : null; 32 const d = detail?.data || {}; 33 34 if (u && u.id) { 35 return { 36 screen_name: u.screen_name, 37 uid: u.id, 38 followers: u.followers_count, 39 following: u.friends_count, 40 statuses: u.statuses_count, 41 verified: u.verified || false, 42 location: u.location || '', 43 description: u.description || d.description || '', 44 avatar: u.avatar_hd || u.avatar_large || '', 45 profile_url: 'https://weibo.com' + (u.profile_url || '/u/' + u.id), 46 }; 47 } 48 49 // Fallback: fetch profile API 50 const resp = await fetch('/ajax/profile/info?uid=' + uid, {credentials: 'include'}); 51 if (!resp.ok) return {error: 'HTTP ' + resp.status}; 52 const info = await resp.json(); 53 if (!info.ok) return {error: 'API error'}; 54 const p = info.data?.user; 55 if (!p) return {error: 'User data not found'}; 56 return { 57 screen_name: p.screen_name, 58 uid: p.id, 59 followers: p.followers_count, 60 following: p.friends_count, 61 statuses: p.statuses_count, 62 verified: p.verified || false, 63 location: p.location || '', 64 description: p.description || d.description || '', 65 avatar: p.avatar_hd || p.avatar_large || '', 66 profile_url: 'https://weibo.com' + (p.profile_url || '/u/' + p.id), 67 }; 68 })() 69 `); 70 if (!data || typeof data !== 'object') 71 throw new CommandExecutionError('Failed to fetch profile'); 72 if (data.error) 73 throw new CommandExecutionError(String(data.error)); 74 return data; 75 }, 76 });