-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
92 lines (78 loc) · 2.5 KB
/
background.js
File metadata and controls
92 lines (78 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.action === 'sendNote') {
handleSendNote(msg.payload).then(sendResponse);
return true;
}
});
async function handleSendNote({ cookieStr, csrftoken, ds_user_id, noteText, textColor, bgColor, audience }) {
try {
const variables = JSON.stringify({
input: {
actor_id: ds_user_id,
client_mutation_id: "1",
inbox_tray_item_type: "note",
audience: audience,
additional_params: {
note_create_params: {
note_style: 0,
note_customization: {
text_color_hex: textColor,
secondary_text_color_hex: "#f8f9f9",
customization_id: null,
custom_emoji: null,
background_color_hex: bgColor
},
note_creation_source: 1,
text: noteText,
external_attribution_url: null
}
}
},
should_fetch_friend_map_entrypoint: false,
is_location_likes_v2_enabled: false,
should_fetch_friend_map_user: false
});
const body = new URLSearchParams({
av: ds_user_id,
__d: 'www',
__user: '0',
__a: '1',
__req: '1',
dpr: '1',
__ccg: 'GOOD',
fb_api_caller_class: 'RelayModern',
fb_api_req_friendly_name: 'usePolarisCreateInboxTrayItemSubmitMutation',
variables,
server_timestamps: 'true',
doc_id: '25155183657506484',
});
const response = await fetch('https://www.instagram.com/graphql/query', {
method: 'POST',
headers: {
'accept': '*/*',
'accept-language': 'en,ar;q=0.9',
'content-type': 'application/x-www-form-urlencoded',
'origin': 'https://www.instagram.com',
'referer': 'https://www.instagram.com/',
'x-csrftoken': csrftoken,
'x-ig-app-id': '936619743392459',
'x-fb-friendly-name': 'usePolarisCreateInboxTrayItemSubmitMutation',
'cookie': cookieStr,
},
body: body.toString()
});
const data = await response.json();
if (data.errors && data.errors.length > 0) {
return { success: false, error: data.errors[0].message || 'Instagram API error' };
}
if (data.data?.xdt_create_inbox_tray_item) {
return { success: true };
}
if (response.ok) {
return { success: true };
}
return { success: false, error: 'Unexpected response from Instagram' };
} catch (err) {
return { success: false, error: err.message };
}
}