Gab.ai Endlessly Scrollable Content

Automatically loads more Gab.ai content when you scroll to the ended of the loaded content.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Gab.ai Endlessly Scrollable Content
// @namespace    http://gab.ai/Jeremy20_9
// @version      0.3
// @description  Automatically loads more Gab.ai content when you scroll to the ended of the loaded content.
// @author       Jeremiah 20:9
// @match        https://gab.ai
// @match        https://gab.ai/*
// @grant        none
// ==/UserScript==

var itvwait = -1;
var clicked = false;
$(document).ready(function(){
    $(window).scroll(function(){
        if(clicked)
            return;
        
        var posts = $("post");
        if(posts.length < 2)
            return;
        
        var elem = $("a.post-list__load-more:last")[0];
        if(elem !== undefined && elementInViewport(elem))
        {
            // http://stackoverflow.com/a/27761213/2381712
            var evt = new MouseEvent("click", {
                view: window,
                bubbles: true,
                cancelable: true,
                clientX: 20
            });
            var ele = $("a.post-list__load-more")[0];
            ele.dispatchEvent(evt);
            clicked = true;
            itvwait = setTimeout(function(){clicked = false;}, 3000);
        }
    });
});

// http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
function elementInViewport(el) {
  var top = el.offsetTop;
  var left = el.offsetLeft;
  var width = el.offsetWidth;
  var height = el.offsetHeight;

  while(el.offsetParent) {
    el = el.offsetParent;
    top += el.offsetTop;
    left += el.offsetLeft;
  }

  return (
    top >= window.pageYOffset &&
    left >= window.pageXOffset &&
    (top + height) <= (window.pageYOffset + window.innerHeight) &&
    (left + width) <= (window.pageXOffset + window.innerWidth)
  );
}