您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
下载畅课(一网畅学)平台的课程资源,即使老师设置了不可下载~
// ==UserScript== // @name 畅课平台资源下载 // @namespace https://bobliu.tech/ // @version 1.1.2 // @license MIT // @supportURL https://github.com/BobLiu0518/TronClass-Resource-Download/issues // @description 下载畅课(一网畅学)平台的课程资源,即使老师设置了不可下载~ // @author BobLiu // @match https://*/course/*/learning-activity* // @icon https://tronclass.com.cn/favicon.ico // @grant none // ==/UserScript== (async function () { 'use strict'; let host = window.location.origin; let activityId = window.location.hash.replace('#/', ''); let res = await fetch(`${host}/api/activities/${activityId}/upload_references`); let resources = (await res.json()).references; if (!resources.length) { console.log('No resources found.'); return; } for (let id in resources) { let resource = resources[id]; console.log(`[${parseInt(id) + 1}] ${resource.name}`); } console.log('Execute downloadResource(n) to download!'); window.downloadResource = async function (i) { i = parseInt(i) - 1; console.log(`Downloading ${resources[i].name}...`); let downloadUrlData = await fetch(`${host}/api/uploads/reference/document/${resources[i].id}/url`); let downloadUrl = (await downloadUrlData.json()).url; if (!downloadUrl) { console.error('Failed to get download URL.'); return; } window.open(downloadUrl, '_blank'); }; let inject = async function (retry) { if (typeof retry == 'object') retry = 0; let dom = document.getElementsByClassName('attachment-body')[0]; if (!dom) { if (retry < 5) { console.log('Cannot get file list dom, retrying in 1s...'); setTimeout(() => inject(retry + 1), 1000); } else { console.log('Cannot get file list dom, inject button failed.'); } return; } let fileList = dom.children; for (let row of fileList) { let filename = row.children[0].children[0].textContent.replaceAll(/\s*\n\s*/g, '').trim(); for (let i in resources) { let resource = resources[i]; if (filename == resource.name) { let downloadBtn = document.createElement('button'); downloadBtn.textContent = '下载'; downloadBtn.onclick = function (event) { event.preventDefault(); event.stopPropagation(); window.downloadResource(parseInt(i) + 1); }; row.children[0].appendChild(downloadBtn); break; } } } console.log('Download button injected.'); }; addEventListener('load', inject); })();