Scribd Enhancer All-in-One

Bypass blur, enable downloads, print books, auto scrape pages, hide subscription banners (pink/beige), and toggle full dark mode. Floating gear icon with UI toggles and saved settings. Built by Eliminater74.

当前为 2025-06-01 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Scribd Enhancer All-in-One
// @namespace    https://greasyfork.org/users/Eliminater74
// @version      1.5
// @description  Bypass blur, enable downloads, print books, auto scrape pages, hide subscription banners (pink/beige), and toggle full dark mode. Floating gear icon with UI toggles and saved settings. 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,
        enableDownload: true,
        printableView: true,
        autoScrape: true,
        darkMode: false,
        debug: false
    };

    const settings = loadSettings();

    function loadSettings() {
        const saved = localStorage.getItem(LS_KEY);
        return saved ? JSON.parse(saved) : { ...defaultSettings };
    }

    function saveSettings() {
        localStorage.setItem(LS_KEY, JSON.stringify(settings));
    }

    // -------- UI + Global 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;
        }

        /* ✅ Remove banners: pink and beige */
        div[style*="rgb(244, 221, 221)"],
        div[style*="#f4dddd"],
        div[style*="rgb(255, 244, 211)"],
        div[style*="#fff4d3"] {
            display: none !important;
        }

        /* ✅ Dark Mode */
        body.dark-mode,
        html.dark-mode {
            background: #121212 !important;
            color: #e0e0e0 !important;
        }
        .dark-mode div,
        .dark-mode section,
        .dark-mode header,
        .dark-mode aside,
        .dark-mode article,
        .dark-mode span {
            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);

    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');
        }
    }

    // -------- Features --------
    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 color = getComputedStyle(el).color;
                if (color === 'transparent') el.style.color = '#111';
                const ts = getComputedStyle(el).textShadow;
                if (ts && ts !== 'none' && ts.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 enablePDFDownload() {
        if (!settings.enableDownload) return;
        const match = window.location.href.match(/\/document\/(\d+)/);
        if (!match) return;
        const docId = match[1];
        const pdfUrl = `https://www.scribd.com/document_downloads/${docId}?extension=pdf`;
        const btn = document.createElement('a');
        btn.href = pdfUrl;
        btn.download = 'ScribdDocument.pdf';
        btn.textContent = '📄 Download PDF';
        btn.style = 'position:fixed;top:10px;left:10px;background:#4caf50;color:#fff;padding:10px;z-index:9999;text-decoration:none;border-radius:5px;';
        document.body.appendChild(btn);
    }

    function enablePrintableView() {
        if (!settings.printableView) return;
        let new_link;
        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) {
                new_link = `http://d1.scribdassets.com/ScribdViewer.swf?document_id=${idMatch[1]}&access_key=${keyMatch[1]}`;
            }
        });
        if (new_link) {
            document.querySelectorAll('div').forEach(div => {
                div.innerHTML = div.innerHTML.replace(/https?:\/\/www\.scribd\.com\/upload-document/gi, new_link);
            });
        }
    }

    function autoScrapeBook() {
        if (!settings.autoScrape || !/read/.test(location.href)) return;
        const tryLater = () => {
            if (!document.querySelector('.reader_column')) {
                if (settings.debug) console.log('[Scribd Enhancer] Waiting for reader...');
                return setTimeout(tryLater, 1000);
            }
            const bookContainer = document.createElement('div');
            bookContainer.id = 'scraped-book';
            bookContainer.style = 'display:none;';
            document.body.appendChild(bookContainer);

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

            const printBtn = document.createElement('button');
            printBtn.textContent = '🖨️ Print Book';
            printBtn.style = 'position:fixed;top:90px;left:10px;z-index:9999;padding:10px;background:#673ab7;color:#fff;border:none;border-radius:5px;';
            printBtn.onclick = () => {
                const win = window.open('', 'PrintBook');
                win.document.write('<html><head><title>Book</title></head><body>' + bookContainer.innerHTML + '</body></html>');
            };
            document.body.appendChild(printBtn);
        };
        tryLater();
    }

    function scrapePages(container) {
        let pagesScraped = 0;
        const nextBtn = document.querySelector('.page_right.next_btn');
        const interval = setInterval(() => {
            const left = document.querySelector('.reader_column.left_column');
            const right = document.querySelector('.reader_column.right_column');
            if (left) container.appendChild(left.cloneNode(true));
            if (right) container.appendChild(right.cloneNode(true));
            if (nextBtn) nextBtn.click();
            pagesScraped++;
            if (settings.debug) console.log(`Scraped ${pagesScraped} pages...`);
            const counter = document.querySelector('.page_counter');
            if (counter && /(\d+)\s+of\s+(\d+)/i.test(counter.innerText)) {
                const [ , current, total ] = counter.innerText.match(/(\d+)\s+of\s+(\d+)/);
                if (parseInt(current) >= parseInt(total)) {
                    clearInterval(interval);
                    alert("📘 Scraping complete!");
                }
            }
        }, 2000);
    }

    window.addEventListener('load', () => {
        if (settings.debug) console.log('[Scribd Enhancer] Active Settings:', settings);
        applyDarkMode();
        unblurContent();
        enablePDFDownload();
        enablePrintableView();
        autoScrapeBook();
    });

})();