TheSofox / Macropod Madness comic Autoloader

// ==UserScript==
// @name        Macropod Madness comic Autoloader
// @namespace   macropod_madness_autoloader
// @description To help with reading through the Macropod Madness webcomic archive ( http://www.bibp.com/macropodia ). Will automatically load and append the next comic to the bottom of the page, so you can go through the archives by continually scrolling down, rather than continually clicking "next." Each comic page also links to its url archive position.
// @include     http://www.bibp.com/macropodia/index.php*
// @version     1.0
// @grant       none
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js
// ==/UserScript==
if (window.top != window.self) //-- Don't run on frames or iframes
    return ;

var nextPage = $("html");
var loading = false;

console.log("starting script...");
function checkScrollSystem(){
    if(loading){
       return;
    }
	if( $(window).height() - $(window).scrollTop() - window.innerHeight<window.innerHeight){
        console.log("scroll met");
        var nextUrl = $("img[src='images/next.gif']", nextPage).parent().parent().attr("href");
        console.log("Next url: " + nextUrl);
        loading = true;
        nextPage = $("<div></div>").load(nextUrl, function(){
            loading=false;
            console.log("Page loaded...")
            var comicPage = $("table:eq(3)", nextPage);
            var link = $("<a href='" + nextUrl + "'></a>");
            link.append(comicPage);
            $("html").append(link)
            checkScrollSystem();
        })
	}
}

$(window).scroll(checkScrollSystem);