Greasy Fork is available in English.

Discussioni » Sviluppo

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

Pubblicato: 17/08/2015
Modificato: 17/08/2015

'load more comments' in 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*
// @include*
// @version     1
// @grant       none
// @require
// ==/UserScript==

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

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,
works ok.

Could you please help me with this?

Pubblicato: 17/08/2015

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');
Pubblicato: 17/08/2015

Thank you very much for the quick answer!

Pubblica risposta

Accedi per pubblicare una risposta.