Bookmarklet: Load all forum pages from long threads

Martin Larsen

Active Member
Licensed User
Longtime User
As described in my wish it is difficult to find specific information inside very long threads such as the thread about Firebase push notifications which is 18 pages long!

Now I have done something about it in the form of a little nice bookmarklet!



Simply create a bookmark on your bookmark bar with this content:
JavaScript:
javascript:var url = location.href.replace(/page-\d+.*/,""); var className = ".b-body.js-replyNewMessageContainer:first"; var numPages = +$("li.pageNav-page:last").text()||1; var currentPage = +$(".pageNav-page--current:first").text()||1; (async function () { if(currentPage==numPages) return; for(i=currentPage+1; i<=numPages; i++) { if(i==currentPage+1) $("div.p-body-inner").prepend(`<h1 id="pageloader" style="text-align: center;background: #edf6fd;color: #2577b1;padding: 40px 0;border: 2px solid #d0e5f3;position: fixed;width: 30%;z-index: 9999;top: 40%;left: 35%;">Loading page ${i}</h1>`); else $("#pageloader").text(`Loading page ${i}`); let resp = await fetch(`${url}page-${i}`); let html = await resp.text(); $(className).append($(html).find(className)); } $("#pageloader").text("All pages loaded!").fadeOut(2500); $(".pageNav-main:first .pageNav-page--current:first").nextAll(".pageNav-page").hide(); $(".pageNav-main:last .pageNav-page--current:first").nextAll(".pageNav-page").hide(); $(".pageNav-jump--next").hide(); })();

You can call it "B4X Load all pages" or whatever. Then, whenever you encounter a long thread, simply click on the bookmarklet to load all the pages from the current page and onward. Then you can use Ctrl-F to find whatever you are looking for.

Note: Normally, it is possible to create the bookmarklet directly in HTML so that you can simply drag it to the bookmark line. But that is not possible in this forum because it tries to make a normal http url out of it.

For your convenience, I have created the bookmarklet here: http://marlar.dk/b4x/bookmarklet.html

Simply drag the bookmarklet to your bookmark line and try it out on for example the push notification thread.

This is the same code non-minified:
Load all pages:
var url = location.href.replace(/page-\d+.*/,"");
var className = ".b-body.js-replyNewMessageContainer:first";
var numPages = +$("li.pageNav-page:last").text()||1;
var currentPage = +$(".pageNav-page--current:first").text()||1;
(async function () {
    if(currentPage==numPages) return;
    for(i=currentPage+1; i<=numPages; i++) {
        if(i==currentPage+1)
            $("div.p-body-inner").prepend(`<h1 id='pageloader' style='text-align: center;background: #edf6fd;color: #2577b1;padding: 40px 0;border: 2px solid #d0e5f3;position: fixed;width: 30%;z-index: 9999;top: 40%;left: 35%;'>Loading page ${i}</h1>`);
        else
            $("#pageloader").text(`Loading page ${i}`);
        let resp = await fetch(`${url}page-${i}`);
        let html = await resp.text();
        $(className).append($(html).find(className));
    }
    $("#pageloader").text("All pages loaded!").fadeOut(2500);
    $(".pageNav-main:first .pageNav-page--current:first").nextAll(".pageNav-page").hide();
    $(".pageNav-main:last .pageNav-page--current:first").nextAll(".pageNav-page").hide();
    $(".pageNav-jump--next").hide();
})();

Tested in Chrome and Firefox.
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Great trick !!

A little incovenience though; doing this, the Post number on several pages is Lost (and frequently, there's a link in the Thread to a especific Post number); sure can be possible to modify de javascript code to mantain the Post number but I've no knowledge in Javascript to modify it
Edit: Seems to work fine now
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hello, I think there is a bug in the bookmarklet.

I tried it again with the Firebase Notifications again and I realized after it says done loading all pages, when you scroll, you wont see all pages, After the 20th thread is displayed, it then looped and start displaying the 1st to 20th thread again, and it continues looping

 

Martin Larsen

Active Member
Licensed User
Longtime User

Thanks for letting me know. I will take a look at it.

please make sure not to cause unintended DOS attacks with these plugins. It is not good to load 20 pages at once.

They are actually not loaded at once but sequentially. I could however insert at small break between page load. Would that help?

Also note that this bookmarklet will probably only be used a few times each day.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…