/ clis / tiktok / unsave.js
unsave.js
 1  import { cli } from '@jackwener/opencli/registry';
 2  cli({
 3      site: 'tiktok',
 4      name: 'unsave',
 5      description: 'Remove a TikTok video from Favorites',
 6      domain: 'www.tiktok.com',
 7      args: [
 8          { name: 'url', required: true, positional: true, help: 'TikTok video URL' },
 9      ],
10      columns: ['status', 'url'],
11      pipeline: [
12          { navigate: { url: '${{ args.url }}', settleMs: 6000 } },
13          { evaluate: `(async () => {
14    const url = \${{ args.url | json }};
15    const btn = document.querySelector('[data-e2e="bookmark-icon"]') ||
16                document.querySelector('[data-e2e="collect-icon"]');
17    if (!btn) throw new Error('Favorites button not found - make sure you are logged in');
18    const container = btn.closest('button') || btn.closest('[role="button"]') || btn;
19    const aria = (container.getAttribute('aria-label') || '').toLowerCase();
20    if (aria.includes('add to favorites') || aria.includes('收藏')) {
21      if (!aria.includes('remove') && !aria.includes('取消')) {
22        return [{ status: 'Not in Favorites', url: url }];
23      }
24    }
25    container.click();
26    await new Promise(r => setTimeout(r, 2000));
27    return [{ status: 'Removed from Favorites', url: url }];
28  })()
29  ` },
30      ],
31  });