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.

От 03.06.2025. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

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

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като 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();
    });
})();