拷貝漫畫視覺化(章節)

依序開啟未訪問的連結,完成後返回目錄頁

// ==UserScript==
// @name         拷貝漫畫視覺化(章節)
// @namespace    http://tampermonkey.net/
// @version      10.22
// @description  依序開啟未訪問的連結,完成後返回目錄頁
// @match        https://mangacopy.com/comic/*/chapter/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const listPrefix = 'unvisitedLinks_';

    // 顯示狀態訊息
    function showStatus(message) {
        let statusBar = document.getElementById('status-bar');
        if (!statusBar) {
            statusBar = document.createElement('div');
            statusBar.id = 'status-bar';
            statusBar.style.position = 'fixed';
            statusBar.style.top = '10px';
            statusBar.style.left = '10px';
            statusBar.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
            statusBar.style.color = 'white';
            statusBar.style.padding = '10px';
            statusBar.style.borderRadius = '5px';
            statusBar.style.zIndex = '9999';
            document.body.appendChild(statusBar);
        }
        statusBar.textContent = message;
    }

    // 獲取當前網址對應的未訪問連結列表
    function getUnvisitedLinks() {
        const listKey = listPrefix + window.location.href.replace(/\/chapter\/.*/, '');
        const unvisitedLinks = JSON.parse(localStorage.getItem(listKey) || '[]');
        return unvisitedLinks;
    }

    // 開啟下一個未訪問的連結
    function openNextLink(unvisitedLinks) {
        if (unvisitedLinks.length > 0) {
            const nextLink = unvisitedLinks.shift();
            const listKey = listPrefix + window.location.href.replace(/\/chapter\/.*/, '');
            localStorage.setItem(listKey, JSON.stringify(unvisitedLinks));

            if (unvisitedLinks.length === 0) {
                const parentUrl = window.location.href.replace(/\/chapter\/.*/, '');
                showStatus('所有連結已處理完畢,返回目錄頁。');
                setTimeout(() => {
                    window.location.href = parentUrl;
                }, 1000);
            } else {
                showStatus('正在開啟下一個連結...');
                setTimeout(() => {
                    window.location.href = nextLink;
                }, 1000);
            }
        }
    }

    // 新增:清除按鈕
    function addClearButton() {
        const clearButton = document.createElement('button');
        clearButton.textContent = '清除';
        clearButton.style.position = 'fixed';
        clearButton.style.top = '60px';
        clearButton.style.left = '10px';
        clearButton.style.zIndex = '9999';
        clearButton.style.padding = '5px 10px';
        clearButton.style.backgroundColor = '#ffaa44';
        clearButton.style.color = 'white';
        clearButton.style.border = 'none';
        clearButton.style.borderRadius = '5px';
        clearButton.style.cursor = 'pointer';

        clearButton.addEventListener('click', () => {
            const listKey = listPrefix + window.location.href.replace(/\/chapter\/.*/, '');
            const queue = JSON.parse(localStorage.getItem('processingQueue') || '[]');

            localStorage.removeItem(listKey);
            const updatedQueue = queue.filter(item => item !== listKey);
            localStorage.setItem('processingQueue', JSON.stringify(updatedQueue));
            showStatus('已清除當前清單!');
        });

        document.body.appendChild(clearButton);
    }

    // 主邏輯
    function runScript() {
        const unvisitedLinks = getUnvisitedLinks();
        if (unvisitedLinks.length > 0) {
            openNextLink(unvisitedLinks);
        } else {
            const parentUrl = window.location.href.replace(/\/chapter\/.*/, '');
            showStatus('沒有未訪問的連結,返回目錄頁。');
            setTimeout(() => {
                window.location.href = parentUrl;
            }, 1000);
        }
        addClearButton(); // 添加清除按鈕
    }

    // 延遲執行以避免頁面未完全加載
    setTimeout(runScript, 1000);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址