-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjected.js
More file actions
85 lines (74 loc) · 3.04 KB
/
injected.js
File metadata and controls
85 lines (74 loc) · 3.04 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
// Injected script to access Instagram's internal APIs
(function() {
'use strict';
// Helper to intercept Instagram's GraphQL requests
window.instagramHelper = {
// Store original fetch function
originalFetch: window.fetch,
// Initialize interception
init: function() {
const self = this;
window.fetch = function(...args) {
const url = args[0];
// Intercept GraphQL requests for followers/following
if (typeof url === 'string' && url.includes('graphql')) {
return self.originalFetch.apply(this, args).then(response => {
// Clone response to avoid consuming it
const clonedResponse = response.clone();
// Check if this is a followers/following request
if (url.includes('edge_followed_by') || url.includes('edge_follow')) {
clonedResponse.json().then(data => {
// Emit event with data
window.dispatchEvent(new CustomEvent('instagramData', {
detail: { url, data }
}));
}).catch(() => {});
}
return response;
});
}
return self.originalFetch.apply(this, args);
};
},
// Get user ID from page
getUserId: function() {
const scripts = document.querySelectorAll('script');
for (const script of scripts) {
const content = script.textContent;
if (content.includes('"profilePage_')) {
const match = content.match(/"profilePage_(\d+)"/);
if (match) return match[1];
}
}
return null;
},
// Extract shared data
getSharedData: function() {
const scripts = document.querySelectorAll('script');
for (const script of scripts) {
const content = script.textContent;
if (content.includes('window._sharedData')) {
try {
const match = content.match(/window\._sharedData\s*=\s*({.+?});/);
if (match) {
return JSON.parse(match[1]);
}
} catch (e) {
continue;
}
}
}
return null;
}
};
// Initialize the helper
window.instagramHelper.init();
// Listen for data events
window.addEventListener('instagramData', function(event) {
// Forward to content script
window.postMessage({
type: 'INSTAGRAM_DATA',
data: event.detail
}, '*');
});
})();