4chan instant page loader (3 pages)

By haluk Last update Nov 6, 2011 — Installed 2,445 times.

There are 2 previous versions of this script.

// ==UserScript==
// @name           4chan instant page loader (3 pages)
// @namespace      haluk
// @description    load first 3 pages
// @include        http://boards.4chan.org/*/
// @include        http://boards.4chan.org/*/*
// @exclude        http://boards.4chan.org/*/res/*
// @version        0.2
// ==/UserScript==

(function () {
    //USER OPTIONS
    var loadCount = 3;
    //loadCount equals the maximum number of pages to load at once.
    //DO NOT TOUCH ANYTHING BELOW THIS LINE
    String.prototype.format = function () {
        var string = this,
            threadsStart = string.indexOf('<span class="filesize">'),
            threadsEnd = string.lastIndexOf("<center><a");
        return string.slice(threadsStart, threadsEnd);
    };
    // NODE FETCHERS
    function singleNode(sXPath) {
        return document.evaluate(sXPath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
    }
    function multiNode(xpath, root) {
        var doc = root ? root.evaluate ? root : root.ownerDocument : document,
            next, got = doc.evaluate(xpath, root || doc, null, null, null),
            result = [];
        while (next = got.iterateNext()) { result.push(next); }
        return result;
    }
    // CONTENT GETTERS
    function getNxtPg(lnkToNxtPg) {
        var req = new XMLHttpRequest();
        req.open("GET", lnkToNxtPg, false);
        req.send(null);
        return req.responseText;
    }
    function loadContent(arrItm) {
        var frag = arrItm.format(),
            range = document.createRange();
        return range.createContextualFragment(frag);
    }
    function loadContentChrome(arrItm) {
        var bin = document.createElement("body"),
            frag = document.createDocumentFragment();
        bin.innerHTML = arrItm.format();
        do { frag.appendChild(bin.firstChild); }
        while (bin.childNodes.length > 0);
        return frag;
    }
    //OTHER
    function throbber(node) {
        var loadGeef = new Image();
        loadGeef.src = "data:image/gif;base64,R0lGODlhHwAfAPUAAP%2F%2F%2FwAzWOjs79La4bzJ0q6%2ByaK0wdzi57jG0JquvOTp7djf5aq6x6CywLC%2Fy8zW3fb3%2BKi5xdTc4ubq7jZeeyZRcFByjMTP2HCMoZKnt1Z3kPr6%2B2iGm0ZqhcbR2fj5%2Bkhshz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KC4ySH3OQEJKYHZWWi5iZG0ecEZ6eHEOio6SfqCaqpaytrpOwJLKztCO2jLi1uoW8Ir6%2FwCHCxMG2x7muysukzb230M6H09bX2Nna29zd3t%2Fg4cAC5OXm5%2Bjn3Ons7eba7vHt2fL16tj2%2BQL0%2BvXw%2Fe7WAUwnrqDBgwgTKlzIsKHDh2gGSBwAccHEixAvaqTYcFCjRoYeNyoM6REhyZIHT4o0qPIjy5YTTcKUmHImx5cwE85cmJPnSYckK66sSAAj0aNIkypdyrSp06dQo0qdSrWq1atYs2rdyrWr169gwxZJAAA7";
        loadGeef.style.cssText = "top:50%; left: 50%; position:fixed;";
        node.appendChild(loadGeef);
    }
    // REV UP THOSE FUNCTIONS
    var bod = document.body,
        currPg = document.forms[1],
        pgFt = singleNode("//form/hr/following-sibling::center"),
        pgLnks = multiNode("//b/following-sibling::a[position()<=" + loadCount + "]"),
        init = function (e) { currPg.insertBefore(loadContent(e), pgFt); },
        initChrome = function (e) { currPg.insertBefore(loadContentChrome(e), pgFt); },
        htmlList = [],
        len = pgLnks.length;
    currPg.style.display = "none";
    throbber(document.body);
    for (var i = len; i--;) { pgLnks[i] = pgLnks[i].pathname; }
    for (var j = len; j--;) { htmlList[htmlList.length] = getNxtPg(pgLnks.shift()); }
    pgLnks = null;
    len = null;
    (Boolean(window.chrome)) ? htmlList.forEach(initChrome) : htmlList.forEach(init);
    htmlList = null;
    throbber = bod.lastChild;
    bod.removeChild(throbber);
    currPg.style.display = "block";
})();