[ prog / sol / mona ]

prog


Turn a textboard into an imageboard

1 2020-05-23 22:55

Raw text without reaction images is sad so here's an add-on to display linked images with Tampermonkey.

// ==UserScript==
// @name          Fetch images from url
// @namespace     http://textboard.org
// @description   Replaces links to images with the actual image
// @include       *
// ==/UserScript==
(function() {
    function getXPath(p, context) {
        var arr = new Array();
        var xpr = document.evaluate(p,context,null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
        var item;
        for(var i = 0;item = xpr.snapshotItem(i); i++) {
            arr.push(item);
        }
        return arr;
    }
    var doc = window.document;
    var xpath = "//A[(contains(@href, '.jpg') or contains(@href, '.jpeg') or contains(@href, '.gif') or contains(@href, '.png'))]";
    var results = getXPath(xpath, doc);
    for(var i = 0; i < results.length; i++) {
        var img = document.createElement("img");
        var source = results[i].getAttribute("href");
        img.setAttribute("src", source);
        results[i].textContent = "";
        results[i].appendChild(img);
    }
}
)();

Test:

https://kaiyodo.co.jp/danboard/img/yr007/01.png

It could be improved to position the image on the top left corner, generate clickable thumbnails and display multiple images the way 2ch.hk does it.

6 2020-05-24 09:28

It would be better to extend the SchemeBBS markup to support images. Maybe something like sent's syntax

@https://domain.tld/path/to/image.png

?

11


VIP:

do not edit these