4chan Save

Save the 4chan thread

当前为 2025-03-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         4chan Save
// @namespace    http://github.com/hangjeff
// @version      2025-03-07_15h47m
// @description  Save the 4chan thread
// @author       hangjeff
// @match        https://boards.4chan.org/*
// @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, 'Thread'));
        $(this).find('.postInfo').first().after(GhostArchive_Create(Komica_Thread_Url, 'Thread'));

        if($(this).find('.fileThumb').length){
            let Komica_File_Url = 'https:' + $(this).find('.fileThumb').attr('href');

            if($(this).find('.fileThumb').attr('href').includes('.webm') || $(this).find('.fileThumb').attr('href').includes('.mp4')){
                $(this).find('.fileText').first().append(WebArchive_Create(Komica_File_Url, 'Video'));
            }
            else{
                // $(this).find('.fileText').first().append(WebArchive_Create(Komica_File_Url, 'Image'));
                $(this).find('.fileText').first().append(ArchiveIs_Create(Komica_File_Url, 'Image'));
            }
        }

    })

   reply_Class_Read();
   $(document).ready(function() {
       $(document).on('click', '.-expand-thread', function() {
           setTimeout(function(){
               reply_Class_Read();
               console.log('Done!');
           }, 1000);
       });
   });

   function reply_Class_Read(){
       $('.reply').each(function(){
           if($(this).find('.fileThumb').length){
               if(!$(this).find('form').length){
                   let Komica_File_Url = 'https:' + $(this).find('.fileThumb').attr('href');
                   if($(this).find('.fileThumb').attr('href').includes('.webm') || $(this).find('.fileThumb').attr('href').includes('.mp4')){
                       $(this).find('.fileThumb').append(WebArchive_Create(Komica_File_Url, 'Video'));
                   }
                   else{
                       // $(this).find('.fileText').append(WebArchive_Create(Komica_File_Url, 'Image'));
                       $(this).find('.fileText').append(ArchiveIs_Create(Komica_File_Url, 'Image'));
                   }
               }
           }
       })
   }
   
    function WebArchive_Create(myUrl, myTarget){
       let form = $('<form>', {
        name: 'wwmform_save',
        action: 'https://web.archive.org/save',
        method: 'POST',
                    target: '_blank'
    }).css('display', 'inline-block');

        form.append(
        $('<input>', {
                id: 'url',
                type: 'hidden',
                name: 'url',
                value: myUrl
            })
    );

        form.append(
        $('<input>', {
                type: 'submit',
                value: 'Save ' + myTarget + ' to Web archive',
            })
    );
        return form;
    }

    function ArchiveIs_Create(myUrl, myTarget){
       let form = $('<form>', {
        id: 'submiturl',
        action: 'https://archive.ph/submit/',
        method: 'GET',
                    target: '_blank'
    }).css('display', 'inline-block');

        form.append(
        $('<input>', {
                id: 'url',
                type: 'hidden',
                name: 'url',
                value: myUrl
            })
    );

        form.append(
        $('<input>', {
                type: 'submit',
                value: 'Save ' + myTarget + ' to archive.is',
                tabindex: '1'
            })
    );
        return form;
    }

    function GhostArchive_Create(myUrl, myTarget){
      let form = $('<form>', {
        id: 'submiturl',
        action: 'https://ghostarchive.org/archive2',
        method: 'POST',
                    target: '_blank'
    }).css('display', 'inline-block');

      form.append(
        $('<input>', {
                id: 'url',
                type: 'hidden',
                name: 'archive',
                value: myUrl
            })
    );

      form.append(
        $('<input>', {
                type: 'submit',
                value: 'Save ' + myTarget + ' to ghostarchive.org',
                tabindex: '1'
            })
    );

      return form;
    }

})();