Created
October 16, 2016 11:26
-
-
Save imamhidayat92/4267c67cda4b7661d9e5a202dba726ea to your computer and use it in GitHub Desktop.
This is a simple script used to read all comments from an Instagram account photo. Tested on this link: https://www.instagram.com/p/BLlhP-yDplV/
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 container = $('._mo9iw._123ym'); | |
var button = $('._l086v._ifrvy'); | |
var scrollAndClick = () => { | |
container.scrollTop = 0; | |
button.click(); | |
}; | |
var startScrollAndClick = (finishCallback) => { | |
scrollAndClick(); | |
setTimeout(() => { | |
if (button.offsetParent !== null) { | |
startScrollAndClick(); | |
} | |
else { | |
console.info('Fetching all comments finished.'); | |
if (typeof finishCallback === 'function') { | |
finishCallback(); | |
} | |
} | |
}, 1000); | |
}; | |
var classifyComment = () => { | |
window.__valueMap = {}; | |
var commentList = document.querySelectorAll('._nk46a'); | |
for (var i = 1; i < commentList.length; i++) { | |
var comment = commentList[i].children[1].innerHTML.replace(/<!-- [/]?react-text(:\s{1}[0-9]+)? -->/g, ''); | |
var content; | |
try { | |
content = parseInt(comment, 10) + ''; | |
if (window.__valueMap[content]) { | |
window.__valueMap[content]++; | |
} | |
else { | |
window.__valueMap[content] = 1; | |
} | |
} | |
catch (err) { | |
content = ''; | |
} | |
} | |
console.info(window.__valueMap); | |
}; | |
startScrollAndClick(() => { | |
classifyComment(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment