Yuntech Extract PDF URL

Extract and log the actual PDF download URL from eClass Yuntech, and add a download button

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Yuntech Extract PDF URL
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Extract and log the actual PDF download URL from eClass Yuntech, and add a download button
// @author       Chat-GPT
// @icon         https://eclass.yuntech.edu.tw/static/assets/images/favicon-b420ac72.ico
// @match        https://eclass.yuntech.edu.tw/*
// @license MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
  
    function extractPDFUrl() {
        try {
            // 取得當前頁面的 URL
            const viewerUrl = window.location.href;
            const urlParams = new URL(viewerUrl).searchParams;
            const encodedPdfUrl = urlParams.get("file");

            if (encodedPdfUrl) {
                // 解碼 URL 並輸出
                const pdfUrl = decodeURIComponent(encodedPdfUrl);
                console.log("PDF 下載網址:", pdfUrl);
                addDownloadButton(pdfUrl);
            } else {
                console.log("無法找到 PDF 下載網址");
            }
        } catch (error) {
            console.error("發生錯誤:", error);
        }
    }

    function addDownloadButton(pdfUrl) {
        const button = document.createElement("a");
        button.href = pdfUrl;
        button.textContent = '📥 下載 PDF';
        button.style.position = "fixed";
        button.style.bottom = "20px";
        button.style.right = "80px";
        button.style.background = "#28a745";
        button.style.color = "white";
        button.style.padding = "12px 16px";
        button.style.borderRadius = "8px";
        button.style.fontSize = "16px";
        button.style.fontWeight = "bold";
        button.style.boxShadow = "0 4px 6px rgba(0, 0, 0, 0.1)";
        button.style.transition = "all 0.3s ease";
        button.style.zIndex = "1000";
        button.style.cursor = "pointer";
        button.style.textDecoration = "none";
 // 滑鼠懸停特效
        button.onmouseover = function() {
            button.style.background = "#218838";
            button.style.transform = "scale(1.1)";
        };

        button.onmouseout = function() {
            button.style.background = "#28a745";
            button.style.transform = "scale(1)";
        };
        document.body.appendChild(button);
    }

    // 延遲執行,確保 DOM 內容加載完成
    setTimeout(extractPDFUrl, 2000);
})();