Skip to content

Instantly share code, notes, and snippets.

@duncangh
Last active July 26, 2020 01:02
Show Gist options
  • Save duncangh/29bb8d53fd367f059791f875a00c2aa6 to your computer and use it in GitHub Desktop.
Save duncangh/29bb8d53fd367f059791f875a00c2aa6 to your computer and use it in GitHub Desktop.

Next Door

Get controversial posts only

Comment Count

<span class="post-comment-count-text _1kIyUB5y" aria-hidden="true">51 Comments</span>

Like Count

<div class="_3n-MWIpy nuanMjzR" data-testid="count-text">16</div>



```javascript

const comment_count_selector = "span[class*='post-comment-count-text']");
const like_count_selector = "div[data-testid*='count-text']";
const post_selector = "div[class*='feed-container']"

let reply_buttons = [...$("div[data-testid='post-reply-button']")]
let reply_cts_txt = reply_buttons.map((e) => {return e.innerText});

reply_buttons[0].parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement
reply_buttons[0].parentElement.parentElement.parentElement.parentElement.parentElement.setAttribute('hidden', true);
const div = document.querySelector('div');
const spanWithNoAttributes = [...div.children]
  .find(span => span.attributes.length === 0);
spanWithNoAttributes.textContent = 'THIS ONE HERE';


$( "input[name*='man']" )
// scroll to bottom
function autoScrolling() {
window.scrollTo(0,document.body.scrollHeight);
}
var refreshIntervalId = setInterval(autoScrolling, 5);
// run to cancel
clearInterval(refreshIntervalId);
// feed selection:
// feed elem is a div with the class named:
// col-md-12 feed-container with-navbar
// let post_selector = "div[class*='feed-container']"
let post_selector = "div[class='col-md-12 feed-container with-navbar'] > div";
let comment_count_selector = "span[class*='post-comment-count-text']";
let like_count_selector = "div[data-testid*='count-text']";
let has_comment_count = function(post){
return $(post).find(comment_count_selector)[0] !== undefined};
let missing_comment_count = function(post){
return $(post).find(comment_count_selector)[0] === undefined};
let get_comment_count = function(post) {
return parseInt($(post).find(comment_count_selector)[0].innerText.replace(' Comment', ' ').split(' ')[0]) || 0}
let comment_count_less_than = function(post){
comment_count = parseInt($(post).find(comment_count_selector)[0].innerText.replace(' Comment', ' ').split(' ')[0]) || 0
return comment_count < 10}
let comment_count_greater_than = function(post){
comment_count = parseInt($(post).find(comment_count_selector)[0].innerText.replace(' Comment', ' ').split(' ')[0]) || 0
return comment_count > 10}
let post_list = [...$(post_selector)]//.filter(has_comment_count);
$(post_list.filter(missing_comment_count)).hide(); //let posts_without_comments =
let posts_with_comments = post_list.filter(has_comment_count);
$(posts_with_comments.filter(comment_count_less_than)).hide()
let total_comments = posts_with_comments.map((post) => get_comment_count(post));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment