Created
August 28, 2013 13:12
-
-
Save oswaldoacauan/6365888 to your computer and use it in GitHub Desktop.
Facebook - Get most liked comment
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
// Copy and paste on your console (Command - Option - J (Mac) or Control -Shift -J (Windows/Linux)) | |
// Press enter and wait the magic happens :3 | |
var intervalShowComments = setInterval(function () { | |
var evt = document.createEvent("MouseEvents"); | |
evt.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, | |
false, false, false, false, 0, null); | |
var cb = document.querySelector('.UFIPagerLink'); | |
if (cb === null) { | |
clearInterval(intervalShowComments); | |
showMostLiked(); | |
} else { | |
cb.dispatchEvent(evt); | |
} | |
}, 500) | |
function showMostLiked() { | |
var max = 0, | |
maxName = '', | |
maxNode = null, | |
nodeList = document.querySelectorAll('.UFICommentLikeButton span'), | |
nodes = Array.prototype.slice.call(nodeList, 0); | |
nodes.forEach(function (node) { | |
var likes = parseInt(node.innerHTML.replace(',', '')); | |
if (likes > max) { | |
max = likes; | |
maxNode = maxName = node.parentNode.parentNode.parentNode; | |
maxName = maxNode.querySelector('.UFICommentActorName').innerHTML; | |
} | |
}); | |
alert(maxName + ' - ' + max + ' likes'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment