Skip to content

Instantly share code, notes, and snippets.

@AronDavis
Last active April 24, 2017 15:13
Show Gist options
  • Save AronDavis/90981d8fc2815e113880f7b05834f35c to your computer and use it in GitHub Desktop.
Save AronDavis/90981d8fc2815e113880f7b05834f35c to your computer and use it in GitHub Desktop.
Reddit - Select 1st Level Comment at Random
//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