Greasy Fork

Greasy Fork is available in English.

CAU在线教育综合平台PDF课件下载

自动检测网页中的PDF文件并提供下载按钮

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         CAU在线教育综合平台PDF课件下载
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  自动检测网页中的PDF文件并提供下载按钮
// @author       chatgpt
// @match        https://jx.cau.edu.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 检测页面中是否有PDF文件的iframe
    const pdfIframe = document.getElementById('pdfIframe');
    if (pdfIframe) {
        // 从iframe中提取PDF文件的URL
        const urlString = pdfIframe.src;
        const urlParams = new URLSearchParams(urlString.split('?')[1]);
        const fileUrl = decodeURIComponent(urlParams.get('file'));

        // 创建下载按钮
        const downloadButton = document.createElement('button');
        downloadButton.innerText = '下载PDF文件';
        downloadButton.style.position = 'fixed';
        downloadButton.style.top = '10px';
        downloadButton.style.right = '10px';
        downloadButton.style.zIndex = '1000';
        downloadButton.style.padding = '10px';
        downloadButton.style.backgroundColor = '#4CAF50';
        downloadButton.style.color = 'white';
        downloadButton.style.border = 'none';
        downloadButton.style.borderRadius = '5px';
        downloadButton.style.cursor = 'pointer';

        // 按钮点击事件,下载PDF文件
        downloadButton.addEventListener('click', () => {
            const link = document.createElement('a');
            link.href = fileUrl;
            link.download = 'document.pdf'; // 默认下载时的文件名
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });

        // 添加下载按钮到页面
        document.body.appendChild(downloadButton);
    }
})();