pklauzinski / jscroll

An infinite scrolling plugin for jQuery.
http://jscroll.com/
1.11k stars 563 forks source link

Userscripts with jScroll don't work in Greasemonkey 4.0 (but work ok in GM 3.x and Tampermonkey ) #144

Closed darkred closed 6 years ago

darkred commented 6 years ago

As you might have noticed in https://www.greasespot.net/2017/09/greasemonkey-4-for-script-authors.html:

Greasemonkey 4 is changing to be compatible with the Browser Extension API. At its core, this set of APIs is completely asynchronous. Greasemonkey's old "GM" APIs are typically synchronous._

But, the following userscript, meant for use to http://majorgeeks.com/, (as well as any other userscript with jScroll that I have), even though it doesn't use any GM API, unfortunately it doesn't work in Greasemonkey 4.0 (or latest GM 4.1 beta4) in FF 57 : it only shows jScroll: -2 from bottom. Loading next request... in Web Console whenever I scroll to the bottom of the page. There's no error in Browser Console.

In GM 3.x (FF 56) as well as in Tampermonkey 4.5.5590 (FF 57) it works ok.


// ==UserScript==
// @name        MajorGeeks - Infinite Scrolling
// @include     http://www.majorgeeks.com/*
// @version     1
// @grant       none
// @require     http://code.jquery.com/jquery-2.1.4.min.js
// @require     https://cdn.rawgit.com/pklauzinski/jscroll/master/jquery.jscroll.js
// ==/UserScript==

$('.pageborder').last().jscroll({
    debug: true,
    nextSelector: '#content .pagelink:nth-last-child(6) a',
    contentSelector: '#content',
});
darkred commented 6 years ago

I found it, it's because of the use of relative paths. I quote from https://github.com/greasemonkey/greasemonkey/issues/2680#issuecomment-344778286 :

Use absolute paths. This is an issue with Firefox and content scripts.

So, changing all three instances of _$next.attr('href') into _$next.get(0).href

Edit: eventually I used _$next.prop('href') to stay within the jQuery paradigm