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