To Archived.moe

To https://Archived.moe

// ==UserScript==
// @name         To Archived.moe
// @namespace    http://github.com/hangjeff
// @version      2025-03-07_17h14m
// @description  To https://Archived.moe
// @author       hangjeff
// @match        https://boards.4chan.org/*
// @exclude      https://boards.4chan.org/search*
// @require      https://code.jquery.com/jquery-3.7.1.slim.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    $('.thread').each(function(){
        let Komica_Thread_Url = window.location.href;
        if(!Komica_Thread_Url.includes('thread')){
            Komica_Thread_Url = Komica_Thread_Url.substring(0, Komica_Thread_Url.lastIndexOf('/') + 1);
            if(!($(this).find('.postContainer').find('.replylink').first().attr('href') === undefined)  ){
               Komica_Thread_Url = Komica_Thread_Url + $(this).find('.postContainer').find('.replylink').first().attr('href');
                //alert(Komica_Thread_Url);
            }
            else{
                // Komica_Thread_Url = Komica_Thread_Url + $(this).find('.threadpost').find('.category a:last').attr('href');
                console.log('404 Thread Not Found!');
            }
        }
        // alert( Komica_Thread_Url);
        $(this).find('.postInfo').first().after(ArchiveIs_Create(Komica_Thread_Url, 'Archived.moe'));

    })

    function ArchiveIs_Create(myUrl, myTarget){
       let btn = $('<button>', {
           text: 'Redirect to ' + myTarget,
           tabindex: '1',
           click: function(event){
               event.preventDefault();
               window.open(myUrl.replace("https://boards.4chan.org/", "https://archived.moe/"), '_blank');
               return false;
           }
       }).css({'display': 'inline-block', 'background-color': 'green'});
       return btn;
    }

})();