Capture and Save Website Source

Capture HTML, CSS, and JS of the page and save it as a file

Verze ze dne 19. 08. 2024. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Capture and Save Website Source
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Capture HTML, CSS, and JS of the page and save it as a file
// @author       You
// @match        *://*/*
// @grant        GM_download
// @grant        GM_info
// @require      https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js
// ==/UserScript==

(function() {
    'use strict';

    // Function to capture and save the website's HTML, CSS, and JS
    function captureAndSave() {
        // Get HTML content
        let htmlContent = document.documentElement.outerHTML;

        // Get CSS content
        let cssContent = '';
        document.querySelectorAll('link[rel="stylesheet"]').forEach(link => {
            fetch(link.href)
                .then(response => response.text())
                .then(css => cssContent += css);
        });

        // Get JavaScript content
        let jsContent = '';
        document.querySelectorAll('script[src]').forEach(script => {
            fetch(script.src)
                .then(response => response.text())
                .then(js => jsContent += js);
        });

        // Wait for all fetch requests to complete
        Promise.all([
            ...Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map(link => fetch(link.href).then(response => response.text())),
            ...Array.from(document.querySelectorAll('script[src]')).map(script => fetch(script.src).then(response => response.text()))
        ]).then(() => {
            // Create a new JSZip instance
            const zip = new JSZip();
            zip.file("index.html", htmlContent);
            zip.file("styles.css", cssContent);
            zip.file("scripts.js", jsContent);

            // Generate the ZIP file and save it
            zip.generateAsync({ type: "blob" })
                .then(content => {
                    saveAs(content, "website-source.zip");
                });
        });
    }

    // Add a button to trigger capture and save
    let button = document.createElement('button');
    button.textContent = 'Save Website Source';
    button.style.position = 'fixed';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = '9999';
    button.style.padding = '10px';
    button.style.backgroundColor = '#007BFF';
    button.style.color = '#FFFFFF';
    button.style.border = 'none';
    button.style.borderRadius = '5px';
    button.style.cursor = 'pointer';
    document.body.appendChild(button);

    button.addEventListener('click', captureAndSave);
})();