Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. // get the top-level comments in a hacker news thread
  2.  
  3. [].slice.call(document.querySelectorAll('.comment'))
  4. .filter((el) => {
  5. var getSiblings = function ( elem ) {
  6. var siblings = []
  7. var sibling = elem.parentNode.firstChild
  8. for (; sibling; sibling = sibling.nextSibling) {
  9. if (sibling.nodeType === 1 && sibling !== elem) {
  10. siblings.push(sibling)
  11. }
  12. }
  13. return siblings
  14. }
  15. // a transparent 1px gif will have a width of 0 if it is a top-level comment in the comment-tree table
  16. return getSiblings(el.parentElement)
  17. .filter((sib) => sib.className.includes('ind') && sib.firstChild.width > 0)
  18. .length === 0
  19. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement