[ 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.

2 2020-05-23 22:59

https://pics.me.me/thumb_ai-23-yoba-png-cliparts-for-free-download-uihere-51537963.png

3 2020-05-23 23:01

http://vignette.wikia.nocookie.net/azumanga/images/9/92/Yotsuba.%21.full.48845.jpg

4 2020-05-23 23:09

It doesn't work with https links.

5 2020-05-24 07:28 *

>>1
That's hotlinking.

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

?

7 2020-05-26 23:25 *

>>1,6
I'm not fond of the idea of adding images. Hotlinking is not cool and at worst with text, if you live the thing running you may get hate speech. CP is in a whole different league.

8 2020-05-28 10:30

>>1
I may had your userscript anyway if you'd just fix the https links and limit image sizes to something sensible. Maybe throw some CSS in there. Userscripts are good, that's the way users should improve their browsing experience. Thanks for caring to write it.

9 2020-05-28 10:30

add*

10 2020-05-28 15:41

+1

11


VIP:

do not edit these