Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

'load more comments' in reddit.com remains at "loading.." when clicked via my userscript

edited August 2015 in Development Firefox

I'm trying to improve my userscript Reddit Infinite Scrolling (jScroll)
so that (in reddit posts that have many comments) (for example this post),
when user user has scrolled to the bottom,
to automatically click the last button(element) "load more comments"
and therefore to have infinite scrolling in comments too.

So, I've made this code (based on this) :

// ==UserScript==
// @name        Reddit Infinite Scrolling
// @include     http://www.reddit.com/*
// @include     https://www.reddit.com/*
// @version     1
// @grant       none
// @require     http://code.jquery.com/jquery-2.1.4.min.js
// ==/UserScript==


$(window).scroll(function () {
  if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
    // $(window).unbind('scroll');
    alert('bottom!');
    var element = document.getElementsByClassName('morecomments');
    var last = element.length;
    element[last - 1].firstChild.click();
  }
});

The alert bottom! works alright,
but the last button(element) "load more comments" of the page,
doesn't load more comments, but stays at 'loading...'.
Note: I've even tried the commmented out line $(window).unbind('scroll');
but it didn't make any difference.

On the other hand, in Firefox Console,
document.getElementsByClassName('morecomments')[77].firstChild.click();
works ok.

Could you please help me with this?

Comments

  • Reddit uses retarded inline js, so you can't invoke it from a sandboxed userscript by default.

    1. Replace // @grant none with // @grant unsafeWindow
    2. var element = unsafeWindow.document.getElementsByClassName('morecomments');
  • Thank you very much for the quick answer!

Sign In or Register to comment.