Last active
April 25, 2018 16:37
-
-
Save Kamapcuc/7c75785b8a76c88c0d42b06045c6eb53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var profilePage = window._sharedData.entry_data.ProfilePage; | |
if (!profilePage) throw new Error("откройте страницу профиля, не поста"); | |
var user_id = profilePage[0].graphql.user.id; | |
var csrf_token = window._sharedData.config.csrf_token; | |
var url_template = 'https://www.instagram.com/graphql/query/?query_hash=42323d64886122307be10013ad2dcc44&variables='; | |
var getMessageData = function(after) { | |
var variablesObj = { | |
id: user_id, | |
first: 50 | |
}; | |
if (after) variablesObj.after = after; | |
var curUrl = url_template + encodeURIComponent(JSON.stringify(variablesObj)); | |
var getReq = new XMLHttpRequest(); | |
getReq.open("GET",curUrl,false); | |
getReq.send(null); | |
return JSON.parse(getReq.responseText); | |
}; | |
var getAllPosts = function() { | |
var result = []; | |
var lastHash = null; | |
var hasNext = true; | |
do { | |
var curBatch = getMessageData(lastHash).data.user.edge_owner_to_timeline_media; | |
lastHash = curBatch.page_info.end_cursor; | |
hasNext = curBatch.page_info.has_next_page; | |
result = result.concat(curBatch.edges.map(function(n){return n.node.id})); | |
console.log(result.length + ' from ' + curBatch.count + ' posts loaded'); | |
} while(hasNext); | |
return result; | |
}; | |
var likePost = function(postId) { | |
var likeUrl = 'https://www.instagram.com/web/likes/' + postId + '/like/'; | |
var likeReq = new XMLHttpRequest(); | |
likeReq.open("POST",likeUrl,false); | |
likeReq.setRequestHeader('X-CSRFToken', csrf_token); | |
likeReq.send(null); | |
if (likeReq.status != 200) { | |
throw new Error("Скрипт остановлен, чтобы, вас забанили " + likeReq.statusText); | |
} | |
return new Promise(resolve => setTimeout(resolve, 2000)); | |
}; | |
var messageIds = getAllPosts(); | |
for (var i = 0; i < messageIds.length; i++) { | |
await likePost(messageIds[i]); | |
console.log((i + 1) + ' from ' + messageIds.length + ' posts liked'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment