Scribd Enhancer All-in-One (v2.0)

Unblur Scribd content, auto scrape visible pages, and print/save as PDF. Always show UI. Includes dark mode and persistent settings. Works on all /document/ and /read/ URLs. Built by Eliminater74.

目前為 2025-06-03 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Scribd Enhancer All-in-One (v2.0)
// @namespace    https://greasyfork.org/users/Eliminater74
// @version      2.0
// @description  Unblur Scribd content, auto scrape visible pages, and print/save as PDF. Always show UI. Includes dark mode and persistent settings. Works on all /document/ and /read/ URLs. Built by Eliminater74.
// @author       Eliminater74
// @license      MIT
// @match        *://*.scribd.com/*
// @icon         https://s-f.scribdassets.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const LS_KEY = 'scribdEnhancerSettings';
    const defaultSettings = {
        unblur: true,
        printableView: true,
        autoScrape: true,
        darkMode: false,
        debug: false
    };

    const settings = JSON.parse(localStorage.getItem(LS_KEY)) || defaultSettings;
    const saveSettings = () => localStorage.setItem(LS_KEY, JSON.stringify(settings));

    // -------- UI Styles --------
    const style = document.createElement('style');
    style.textContent = `
        #se-floating-gear {
            position: fixed; bottom: 20px; right: 20px; z-index: 9999;
            width: 40px; height: 40px; border-radius: 50%; background: #333;
            color: white; font-size: 24px; text-align: center; line-height: 40px;
            cursor: pointer; box-shadow: 0 0 6px rgba(0,0,0,0.4);
        }
        #se-menu {
            position: fixed; bottom: 70px; right: 20px; z-index: 9999;
            background: #fff; border: 1px solid #ccc; padding: 10px; border-radius: 10px;
            display: none; font-family: sans-serif; box-shadow: 0 0 10px rgba(0,0,0,0.3);
        }
        #se-menu label {
            display: block; margin: 5px 0; color: #000; font-size: 14px;
        }
        div[style*="rgb(244, 221, 221)"],
        div[style*="#f4dddd"],
        div[style*="rgb(255, 244, 211)"],
        div[style*="#fff4d3"] {
            display: none !important;
        }
        body.dark-mode, html.dark-mode {
            background: #121212 !important;
            color: #e0e0e0 !important;
        }
        .dark-mode * {
            background: transparent !important;
            color: #e0e0e0 !important;
            border-color: #444 !important;
        }
        .dark-mode a { color: #66c0ff !important; }
        .dark-mode .promo_div, .dark-mode .blurred_page {
            display: none !important;
        }
    `;
    document.head.appendChild(style);

    // -------- Floating Gear UI --------
    const gear = document.createElement('div');
    gear.id = 'se-floating-gear';
    gear.textContent = '⚙';
    document.body.appendChild(gear);

    const menu = document.createElement('div');
    menu.id = 'se-menu';
    menu.innerHTML = Object.keys(settings).map(key => {
        const checked = settings[key] ? 'checked' : '';
        const label = key.replace(/([A-Z])/g, ' $1').replace(/^./, s => s.toUpperCase());
        return `<label><input type="checkbox" data-key="${key}" ${checked}> ${label}</label>`;
    }).join('');
    document.body.appendChild(menu);

    gear.addEventListener('click', () => {
        menu.style.display = menu.style.display === 'none' ? 'block' : 'none';
    });

    menu.addEventListener('change', e => {
        const key = e.target.dataset.key;
        settings[key] = e.target.checked;
        saveSettings();
        applyDarkMode();
        location.reload();
    });

    function applyDarkMode() {
        if (settings.darkMode) {
            document.documentElement.classList.add('dark-mode');
            document.body.classList.add('dark-mode');
        } else {
            document.documentElement.classList.remove('dark-mode');
            document.body.classList.remove('dark-mode');
        }
    }

    // -------- Feature Functions --------

    function unblurContent() {
        if (!settings.unblur) return;
        const clean = () => {
            document.querySelectorAll('.blurred_page, .promo_div').forEach(el => el.remove());
            document.querySelectorAll('[unselectable="on"]').forEach(el => el.removeAttribute('unselectable'));
            document.querySelectorAll('*').forEach(el => {
                const cs = getComputedStyle(el);
                if (cs.color === 'transparent') el.style.color = '#111';
                if (cs.textShadow && cs.textShadow.includes('white')) el.style.textShadow = 'none';
                el.removeAttribute('data-initial-color');
                el.removeAttribute('data-initial-text-shadow');
            });
        };
        clean();
        const observer = new MutationObserver(clean);
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function enablePrintableView() {
        if (!settings.printableView) return;
        document.querySelectorAll('script').forEach(script => {
            const idMatch = /"id":(\d{6,})/.exec(script.textContent);
            const keyMatch = /"access_key":"(key[-\w\d]*)"/.exec(script.textContent);
            if (idMatch && keyMatch) {
                const swfUrl = `http://d1.scribdassets.com/ScribdViewer.swf?document_id=${idMatch[1]}&access_key=${keyMatch[1]}`;
                document.querySelectorAll('div').forEach(div => {
                    div.innerHTML = div.innerHTML.replace(/https?:\/\/www\.scribd\.com\/upload-document/gi, swfUrl);
                });
            }
        });
    }

    function injectScrapeUI() {
        const container = document.createElement('div');
        container.id = 'scraped-book';
        container.style = 'display:none;';
        document.body.appendChild(container);

        const scrapeBtn = document.createElement('button');
        scrapeBtn.textContent = '📖 Start Scraping Book';
        scrapeBtn.style = 'position:fixed;top:50px;left:10px;z-index:9999;padding:10px;background:#2196F3;color:#fff;border:none;border-radius:5px;';
        scrapeBtn.onclick = () => scrapePages(container);
        document.body.appendChild(scrapeBtn);

        const printBtn = document.createElement('button');
        printBtn.textContent = '🖨️ Print to PDF';
        printBtn.style = 'position:fixed;top:90px;left:10px;z-index:9999;padding:10px;background:#4CAF50;color:#fff;border:none;border-radius:5px;';
        printBtn.onclick = () => {
            const win = window.open('', 'PrintBook');
            win.document.write(`<html><head><title>Book</title></head><body>${container.innerHTML}</body></html>`);
            win.document.close();
            win.focus();
            setTimeout(() => win.print(), 600);
        };
        document.body.appendChild(printBtn);
    }

    function scrapePages(container) {
        window.scrollTo(0, 0); // Ensure visibility for lazy-loaded elements
        const pages = document.querySelectorAll('.text_layer, .page, .reader_column, [id^="page_container"]');
        let count = 0;

        pages.forEach(page => {
            const clone = page.cloneNode(true);
            clone.style.marginBottom = '30px';
            container.appendChild(clone);
            count++;
        });

        if (count > 0) {
            alert(`✅ Scraped ${count} page elements. Ready to Print.`);
        } else {
            alert(`❌ No readable page content found. Try scrolling through the book or toggling debug mode.`);
        }
    }

    // -------- Init --------
    window.addEventListener('load', () => {
        applyDarkMode();
        unblurContent();
        enablePrintableView();
        if (settings.autoScrape) injectScrapeUI();
    });
})();