-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathigjs.js
39 lines (38 loc) · 1.45 KB
/
igjs.js
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
function getPosts(user) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const url = 'https://allorigins.me/get?url=' + encodeURIComponent('https://instagram.com/' + user + '/')
xhr.open("GET", url);
xhr.onload = () => resolve(formatPosts(xhr.responseText, user));
xhr.onerror = () => reject(xhr.statusText);
xhr.send();
});
}
function formatPosts(rawPosts, username) {
let result = [];
const captions = [];
rawPosts = JSON.parse(rawPosts)
rawPosts = JSON.parse(rawPosts.contents.split('window._sharedData = ')[1].split('\;\<\/script>')[0]).entry_data.ProfilePage[0].graphql.user.edge_owner_to_timeline_media.edges
rawPosts.forEach(function (item) {
result.push({
raw: item.node,
image: item.node.display_url,
dimensions: item.node.dimensions,
likes: item.node.edge_liked_by.count,
caption: item.node.edge_media_to_caption.edges[0].node.text,
comments: item.node.edge_media_to_comment.count,
video: item.node.is_video,
code: item.node.shortcode,
url: 'https://instagram.com/p/' + item.node.shortcode,
timestamp: item.node.taken_at_timestamp,
thumbnails: {
150: item.node.thumbnail_resources[0].src,
240: item.node.thumbnail_resources[1].src,
320: item.node.thumbnail_resources[2].src,
480: item.node.thumbnail_resources[3].src,
640: item.node.thumbnail_resources[4].src
}
})
})
return result;
}