Skip to content

Instantly share code, notes, and snippets.

@jamesmacfie
Created June 15, 2018 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmacfie/a9548e783870a6f5b5c9a2b319e645b2 to your computer and use it in GitHub Desktop.
Save jamesmacfie/a9548e783870a6f5b5c9a2b319e645b2 to your computer and use it in GitHub Desktop.
Find the most negative comment on Stuff.co.nz articles
const findTheMostNegativeComment = () => {
const voteVals = [];
const votes = document.querySelectorAll('.gig-comment-vote-total');
[].forEach.call(votes, (v) => {
const val = v.innerHTML;
if (val.charAt(0) === '-') {
voteVals.push({
text: val,
total: parseInt(val.slice(1)),
el: v
})
}
})
if (!voteVals.length) {
console.log('There are no negative comments');
return null;
}
return voteVals.sort((a, b) => b.total - a.total)[0].el
// Urgh gross
.parentElement.parentElement.parentElement.querySelector('.gig-comment-body').innerHTML;
}
@rickysullivan
Copy link

(findTheMostNegativeComment = () => {
...
})()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment