Greasy Fork

来自缓存

Greasy Fork is available in English.

Save Comic as HTML

Download comic images as HTML

当前为 2023-08-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Save Comic as HTML
// @version      0.2
// @description  Download comic images as HTML
// @author       Bambi
// @match        https://readcomiconline.li/Comic/*
// @grant        none
// @license      MIT
// @namespace    http://greasyfork.icu/users/1089343
// ==/UserScript==

(function() {
    'use strict';

    // Obtain the list of loaded image URLs from the window or create an empty array
    const lstImagesLoaded = window.lstImagesLoaded || [];

    // Function to download the HTML viewer
    function downloadViewerHtml() {
        const urlParts = window.location.href.split('/');
        const comicName = urlParts[urlParts.length - 2];
        const issueName = urlParts[urlParts.length - 1].split('?')[0];
        const filename = `${comicName}${issueName}.html`;

        // Construct the HTML content dynamically
        const jsonContent = JSON.stringify(lstImagesLoaded);
        const htmlContent = `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Image Viewer</title>
            </head>
            <body>
                <h1>Image Viewer</h1>
                <div id="imageContainer"></div>
                <script>
                    const lstImagesLoaded = ${jsonContent};
                    const imageContainer = document.getElementById('imageContainer');

                    lstImagesLoaded.forEach(imageLink => {
                        const imgElement = document.createElement('img');
                        imgElement.src = imageLink;
                        imgElement.style.width = '50%';
                        imgElement.style.height = 'auto';
                        imgElement.style.marginLeft = '170px';
                        imageContainer.appendChild(imgElement);
                        imageContainer.appendChild(document.createElement('br'));
                    });
                </script>
            </body>
            </html>
        `;

        // Create a Blob with the HTML content
        const htmlBlob = new Blob([htmlContent], { type: 'text/html' });

        // Create a download link
        const downloadLink = document.createElement('a');
        downloadLink.href = URL.createObjectURL(htmlBlob);
        downloadLink.download = filename;
        downloadLink.textContent = 'Download Viewer';

        // Trigger the download
        downloadLink.click();
    }

    // Create a button to initiate the download
    const downloadButton = document.createElement('button');
    downloadButton.textContent = 'Download HTML(d)';
    downloadButton.style.position = 'fixed';
    downloadButton.style.top = '150px';
    downloadButton.style.left = '10px';
    downloadButton.style.zIndex = '9999';
    downloadButton.addEventListener('click', downloadViewerHtml);
    document.body.appendChild(downloadButton);

    // Add a keydown event listener for the "d" key
    document.addEventListener('keydown', event => {
        if (event.key === 'd') {
            downloadViewerHtml();
        }
    });

    // Create and update the images loaded counter
    const counterElement = document.createElement('div');
    counterElement.id = 'imagesLoadedCounter';
    counterElement.style.position = 'fixed';
    counterElement.style.top = '110px';
    counterElement.style.left = '10px';
    counterElement.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    counterElement.style.color = 'white';
    counterElement.style.padding = '5px';
    counterElement.style.borderRadius = '5px';
    counterElement.style.zIndex = '99999';
    counterElement.textContent = 'Images Loaded: 0';
    document.body.appendChild(counterElement);

    // Update the counter initially
    function updateCounter() {
        counterElement.textContent = `Images Loaded: ${lstImagesLoaded.length}`;
    }

    // Update the counter periodically
    setInterval(updateCounter, 1000);
})();