Redirect Images on Archived.moe

Redirect images from archived.moe to warosu.org with dynamic URLs

Від 03.09.2023. Дивіться остання версія.

// ==UserScript==
// @name         Redirect Images on Archived.moe
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Redirect images from archived.moe to warosu.org with dynamic URLs
// @author       Your Name
// @match        https://archived.moe/(3|biz|cgl|ck|diy|fa|ic|lit|sci|vr|vt)/thread/*
// @grant        none
// @license       MIT
// ==/UserScript==

(function() {
    'use strict';

    // Get the current URL
    var currentUrl = window.location.href;

    // Define a regular expression pattern to capture the number sequence
    var regexPattern = /\/(3|biz|cgl|ck|diy|fa|ic|lit|sci|vr|vt)\/thread\/(\d+)/;
    var match = currentUrl.match(regexPattern);

    if (match) {
        // Extract the board name and the number sequence from the URL
        var boardName = match[1];
        var numberSequence = match[2];

        // Pad the number sequence with leading zeros if needed
        while (numberSequence.length < 4) {
            numberSequence = '0' + numberSequence;
        }

        // Find all anchor elements with class 'thread_image_link' and update their href attributes
        var imageLinks = document.querySelectorAll('a.thread_image_link');
        imageLinks.forEach(function(link) {
            var href = link.getAttribute('href');
            // Extract the last part of the href (the filename)
            var filename = href.substring(href.lastIndexOf('/') + 1);

            // Construct the new image URL using both sequences
            var newImageUrl = "https://warosu.org/data/" + boardName + "/img/0" + numberSequence.substr(0, 3) + "/" + numberSequence.substr(3, 2) + "/" + filename;

            // Update the href attribute with the new URL
            link.setAttribute('href', newImageUrl);
        });
    }
})();