ahedu文件下载

ahedu文件下载,右击文件名称下载

  1. // ==UserScript==
  2. // @name ahedu文件下载
  3. // @namespace aheduDownloader.taozhiyu.gitee.io
  4. // @version 0.4
  5. // @description ahedu文件下载,右击文件名称下载
  6. // @author 涛之雨
  7. // @homepageURL https://greasyfork.org/zh-CN/scripts/440303
  8. // @match *://www.ahedu.cn/EduResource/index.php?*
  9. // @match *://www.ahedu.cn/search/index.php?*
  10. // @icon https://www.ahedu.cn/EduResource/addons/theme/stv_resource/_static/images/favicon.ico
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. /* global layer flvjs*/
  16. /* jshint esversion: 8 */
  17. (function() {
  18. 'use strict';
  19. //教师资源页
  20. console.group('%cahedu文件下载脚本 %c by 涛之雨 ','color:white;background:green;font-size:30px;padding:10px','font-size:30px;padding:10px;background:orange;');
  21. console.log('彩蛋(算是吧)');
  22. console.groupEnd('cahedu文件下载脚本 by 涛之雨 ');
  23. const appName= location.href.match(/app=([^&]+)/),
  24. acyName=location.href.match(/acy_name=([^&]+)/);
  25. if(location.pathname.startsWith("/EduResource")){
  26. if(!location.href.match(/rid=([\da-z]+)/))return;
  27. if(!appName||appName.length<2||!acyName||acyName.length<2){
  28. return;
  29. }
  30.  
  31. var getVideoLink=async dom=> await fetch("//www.ahedu.cn/EduResource/index.php?app="+appName[1]+"&mod=ResList&act=downloadRes&acy_name="+acyName[1], {
  32. "headers": {
  33. "cache-control": "no-cache",
  34. "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
  35. "pragma": "no-cache",
  36. },
  37. "referrer": location.href,
  38. "body": "rid="+ dom.getAttribute("data-value"),
  39. "method": "POST"
  40. }).then(a=>a.json()).then(a=>{
  41. if(a.code!==200){
  42. throw '';
  43. }
  44. return a.url;
  45. }).catch(a=>!layer.msg("网络请求出错...", {icon: 5}));
  46.  
  47. document.querySelectorAll('.zuopin_resource_a').forEach(a=>{
  48. a.oncontextmenu=async x=>{
  49. x.preventDefault();
  50. const v=await getVideoLink(x.target);
  51. if(v){
  52. layer.msg("加载成功,准备下载", {icon: 1});
  53. window.location.href=v;
  54. }
  55. return false;
  56. };
  57. });
  58. layer.msg("脚本加载成功<br>右键点击[文件名]下载文件", {icon: 1});
  59. setTimeout(function(){
  60. const prev=document.querySelector('#preview_flv');
  61. if(prev&&prev.innerText.startsWith('Error loading')){
  62. (async function(){
  63. var v=await getVideoLink(document.querySelector('.cur a'));
  64. if(/\.flv$/.test(v)){
  65. // @require https://cdn.bootcdn.net/ajax/libs/flv.js/1.6.2/flv.min.js
  66. //flvjs.isSupported()&&
  67. // prev.innerHTML=`<video src='${v}' controls style='width:100%;height:100%' muted></video>`;
  68. // var flvPlayer = flvjs.createPlayer({
  69. // type: 'flv',
  70. // url: v
  71. // });
  72. // flvPlayer.attachMediaElement(prev.querySelector('video'));
  73. // flvPlayer.load();
  74. layer.msg("暂不支持在线播放flv格式<br>您可以尝试下载", {icon: 7});
  75. }if(/\.mp4$/.test(v)){
  76. prev.innerHTML=`<video src='${v}' controls style='width:100%;height:100%'></video>`;
  77. layer.msg("已为您修复并重构播放界面", {icon: 1});
  78. }else{
  79. layer.msg("暂不支持的格式<br>您可以尝试下载", {icon: 7});
  80. }
  81. })();
  82. }
  83. },2000);
  84. }else if(location.pathname.startsWith("/search")){
  85. var rid=location.href.match(/resId=([\da-z]+)/);
  86. if(rid.length<2){
  87. return;
  88. }
  89. var links=document.body.parentElement.innerHTML.match(new RegExp(`[^'"]+${rid[1]}[^'"]+`,'g'));
  90. if(!links){
  91. links=document.body.parentElement.innerHTML.match(/fileurl\s*=\s*['"][^'"]+/g);
  92. if(!links){
  93. layer.msg("获取链接出错...", {icon: 5});
  94. return;
  95. }
  96. links=links[0].match(/[^'"]+$/g);
  97. }
  98. links=[...new Set(links)].filter(a=>!a.match(/html|qrCode/));
  99. if(links.length!==1){
  100. layer.msg("获取到未预期的链接数量...<br>请F12打开控制台查看链接<br>理论上每个都一样", {icon: 3});
  101. console.clear();
  102. console.group('%cahedu文件下载脚本 %c by 涛之雨 ','color:white;background:green;font-size:30px;padding:10px','font-size:30px;padding:10px;background:orange;');
  103. links.map(a=>console.log(a));
  104. console.groupEnd('cahedu文件下载脚本 by 涛之雨 ');
  105. return false;
  106. }
  107. document.querySelectorAll('.down').forEach(x=>{
  108. x.oncontextmenu=x=>{
  109. layer.msg("加载成功,准备下载", {icon: 1});
  110. window.location.href=links;
  111. return false;
  112. };
  113. });
  114. layer.msg("脚本加载成功<br>右键点击[下载]按钮<br>即可下载文件", {icon: 1});
  115. }
  116. })();