4chan Save

Save the 4chan thread

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         4chan Save
// @namespace    http://github.com/hangjeff
// @version      2025-03-27_14h03m
// @description  Save the 4chan thread
// @author       hangjeff
// @match        https://boards.4chan.org/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    document.querySelectorAll('.thread').forEach(thread => {
        let fileThumb = thread.querySelector('.fileThumb');
        if(fileThumb){
            let Komica_File_Url = 'https:' + fileThumb.getAttribute('href');
            let fileText = thread.querySelector('.fileText');

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

    })

   reply_Class_Read();
   document.addEventListener('click', event => {
       if (event.target.matches('.-expand-thread')) {
           setTimeout(() => {
               reply_Class_Read();
               console.log('Done!');
           }, 1000);
       }
   });

   function reply_Class_Read(){
       document.querySelectorAll('.reply').forEach(reply => {
               let fileThumb = reply.querySelector('.fileThumb');
               if (fileThumb && !reply.querySelector('form')) {
                   let Komica_File_Url = 'https:' + fileThumb.getAttribute('href');
                   let fileText = reply.querySelector('.fileText');
                   if (fileThumb.getAttribute('href').includes('.webm') || fileThumb.getAttribute('href').includes('.mp4')) {
                       fileThumb.appendChild(GhostArchive_Create(Komica_File_Url, 'Video'));
                       fileThumb.appendChild(WebArchive_Create(Komica_File_Url, 'Video'));
                   }
                   else{
                       // $(this).find('.fileText').append(WebArchive_Create(Komica_File_Url, 'Image'));
                       fileText.appendChild(ArchiveIs_Create(Komica_File_Url, 'Image'));
                   }
               }
       });
   }
       function WebArchive_Create(myUrl, myTarget){
       let form = document.createElement('form');
        form.setAttribute('name', 'wwmform_save');
        form.setAttribute('action', 'https://web.archive.org/save');
        form.setAttribute('method', 'POST');
        form.setAttribute('target', '_blank');
        form.style.display = 'inline-block';

        let inputUrl = document.createElement('input');
        inputUrl.setAttribute('id', 'url');
        inputUrl.setAttribute('type', 'hidden');
        inputUrl.setAttribute('name', 'url');
        inputUrl.setAttribute('value', myUrl);

        let inputSubmit = document.createElement('input');
        inputSubmit.setAttribute('type', 'submit');
        inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to Web archive');

        form.appendChild(inputUrl);
        form.appendChild(inputSubmit);

        return form;
    }

    function ArchiveIs_Create(myUrl, myTarget){
       let form = document.createElement('form');
       form.setAttribute('id', 'submiturl');
       form.setAttribute('action', 'https://archive.is/submit/');
       form.setAttribute('method', 'GET');
       form.setAttribute('target', '_blank');
       form.style.display = 'inline-block';

        let inputUrl = document.createElement('input');
        inputUrl.setAttribute('id', 'url');
        inputUrl.setAttribute('type', 'hidden');
        inputUrl.setAttribute('name', 'url');
        inputUrl.setAttribute('value', myUrl);

        let inputSubmit = document.createElement('input');
        inputSubmit.setAttribute('type', 'submit');
        inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to archive.is');
        inputSubmit.setAttribute('tabindex', '1');

        form.appendChild(inputUrl);
        form.appendChild(inputSubmit);
        return form;
    }

    function GhostArchive_Create(myUrl, myTarget){
      let form = document.createElement('form');
        form.setAttribute('id', 'submiturl');
        form.setAttribute('action', 'https://ghostarchive.org/archive2');
        form.setAttribute('method', 'POST');
        form.setAttribute('target', '_blank');
        form.style.display = 'inline-block';

      let inputUrl = document.createElement('input');
        inputUrl.setAttribute('id', 'url');
        inputUrl.setAttribute('type', 'hidden');
        inputUrl.setAttribute('name', 'archive');
        inputUrl.setAttribute('value', myUrl);

      let inputSubmit = document.createElement('input');
        inputSubmit.setAttribute('type', 'submit');
        inputSubmit.setAttribute('value', 'Save ' + myTarget + ' to ghostarchive.org');
        inputSubmit.setAttribute('tabindex', '1');

      form.appendChild(inputUrl);
      form.appendChild(inputSubmit);
      return form;
    }

})();