Discussions » Développement

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

§
Posté le: 2015-08-17
Édité le: 2015-08-17

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

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?

woxxomMod
§
Posté le: 2015-08-17

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');
§
Posté le: 2015-08-17

Thank you very much for the quick answer!

Poster une réponse

Connectez-vous pour poster une réponse.