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

47 lines
1.9 KiB
JavaScript

import { cli } from '@jackwener/opencli/registry';
cli({
site: 'instagram',
name: 'save',
access: 'write',
description: 'Save (bookmark) an Instagram post',
domain: 'www.instagram.com',
args: [
{
name: 'username',
required: true,
positional: true,
help: 'Username of the post author',
},
{ name: 'index', type: 'int', default: 1, help: 'Post index (1 = most recent)' },
],
columns: ['status', 'user', 'post'],
pipeline: [
{ navigate: 'https://www.instagram.com' },
{ evaluate: `(async () => {
const username = \${{ args.username | json }};
const idx = \${{ args.index }} - 1;
const headers = { 'X-IG-App-ID': '936619743392459' };
const opts = { credentials: 'include', headers };
const r1 = await fetch('https://www.instagram.com/api/v1/users/web_profile_info/?username=' + encodeURIComponent(username), opts);
if (!r1.ok) throw new Error('User not found: ' + username);
const userId = (await r1.json())?.data?.user?.id;
const r2 = await fetch('https://www.instagram.com/api/v1/feed/user/' + userId + '/?count=' + (idx + 1), opts);
const posts = (await r2.json())?.items || [];
if (idx >= posts.length) throw new Error('Post index ' + (idx + 1) + ' not found');
const pk = posts[idx].pk;
const caption = (posts[idx].caption?.text || '').substring(0, 60);
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
const r3 = await fetch('https://www.instagram.com/api/v1/web/save/' + pk + '/save/', {
method: 'POST', credentials: 'include',
headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },
});
if (!r3.ok) throw new Error('Failed to save: HTTP ' + r3.status);
return [{ status: 'Saved', user: username, post: caption || '(post #' + (idx+1) + ')' }];
})()
` },
],
});