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
49 lines
2.0 KiB
JavaScript
49 lines
2.0 KiB
JavaScript
import { cli } from '@jackwener/opencli/registry';
|
|
cli({
|
|
site: 'instagram',
|
|
name: 'comment',
|
|
access: 'write',
|
|
description: 'Comment on an Instagram post',
|
|
domain: 'www.instagram.com',
|
|
args: [
|
|
{
|
|
name: 'username',
|
|
required: true,
|
|
positional: true,
|
|
help: 'Username of the post author',
|
|
},
|
|
{ name: 'text', required: true, positional: true, help: 'Comment text' },
|
|
{ name: 'index', type: 'int', default: 1, help: 'Post index (1 = most recent)' },
|
|
],
|
|
columns: ['status', 'user', 'text'],
|
|
pipeline: [
|
|
{ navigate: 'https://www.instagram.com' },
|
|
{ evaluate: `(async () => {
|
|
const username = \${{ args.username | json }};
|
|
const commentText = \${{ args.text | 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 csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
|
|
const r3 = await fetch('https://www.instagram.com/api/v1/web/comments/' + pk + '/add/', {
|
|
method: 'POST', credentials: 'include',
|
|
headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
body: 'comment_text=' + encodeURIComponent(commentText),
|
|
});
|
|
if (!r3.ok) throw new Error('Failed to comment: HTTP ' + r3.status);
|
|
return [{ status: 'Commented', user: username, text: commentText }];
|
|
})()
|
|
` },
|
|
],
|
|
});
|