Tampermonkey script to fix borked comment links on stories

I wrote a script to fix the busted comment links on stories (where clicking the link takes you back to the story instead of the BBS).

I’m sure there’s a better way to do this, but it works for me.

You will need to install the Tampermonkey browser extension. Get that here: https://www.tampermonkey.net/

When that’s installed, open the settings for it and create a new script. Paste this in:

// ==UserScript==
// @name         boingboing bbs link fixer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Fix boingboing bbs links
// @author       Me
// @match        https://boingboing.net/*
// @grant        none
// ==/UserScript==

var links;
var link;
var linkUrl;
var newUrl;
var pos;

links = document.evaluate(
    "//a[@class='bbs']",
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);


for(var j=0; j<links.snapshotLength; j++)
{
	link = links.snapshotItem(j);
//    console.log ("link ", link);
    linkUrl = link.href;
//    console.log ("URL ", linkUrl);
    if (linkUrl.indexOf("//bbs.") < 0) // Is this a bbs link?
    {
        // https://boingboing.net/2023/05/01/suspect-who-killed-5-people-in-texas-mass-shooting-has-vanished-with-zero-leads.html
        // not a bbs link, fix it.
        newUrl = "https://bbs.boingboing.net/t/";
        // point to domain.
        pos = linkUrl.indexOf("boingboing.net/");
        if (pos < 0) {
          continue;
        }
        // skip past it.
        pos += 15;
        // skip past three /s
        pos = linkUrl.indexOf("/", pos);
        if (pos < 0) {
            continue;
        }
        pos++;
        pos = linkUrl.indexOf("/", pos);
        if (pos < 0) {
            continue;
        }
        pos++;
        pos = linkUrl.indexOf("/", pos);
        if (pos < 0) {
            continue;
        }
        pos++;
        // should now be pointing past the date.
        newUrl = newUrl + linkUrl.substring(pos);
        if (newUrl.endsWith(".html"))
        {
            // strip .html off the end
            newUrl = newUrl.substring(0, newUrl.length-5);
        }
        console.log ("new URL ", newUrl);
        link.href = newUrl;
    }
}

3 Likes

No more CCBOD? The circular comment button of doom?

1 Like

And once you have access to my cameras, Alexa, and my toaster, what are your plans for that data?

3 Likes

I’m going to feed it into ChatGPT.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.