Elearning Download

高雄科技大學 Elearning 檔案下載(114學年度修復版)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Elearning Download
// @namespace    https://facaikotei.github.io/
// @version      6.0.1
// @description  高雄科技大學 Elearning 檔案下載(114學年度修復版)
// @author       (c)2025 facaikotei (c)2022 Juirmin
// @match        https://elearning.nkust.edu.tw/moocs/*
// @require      https://update.greasyfork.org/scripts/12228/175122/setMutationHandler.js
// @icon         https://elearning.nkust.edu.tw/moocs/assets/icons/PWA_icon_128.png
// @license      MIT
// @website      https://greasyfork.org/users/1305953
// ==/UserScript==

(function () {
    'use strict';

    setMutationHandler(document.querySelector('.cgust-main'), '.course-node__info', async (els) => {
        const courseNodeData = await (await fetch(`/api/v1/courses/${JSON.parse(sessionStorage.assignment).courseId}/node`)).json();
        const urlExtractor = item => [item.blank_url, ...item.items.flatMap(urlExtractor)];
        const urls = courseNodeData.data.items.flatMap(urlExtractor);
        els = [...new Set(els)];
        els.forEach((el, index) => {
            const url = urls[index % urls.length];
            if (url && !el.querySelector(`[href="${url}"]`)) {
                el.insertAdjacentHTML('beforeend', `<a target="_blank" href="${url}">下載</a>`);
            }
        });
    });
})();