Gab.ai Endlessly Scrollable Content

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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)
  );
}