Redirect Images on Archived.moe

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Redirect Images on Archived.moe
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Redirect images from archived.moe to warosu.org with dynamic URLs
// @author       Anon
// @license      MIT
// @icon         https://s.4cdn.org/image/favicon-ws.ico
// @match      https://archived.moe/3/thread/*
// @match      https://archived.moe/biz/thread/*
// @match      https://archived.moe/cgl/thread/*
// @match      https://archived.moe/ck/thread/*
// @match      https://archived.moe/diy/thread/*
// @match      https://archived.moe/fa/thread/*
// @match      https://archived.moe/ic/thread/*
// @match      https://archived.moe/lit/thread/*
// @match      https://archived.moe/sci/thread/*
// @match      https://archived.moe/vr/thread/*
// @match      https://archived.moe/vt/thread/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

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

    // Define a regular expression pattern to capture the board name and 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 rawNumberSequence = match[2];

        // Ensure that numberSequence is at least 8 digits long by adding leading zeros
        var numberSequence = rawNumberSequence.padStart(8, '0');

        // Add an additional leading '0' to make for warosu's image link structure
        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/" + numberSequence.substr(0, 4) + "/" + numberSequence.substr(4, 2) + "/" + filename;

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