Scribd Download Button

Add a download button on Scribd pages to redirect to a custom download service in the same tab, supporting document, doc, and presentation URLs.

当前为 2025-03-27 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Scribd Download Button
// @namespace    http://tampermonkey.net/
// @version      1.6
// @description  Add a download button on Scribd pages to redirect to a custom download service in the same tab, supporting document, doc, and presentation URLs.
// @author       Mayclin.IT
// @match        https://www.scribd.com/document/*
// @match        https://www.scribd.com/doc/*
// @match        https://www.scribd.com/presentation/*
// @icon         https://www.google.com/s2/favicons?domain=scribd.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log("📌 Tampermonkey script is running...");

    // Extract version number from metadata
    const scriptVersion = GM_info.script.version;
    console.log("📌 Script Version:", scriptVersion);

    // Get the current URL
    const currentUrl = window.location.href;

    // Regular expression to match URL format correctly
    const urlMatch = currentUrl.match(/https:\/\/www\.scribd\.com\/(?:document|doc|presentation)\/(\d+)\/(.+)/);

    if (urlMatch) {
        // Extract the document ID and title
        const docId = urlMatch[1]; // Document ID
        let docTitle = urlMatch[2]; // Document title

        // Debugging
        console.log("📌 Extracted docId:", docId);
        console.log("📌 Extracted raw docTitle:", docTitle);

        // Fix docTitle: Replace `/` with `-` and encode special characters
        docTitle = docTitle.replace(/\//g, '-'); // Replace slashes with dashes
        docTitle = encodeURIComponent(docTitle); // Encode special characters

        // Construct the new download URL with "/document/" path
        const downloadUrl = `https://scribd.downloader.tips/document/${docId}/${docTitle}`;
        console.log("📌 Final download URL:", downloadUrl);

        // Create a download button
        const button = document.createElement('button');
        button.textContent = `Download v${scriptVersion}`;
        button.style.position = 'fixed';
        button.style.top = '10px';
        button.style.right = '10px';
        button.style.padding = '10px 15px';
        button.style.backgroundColor = '#007bff';
        button.style.color = '#fff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.zIndex = '10000';

        // Add click event to redirect to the download URL in the same tab
        button.addEventListener('click', () => {
            window.location.href = downloadUrl;
        });

        // Append the button to the body
        document.body.appendChild(button);
        console.log("✅ Download button added successfully!");
    } else {
        console.warn("❌ No matching document found in the URL.");
    }
})();