notifications.js
1 import { cli } from '@jackwener/opencli/registry'; 2 cli({ 3 site: 'tiktok', 4 name: 'notifications', 5 description: 'Get TikTok notifications (likes, comments, mentions, followers)', 6 domain: 'www.tiktok.com', 7 args: [ 8 { name: 'limit', type: 'int', default: 15, help: 'Number of notifications' }, 9 { 10 name: 'type', 11 default: 'all', 12 help: 'Notification type', 13 choices: ['all', 'likes', 'comments', 'mentions', 'followers'], 14 }, 15 ], 16 columns: ['index', 'text'], 17 pipeline: [ 18 { navigate: { url: 'https://www.tiktok.com/following', settleMs: 5000 } }, 19 { evaluate: `(async () => { 20 const limit = \${{ args.limit }}; 21 const type = \${{ args.type | json }}; 22 const wait = (ms) => new Promise(r => setTimeout(r, ms)); 23 24 // Click inbox icon to open notifications panel 25 const inboxIcon = document.querySelector('[data-e2e="inbox-icon"]'); 26 if (inboxIcon) inboxIcon.click(); 27 await wait(1500); 28 29 // Click specific tab if needed 30 if (type !== 'all') { 31 const tab = document.querySelector('[data-e2e="' + type + '"]'); 32 if (tab) { 33 tab.click(); 34 await wait(1500); 35 } 36 } 37 38 const items = document.querySelectorAll('[data-e2e="inbox-list"] > div, [data-e2e="inbox-list"] [role="button"]'); 39 return Array.from(items) 40 .filter(el => el.textContent.trim().length > 5) 41 .slice(0, limit) 42 .map((el, i) => ({ 43 index: i + 1, 44 text: el.textContent.trim().replace(/\\s+/g, ' ').substring(0, 150), 45 })); 46 })() 47 ` }, 48 ], 49 });