4chan Save

Save the 4chan thread

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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;
    }

})();