Greasy Fork

Greasy Fork is available in English.

智慧教育平台PDF获取

自动获取中小学智慧教育平台电子教材的PDF URL

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         智慧教育平台PDF获取
// @version      0.0.1
// @description  自动获取中小学智慧教育平台电子教材的PDF URL
// @match        https://basic.smartedu.cn/*
// @author       白弹汲
// @grant        GM_addStyle
// @grant        GM_setClipboard
// @icon         https://basic.smartedu.cn/favicon.ico
// @license      AGPL-3.0  
// @namespace http://greasyfork.icu/users/1128263
// ==/UserScript==

(function() {
    'use strict';

    // 创建一个按钮并添加到页面上
    const createButton = () => {
        // 检查当前页面是否为目标页面
        const regex = /\/pdfjs\/.+/;
        if (regex.test(window.location.href)) {
            const button = document.createElement('button');
            button.textContent = '获取 PDF URL';
            button.style.position = 'fixed';
            button.style.top = '10px';
            button.style.right = '10px';
            button.style.zIndex = '9999';
            button.addEventListener('click', filterPDFUrl);
            document.body.appendChild(button);
        }
    };

    // 筛选PDF URL并弹出窗口显示结果
    const filterPDFUrl = () => {
        const requests = performance.getEntriesByType('resource');
        let filteredUrl = null;

        for (const request of requests) {
            if (request.name.includes('pdf.pdf')) {
                const originalUrl = request.name;
                const modifiedUrl = originalUrl.replace('-private', '');
                filteredUrl = modifiedUrl;
                break;
            }
        }

        if (filteredUrl) {
            GM_setClipboard(filteredUrl);
            window.alert('URL已被复制到剪贴板内:\n' + filteredUrl);
            window.open(filteredUrl, '_blank');
        } else {
            window.alert('找不到 PDF URL.');
        }
    };

    // 初始化脚本
    const initScript = () => {
        createButton();
        GM_addStyle(`
            button {
                color: #fff;
                background-color: #09AAFF;
                border: none;
                border-radius: 4px;
                padding: 10px;
            }
        `);
    };

    // 当页面加载完成时运行脚本
    window.addEventListener('load', initScript);
})();