// ==UserScript== // @name ahedu文件下载 // @namespace aheduDownloader.taozhiyu.gitee.io // @version 0.2 // @description ahedu文件下载,右击文件名称下载 // @author 涛之雨 // @homepageURL https://greasyfork.org/zh-CN/scripts/440303 // @match http://www.ahedu.cn/EduResource/index.php?* // @match http://www.ahedu.cn/search/index.php?* // @icon http://www.ahedu.cn/EduResource/addons/theme/stv_resource/_static/images/favicon.ico // @grant none // @license MIT // @downloadURL none // ==/UserScript== /* global layer */ /* jshint esversion: 6 */ (function() { 'use strict'; //教师资源页 console.group('%cahedu文件下载脚本 %c by 涛之雨 ','color:white;background:green;font-size:30px;padding:10px','font-size:30px;padding:10px;background:orange;'); console.log('彩蛋(算是吧)'); console.groupEnd('cahedu文件下载脚本 by 涛之雨 '); if(location.pathname.startsWith("/EduResource")){ if(!location.href.match(/rid=([\da-z]+)/))return; document.querySelectorAll('.zuopin_resource_a').forEach(a=>{ a.oncontextmenu=x=>{ fetch("http://www.ahedu.cn/EduResource/index.php?app=acy&mod=ResList&act=downloadRes&acy_name=youzhike2020&upload_file_type=", { "headers": { "cache-control": "no-cache", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "pragma": "no-cache", }, "referrer": "http://www.ahedu.cn/EduResource/index.php?app=acy&mod=ResList&act=detail&rid=508573&acy_name=youzhike2020", "body": "rid="+ x.target.getAttribute("data-value"), "method": "POST" }).then(a=>a.json()).then(a=>{ if(a.code!==200){ throw ''; } layer.msg("加载成功,准备下载", {icon: 1}); window.location.href=a.url; }).catch(a=>layer.msg("网络请求出错...", {icon: 5})); return false; }; }); layer.msg("脚本加载成功
右键点击[文件名]下载文件", {icon: 1}); }else if(location.pathname.startsWith("/search")){ var rid=location.href.match(/resId=([\da-z]+)/); if(!rid||rid.length<2){ return; } var links=document.body.parentElement.innerHTML.match(new RegExp(`[^'"]+${rid[1]}[^'"]+`,'g')); if(!links){ links=document.body.parentElement.innerHTML.match(/fileurl\s*=\s*['"][^'"]+/g); if(!links){ layer.msg("获取链接出错...", {icon: 5}); return; } links=links[0].match(/[^'"]+$/g); } links=[...new Set(links)].filter(a=>!a.match(/html|qrCode/)); if(links.length!==1){ layer.msg("获取到未预期的链接数量...
请F12打开控制台查看链接
理论上每个都一样", {icon: 3}); console.clear(); console.group('%cahedu文件下载脚本 %c by 涛之雨 ','color:white;background:green;font-size:30px;padding:10px','font-size:30px;padding:10px;background:orange;'); links.map(a=>console.log(a)); console.groupEnd('cahedu文件下载脚本 by 涛之雨 '); return false; } document.querySelectorAll('.down').forEach(x=>{ x.oncontextmenu=x=>{ layer.msg("加载成功,准备下载", {icon: 1}); window.location.href=links; return false; }; }); layer.msg("脚本加载成功
右键点击[下载]按钮
即可下载文件", {icon: 1}); } })();