Last active
April 24, 2017 15:13
-
-
Save AronDavis/90981d8fc2815e113880f7b05834f35c to your computer and use it in GitHub Desktop.
Reddit - Select 1st Level Comment at Random
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
//Run this at thread level to select a random 1st level (aka parent/top-tier) comment. Useful for giveaways. | |
var parentComments = $(".sitetable.nestedlisting > .thing > .parent"); | |
var index = Math.floor(Math.random() * parentComments.length); | |
var selectedComment = $(parentComments[index]).parent(); | |
var commentId = selectedComment.attr('id'); | |
var username = selectedComment.find(".entry > .tagline > .author").text(); | |
var commentText = selectedComment.find(".usertext > .usertext-body").text(); | |
console.log(`Selected comment "${commentId}" by "${username}"\n\n${commentText}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment