UESTC dxpx

UESTC dxpx学习平台刷课工具

  1. // ==UserScript==
  2. // @name UESTC dxpx
  3. // @version 0.2.2
  4. // @description UESTC dxpx学习平台刷课工具
  5. // @author 4ehex + fang
  6. // @match https://dxpx.uestc.edu.cn/user/account/info
  7. // @match https://dxpx.uestc.edu.cn/user/lesson
  8. // @match https://dxpx.uestc.edu.cn/fzdx/*
  9. // @match https://dxpx.uestc.edu.cn/jjfz/*
  10. // @match https://dxpx.uestc.edu.cn/exam/*
  11. // @connect easylearn.baidu.com
  12. // @grant unsafeWindow
  13. // @grant GM_getValue
  14. // @grant GM_setValue
  15. // @grant GM_addStyle
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_xmlhttpRequest
  18. // @require https://cdn.bootcdn.net/ajax/libs/jquery/2.0.0/jquery.js
  19. // @icon http://www.gov.cn/ztzl/17da/183d03632724084a01bb02.jpg
  20. // @license MIT
  21.  
  22. // @namespace https://greasyfork.org/zh-CN/users/1073349
  23. // ==/UserScript==
  24.  
  25. /* globals jQuery, $, waitForKeyElements */
  26.  
  27. let _self = unsafeWindow, url = location.pathname, videoLists = [], interval_id = -1;
  28.  
  29. //注册油猴菜单
  30. let id_course = RegisterTipMenu("course", "开/关 自动进入未完成课程", "自动进入未完成课程</p><p>(此功能将在进入课程中心时自动查找未完成必读课件的课程)</p>");
  31. let id_compulsory = RegisterTipMenu("compulsory", "开/关 自动进入必修课程", "自动进入必修课程</p><p>(此功能将在进入课程时自动查找未完成的必修课程)</p>");
  32. let id_back = RegisterTipMenu("back", "开/关 自动返回上一级", "自动返回上一级</p><p>(此功能将在完成视频列表里所有播放时, 返回上一级自动查找还未看的视频)</p>");
  33. let id_rightmenu = RegisterTipMenu("rightmenu", "开/关 右键菜单复制", "右键菜单复制</p><p>(此功能将开启右键菜单和复制)</p>");
  34. let id_answer = RegisterTipMenu("answer", "开/关 考试自动搜索答案", "自动搜索答案</p><p>(此功能将自动读取题目,通过百度题库搜索并显示答案)</p>")
  35. let id_about = GM_registerMenuCommand ("关于", function(){
  36. video_note();
  37. });
  38.  
  39.  
  40. // 适配发展对象
  41. if ((url == "/fzdx/lesson"))
  42. {
  43. alert_note(2, ["转到", "取消"], "[刷课脚本] 提示", '<p>请转到\'个人中心-我的课程\'页面</p><p>当前页面还未做刷课适配</p>', 'public_cont1',
  44. function () { $(".public_close").click(); },function (){ $(".public_close").click();});
  45. }
  46.  
  47. if (url == "/user/account/info")
  48. {
  49. alert_note(2, ["明白", "关闭"], "[刷课脚本] 提示", '<p>发展对象请转到\'我的课程\'页面开始刷课</p><p>积极分子请转到\'课程中心\'页面开始刷课</p><p>(若未开启刷课,需点击油猴图标开启刷课功能后刷新页面)</p>', 'public_cont1',
  50. function () { window.location.href = "https://dxpx.uestc.edu.cn/user/lesson"; },function (){ $(".public_close").click();});
  51. }
  52.  
  53. if (url == "/user/lesson")
  54. {
  55. if (!GM_getValue("dont_note")) video_note();
  56.  
  57. if (GM_getValue("course")) {
  58. var unstudy_links = new Array();//所有'未学习'的路由url
  59.  
  60. // 遍历所有 class 为 'study_plan2' 的元素
  61. $('.study_plan2').each(function() {
  62. var unfinishedFound = false;
  63. // 遍历子元素
  64. $(this).find('*').each(function() {
  65. // 检查子元素的文本是否包含 '未完成'
  66. if ($(this).text().indexOf('未完成') !== -1) {
  67. unfinishedFound = true;
  68. return false; // 停止遍历子元素
  69. }
  70. });
  71. // 如果找到了包含 '未完成' 的子元素
  72. if (unfinishedFound) {
  73. var study_a = $(this).find('.study_a:contains("学习")').attr('href');
  74. unstudy_links.push(study_a);
  75. }
  76. });
  77.  
  78. if (unstudy_links.length != 0)
  79. {
  80. //进入第一个还未学习的课程
  81. console.log("[Debbug] Enter:" + unstudy_links[0]);
  82. window.location.href = unstudy_links[0];
  83. }
  84. else
  85. {
  86. alert_note(2, ["好的", "敬请期待"], "提示", '<p>已刷完全部课程</p><p>感谢使用!</p><p>发展对象考试搜题功能还在开发中^_^</p>', 'public_cont1',
  87. function () { $(".public_close").click();},function (){ $(".public_close").click();});
  88. }
  89. }
  90. }
  91.  
  92. //定位到'必读课件'<'已完成必读课件'的课程 并自动跳转到'课程中心-精品课程'
  93. if (url == "/jjfz/lesson") {
  94. if (!GM_getValue("dont_note")) video_note();
  95.  
  96. if(interval_id!= -1) {
  97. clearInterval(interval_id);
  98. interval_id = -1;
  99. }
  100.  
  101. if (GM_getValue("course")) {
  102. let completed_count = 0, course_count = $(".lesson_c_ul").children().length;
  103.  
  104. $(".lesson_center_dl").each( function() {
  105. let courseware_ = $(this).text();
  106. let required_ = parseInt(courseware_.substr(courseware_.indexOf("必读课件:") + 5, 4));
  107. let completed_ = parseInt(courseware_.substr(courseware_.indexOf("已完成必读课件:") + 8), 4);
  108. //console.log("必读课件:" + required_ + "\n已完成:" + completed_);
  109. if (required_ > completed_) {//未完成
  110. $(this).next().children()[0].click();//点击'开始学习'
  111. return false;
  112. }
  113. else{
  114. completed_count += 1;
  115. if (completed_count >= course_count) {
  116. alert_note(2, ["好的", "关闭刷课功能"], "提示", '<p>已刷完全部课程</p><p>感谢使用!</p>', 'public_cont1', function () {
  117. $(".public_close").click();
  118. },function (){
  119. GM_setValue("course", false);GM_setValue("compulsory", false);GM_setValue("back", false);
  120. $(".public_close").click();
  121. alert("已关闭 [自动进入未完成课程] [自动进入必修课程] [自动返回上一级]");
  122. });
  123. return false;
  124. }
  125. }
  126. });
  127. }
  128. }
  129.  
  130. if (url == "/jjfz/lesson/video" && GM_getValue("compulsory")) {
  131. if(interval_id!= -1) {
  132. clearInterval(interval_id);
  133. interval_id = -1;
  134. }
  135.  
  136. //如果URL最后一位是#则删去
  137. if (window.location.href.substr(-1) == "#") {
  138. window.location.href = window.location.href.replace(/\#$/, '');
  139. return;
  140. }
  141.  
  142. //转到'必修'页面
  143. if (getUrlParam("required") == null || getUrlParam("required") != '1'){
  144. UpdateUrlParam("required", 1);
  145. return;
  146. }
  147.  
  148. let page_count = 1, page_cur = 1, lesson_cur = 0, completed_cur = 0;
  149. //获取有几页课程 (判断.page_btn是否存在)
  150. if ($(".page_btn").length != 0) {
  151. page_count = $(".page_btn").siblings("a").length - 2;//a标签还有page_go和末页
  152. page_cur = parseInt($(".page_btn").text());
  153. }
  154.  
  155. lesson_cur = $(".lesson1_lists ul:first").children().length;
  156.  
  157. //定位到未完成课程 并自动进入
  158. $(".lesson1_lists ul:first").children().each( function() {
  159. if ($(this).find(".lesson_pass").length == 0) {//判断是否有"完成"标志 没有则进入
  160. $(this).children()[0].click();
  161. return false;
  162. }
  163. else {
  164. completed_cur += 1;
  165. if (completed_cur >= lesson_cur) {//如果已完成的课程等于列表课程数 则翻页 如果到末页则返回上一级
  166. if (page_cur >= page_count) {
  167. console.log("全部已完成,返回课程中心");
  168. if (GM_getValue("back")) $(".head_top_left").find(".head_cut")[0].click();
  169. }
  170. else{
  171. UpdateUrlParam("page", page_cur + 1);
  172. return false;
  173. }
  174. }
  175. }
  176. });
  177.  
  178. }
  179.  
  180. if ((url.indexOf("jjfz/play") != -1) || (url.indexOf("fzdx/play") != -1)) {
  181. let is_fzdx = (url.indexOf("fzdx/play") != -1);
  182.  
  183. getVideoList();//获取视频播放列表
  184.  
  185. let nextVideoFlag = false,
  186. nextClassFlag = false;
  187.  
  188. //不加muted谷歌不让自动播放
  189. setVideoMuted();
  190.  
  191. interval_id = setInterval(() => {
  192. nextVideoFlag = closeAlert();
  193. nextClassFlag = jumpToVideo(videoLists);
  194. if (nextVideoFlag) nextClassFlag = nextVideo(videoLists);
  195. if (nextClassFlag) {
  196. if (is_fzdx){
  197. window.location.href = "https://dxpx.uestc.edu.cn/user/lesson"
  198. }
  199. else{
  200. goBack();
  201. }
  202. }
  203. }, 1000)
  204. }
  205.  
  206. function getVideoList() {
  207. if ($(".video_lists li").length) {
  208. //console.log("当前视频" + $(".video_red1").text())
  209. videoLists = $(".video_lists li");
  210. }
  211. }
  212.  
  213. function closeAlert(){
  214. if($(".video_red1>a").css("color") == "rgb(255, 0, 0)"){
  215. nextVideo();
  216. }else if($(".public_cont>.public_text>p").text().indexOf('您需要完整观看一遍课程视频') != -1){
  217. $(".public_cont>.public_btn>a")[0].click();
  218. }else if($(".public_cont>.public_text>p").text().indexOf('视频已暂停') != -1){
  219. $(".public_cont>.public_btn>a")[0].click();
  220. }else if($(".public_btn>.public_cancel").text().indexOf('继续观看') != -1 ) {
  221. $(".public_btn>.public_cancel")[0].click();
  222. }else if($(".public_cont>.public_text>p").text().indexOf('当前视频播放完毕') != -1){
  223. $(".public_cont>.public_btn>a")[0].click();
  224. }else if($(".public_cont>.public_text>p").text().indexOf('上次观看') != -1){
  225. $(".public_cont>.public_btn>a")[1].click();
  226. }else if($("#wrapper>div>div>button").attr("aria-label") == 'Play'){
  227. $("#wrapper>div>button").click();
  228. }
  229. }
  230.  
  231. //判断是否播放完毕过
  232. function isPlayOverEver() {
  233. //通过判断Player中是否有进度条来判断是否播放完毕
  234. if ($(".plyr__progress").length) {
  235. return true;
  236. }
  237. else {
  238. return false;
  239. }
  240. }
  241.  
  242. function nextVideo(){
  243. let videoCount = $(".video_lists>ul>li").length;
  244. $(".video_lists>ul>li").each((_,element) => {
  245. if($(element).children("a").css("color") != "rgb(255, 0, 0)"){//通过文本颜色判断是否播放完毕过 (红色为播放完毕过)
  246. $(element).children("a")[0].click()
  247. return false
  248. }else{
  249. videoCount--
  250. if(videoCount == 0) {
  251. console.log("列表播放完毕,返回课程页");
  252. clearInterval(interval_id);
  253. goBack();
  254. }
  255. }
  256. })
  257. }
  258.  
  259. function jumpToVideo(videoList) {
  260. if ($(".video_red1").find("a").attr("style") == "width:70%;color:red") {
  261. let index = $(videoList).index($(".video_red1"));
  262. if (videoList[index + 1]) {
  263. $(videoList[index + 1]).children("a").attr('id', 'aRemoveAllTxt');
  264. document.getElementById("aRemoveAllTxt").click();
  265. } else {
  266. return true;
  267. }
  268. }
  269. }
  270.  
  271. function goBack() {
  272. if (GM_getValue("back")) $('.video_goback')[0].click();
  273. }
  274.  
  275. //给player加上muted标签
  276. function setVideoMuted() {
  277. $("#video").prop("muted", true);
  278. }
  279.  
  280. //通过'百度教育'搜索答案
  281. if ((url == "/jjfz/lesson/exam" || url == "/jjfz/exam_center/end_exam") && GM_getValue("answer")) {
  282. //↓添加一个搜索答案的浮窗
  283. //添加样式
  284. GM_addStyle("body {background: #e9e9e9;font-family: 'Microsoft YaHei','Lantinghei SC','Open Sans',Arial,'Hiragino Sans GB','STHeiti','WenQuanYi Micro Hei','SimSun',sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}.bd_answer {background: #ffffff;position:absolute;box-shadow: 3px 3px 2px grey;}.bd_answer header {background: #bd6982;padding: 10px 15px;color: #ffffff;font-size: 14px;cursor: move;}.bd_answer header:before, .bd_answer header:after {display: block;content: '';clear: both;}.bd_answer header h2, .bd_answer .body ul li .content h3 {margin: 0;padding: 0;font-size: 14px;float: left;}.bd_answer header h2 a {color: #ffffff;text-decoration: none;}.bd_answer header .tools {list-style: none;margin: 0;padding: 0;float: right;}.bd_answer header .tools li {display: inline-block;margin-right: 6px;}.bd_answer header .tools li:last-child {margin: 0;}.bd_answer header .tools li a {color: #ffffff;text-decoration: none;-webkit-transition: all 0.3s linear 0s;-moz-transition: all 0.3s linear 0s;-ms-transition: all 0.3s linear 0s;-o-transition: all 0.3s linear 0s;transition: all 0.3s linear 0s;}.bd_answer .body {position: relative;max-height: 360px;overflow-y: scroll;overflow-x: hidden;}.bd_answer .body .search {display: none;width: 100%;}.bd_answer .body .search.opened {display: block;}.bd_answer .body .search input {width: 100%;margin: 0;padding: 10px 15px;border: none;-webkti-box-size: border-box;-moz-box-size: border-box;box-size: border-box;}.bd_answer .body ul {list-style: none;padding: 0;margin: 0;border-top: 1px solid #f2f2f2;}.bd_answer .body ul li {position: relative;background: #ffffff;display: block;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer .body ul li:before, .bd_answer .body ul li:after {display: block;content: '';clear: both;}.bd_answer .body ul li:hover .thumbnail {background: #bd6982;}.bd_answer .body ul li:nth-child(2n) {background: #f2f2f2;}.bd_answer .body ul li .thumbnail {display: inline-block;background: #bfbfbf;width: 50px;color: #ffffff;line-height: 50px;text-align: center;text-decoration: none;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.bd_answer .body ul li .thumbnail img {width: 100%;}.bd_answer .body ul li .content {display: inline-block;margin-left: 6px;vertical-align: top;line-height: 1;}.bd_answer .body ul li .content h3 {display: block;width: 100%;margin-bottom: 5px;color: #808080;}.bd_answer .body ul li .content .preview {display: block;width: 100%;max-width: 200px;margin-bottom: 5px;color: #cccccc;font-size: 12px;}.bd_answer .body ul li .content .meta {color: #b3b3b3;font-size: 12px;}.bd_answer .body ul li .content .meta a {color: #999999;text-decoration: none;}.bd_answer .body ul li .content .meta a:hover {text-decoration: underline;}.bd_answer .body ul li .message {display: none;position: absolute;top: 0;left: 0;overflow: hidden;height: 100%;width: 100%;padding: 10px;box-sizing: border-box;}.bd_answer footer a {background: #bd6982;display: block;width: 100%;padding: 10px 15px;color: #ffffff;font-size: 14px;text-align: center;text-decoration: none;box-sizing: border-box;}.bd_answer footer a:hover {background: #cd8ca0;-webkit-transition: background 0.3s linear 0s;-moz-transition: background 0.3s linear 0s;-ms-transition: background 0.3s linear 0s;-o-transition: background 0.3s linear 0s;transition: background 0.3s linear 0s;}.info {width: 300px;margin: 25px auto;text-align: center;}.info h1 {margin: 0;padding: 0;font-size: 20px;font-weight: 400;color: #333333;}.info span {color: #666666;font-size: 12px;}.info span a {color: #000000;text-decoration: none;}.info span .fa {color: #bd6982;}.info span .spoilers {color: #999999;margin-top: 5px;font-size: 10px;}");
  285. //添加html
  286. $("body").prepend(`<div class="bd_answer" id="asr1" style="width:auto;inset:107px auto auto 124.82px;height:auto;z-index: 9999999;"><header><h2 id="main_title" class="drag_zone">点击右侧获取答案👉</h2><ul class="tools" style="cursor:pointer"><li><div id="get_answer">◼</div></li><li><div id="clear_asr">🗑︎</div></li><li><div id="search_setting">⚙</div></li></ul></header><div class="body"><div id="search_options" style="display: block;"><input id="search_num" placeholder="搜索数量 默认为3" type="number" min="1" max="10" style="float: left;width:62%;"><label style="font-size: 80%;vertical-align: middle;"><input type="checkbox" id="cb_enhanced" style="vertical-align: middle;"/>Enhanced</label></div><ul id="info_container"><li><a class="thumbnail"style="width: 50px;word-wrap: break-word;word-break: break-all;" href="#">[简答]</a><div class="content"><h3>[题目]</h3><span class="preview">[答案]</span> <span class="meta"><a target="_blank" href="[#]">原网页链接</a></span></div></li></ul></div><footer class="drag_zone"><a style="cursor:move">拖动这里移动窗口</a></footer></div>`);
  287. //以下为针对新添加浮窗的JS脚本
  288. var _move=false;//移动标记
  289. var _x,_y;//鼠标离控件左上角的相对位置
  290. $(".drag_zone").click(function(){}).mousedown(function(e){
  291. _move=true;
  292. _x=e.pageX-parseInt($("#asr1").css("left"));
  293. _y=e.pageY-parseInt($("#asr1").css("top"));
  294. $(".bd_answer").fadeTo(20, 0.25);//点击后开始拖动并透明显示
  295. });
  296. $(document).mousemove(function(e){
  297. if(_move){
  298. var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
  299. var y=e.pageY-_y;
  300. $(".bd_answer").css({top:y,left:x});//控件新位置
  301. }
  302. }).mouseup(function(){
  303. _move=false;
  304. $(".bd_answer").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明
  305. });
  306. $("#clear_asr").click(function(){//清空答案
  307. $('#info_container').children().each(function(){$(this).remove()});
  308. $("#main_title").text('点击右侧获取答案👉');
  309. });
  310. $("#search_setting").click(function(){
  311. if ($("#search_options").attr("style").indexOf("display: none") != -1) {
  312. $("#search_options").css('display', 'block');
  313. }
  314. else {
  315. $("#search_options").css('display', 'none');
  316. }
  317. });
  318. $("#get_answer").click(function(){
  319. let s_question = $(".exam_h2").text().substr($(".exam_h2").text().indexOf('.') + 1);//获取问题;
  320. if ($('#cb_enhanced').is(':checked')){//如果开启了增强模式则连同题目的选项一起搜索
  321. let s_options = '';
  322. if ($('.e_cont_title').text().indexOf('单选题') != -1) {
  323. s_options = $('.answer_list').text().split(/[\t\r\f\n\s]*/g).join('');
  324. }
  325. else if ($('.e_cont_title').text().indexOf('多选题') != -1){
  326. s_options = $('.answer_list_box').text().split(/[\t\r\f\n\s]*/g).join('');
  327. }
  328. s_question += s_options;
  329. }
  330. //console.log(s_question);
  331. $('#info_container').children().each(function(){$(this).remove()});//删除之前的元素
  332.  
  333. //在浮窗中添加search_bdjy search_rwwz链接
  334. let template_a = `<li><a class="thumbnail" style="width: 50px;word-wrap: break-word;word-break: break-all;" href="#">[🔎]</a><div class="content"><span class="meta"><a target="_blank" href="[search_bdjy]">🔎: 用百度在'百度教育'中搜索</a></span><br><br><span class="meta"><a target="_blank" href="[search_rwwz]">🔎: 用百度在'瑞文文摘'中搜索</a></span>`;
  335. let bd_search_url = "https://www.baidu.com/s?ie=utf-8&tn=baidu&wd=";
  336. template_a = template_a.replace("[search_bdjy]", bd_search_url + encodeURIComponent("site:easylearn.baidu.com" + s_question));
  337. template_a = template_a.replace("[search_rwwz]", bd_search_url + encodeURIComponent("site:www.rwtext.com" + s_question));
  338. $('#info_container').append(template_a);
  339.  
  340. //拼接请求URL (pageSize代表返回几个搜索结果)
  341. let search_count = "3",
  342. search_url = "https://easylearn.baidu.com/edu-web/content/search?query=[question]&type=&page=1&pageSize=[seach_count]&clientType=pc",
  343. search_result_ids = new Array(),
  344. basicinfo_url = "https://easylearn.baidu.com/edu-web-go/shiti/basicinfo?id=[entityId]&eqid=&clientType=pc",//通过entityId获取问题答案
  345. basicinfo_result_iqac = new Map();//{id:[ question, answer, [choice] ], ...} e.g. 1709367078503208905:["邓小平理论同马克思列宁主", "A", ["A.xxx", B."xxxx"]], ...
  346.  
  347. if ($("#search_num").val() != '') search_count = $("#search_num").val();
  348. search_url = search_url.replace("[seach_count]", search_count);
  349.  
  350. //发送搜索题目的GET请求 同步方式
  351. $("#main_title").text('正在发送搜索问题GET请求...');
  352. let true_search_url = search_url.replace("[question]", encodeURIComponent(s_question));
  353. SyncXmlHttpRequest(true_search_url, "GET").then((res) => {
  354. let search_parse = $.parseJSON(res);
  355. if (search_parse.errmsg != "success") {
  356. console.log("[Error] Search GET response Json Not success!");
  357. return alert("搜索响应结果不是success!");
  358. }
  359.  
  360. if (search_parse.data.list.length <= 0) {
  361. console.log("[Error] Search GET response Json List Empty!");
  362. $("#main_title").text('❌搜索为空请点击下方搜索...');
  363. return ;//alert("搜索响应结果为空!");
  364. }
  365.  
  366. search_parse.data.list.forEach(function (item, index) {//遍历搜索结果的entityId
  367. if (item.entityId != null) search_result_ids.push(item.entityId);
  368. });
  369.  
  370. if (search_result_ids.length <= 0) {
  371. console.log("[Error] Search Result Empty!");
  372. return alert("搜索结果为空!");
  373. }
  374.  
  375. //发送获取答案的GET请求 同步方式
  376. var promises = search_result_ids.map(function (item) {
  377. //console.log("[Debug] id: " + item);
  378. let true_basicinfo_url = basicinfo_url.replace("[entityId]", item);
  379. return SyncXmlHttpRequest(true_basicinfo_url, "GET").then((res) => {
  380. console.log(res);
  381. let basicinfo_parse = $.parseJSON(res);
  382. if (basicinfo_parse.errmsg != "success") {
  383. console.log("[Error] BasicInfo GET response Json Not success!");
  384. return alert("获取答案响应结果不是success!");
  385. }
  386. let array_choice = new Array();//获取选项
  387. if (basicinfo_parse.data.choice != null && basicinfo_parse.data.choice.length != 0) {
  388. basicinfo_parse.data.choice.forEach(function(item) {
  389. array_choice.push(item.desc);
  390. })
  391. }
  392.  
  393. basicinfo_result_iqac[basicinfo_parse.data.id] = [basicinfo_parse.data.strquestion, basicinfo_parse.data.answer[0].desc, array_choice];
  394.  
  395. //console.log("[Debug] 题目: " + basicinfo_parse.data.strquestion);
  396. //console.log("[Debug] 解答: " + basicinfo_parse.data.answer[0].desc);
  397. }).catch((err) => {
  398. console.log("[Error] " + err);
  399. return alert(err);
  400. });
  401. });
  402. $("#main_title").text('题目搜索完毕,发送搜索答案GET请求...');
  403. Promise.all(promises).then(() => {//统一执行
  404. //添加元素到浮窗
  405. let template_li = `<li><a class="thumbnail"style="font-size: 25%; line-height:235%;width: 50px; word-wrap: break-word;word-break: break-all;" href="#">[简答]</a><div class="content"><h3>[题目]</h3><span class="preview">[选项]</span> <span class="meta"><a target="_blank" href="[#]">原网页链接</a></span></div></li>`,
  406. org_answer_url = "https://easylearn.baidu.com/edu-page/tiangong/questiondetail?id=[entityId]&from=jySearch";
  407. $.each(basicinfo_result_iqac, function(key, value){
  408. let str_tmp = template_li.replace("[题目]", value[0].substr(0, 20)), str_choice = '';
  409. if (value[2].length != 0) {//选项文本
  410. value[2].forEach(function(item, index){
  411. str_choice += (String.fromCharCode(65+index) + "." + DelMiscContent(item));
  412. });
  413. }
  414.  
  415. if (value[1].indexOf("<img") != -1) {//答案中有图片
  416. let img_ = `<img style="width: auto; height: auto; max-width: 100%; max-height: 60%;"src=` + GetImgSrc(value[1])[0] + "/>";
  417. str_tmp = str_tmp.replace("[选项]", str_choice + img_);
  418. str_tmp = str_tmp.replace("[简答]", "[图片]");
  419. }
  420. else {
  421. if (str_choice.length != 0){//选项不为空文本
  422. str_tmp = str_tmp.replace("[选项]", str_choice);
  423. }
  424. else{//选项为空则把选项的位置放入答案文本
  425. str_tmp = str_tmp.replace("[选项]", DelMiscContent(value[1]));
  426. }
  427. str_tmp = str_tmp.replace("[简答]", DelMiscContent(value[1]).substr(0, 10));
  428. }
  429.  
  430. str_tmp = str_tmp.replace("[#]", org_answer_url.replace("[entityId]", key));
  431.  
  432. $('#info_container').append(str_tmp);
  433. });
  434. $("#main_title").text('✔︎全部已完成...');
  435. });
  436. }).catch((err) => {
  437. console.log("[Error] " + err);
  438. return alert(err);
  439. });
  440. });
  441. }
  442.  
  443. if (GM_getValue("rightmenu")) openCopy();
  444.  
  445.  
  446. function openCopy() {
  447. $(document).ready(new function () {
  448. document.oncontextmenu = new Function("event.returnValue=true");
  449. document.onselectstart = new Function("event.returnValue=true");
  450. document.oncopy = new Function("return true");
  451. })
  452. }
  453.  
  454. function video_note() {
  455. alert_note(2, ["关闭", "不再提示"], "UESTC dxpx脚本使用说明",
  456. '<p><font color="aqua"></font>[*] 默认功能全关 需点击油猴图标进行设置</p>' +
  457. '<p style="color: red;"><font color="aqua"></font>[*] 积极分子开启前三项即可自动刷课</p>' +
  458. '<p style="color: red;"><font color="aqua"></font>[*] 发展对象只需开启第一项和第三项</p>' +
  459. '<p><font color="aqua"></font>[+] 新增发展对象刷课功能</p>' +
  460. '<p>[-] 考试自动搜题功能已失效 之后完善</p>',
  461. 'public_cont1', function () {
  462. $(".public_close").click(); //此为关闭方法
  463. GM_setValue("dont_note", false)
  464. }, function () {
  465. $(".public_close").click(); //此为关闭方法
  466. GM_setValue("dont_note", true)
  467. });
  468. }
  469.  
  470. function alert_note(btn_num, btn_text, note_text, public_text, public_cont_class, submit_fun, cancel_fun) {
  471. var public_a;
  472. if (btn_num == 1) {
  473. public_a = '<a href="#" class="public_submit">' + btn_text[0] + '</a>';
  474. } else {
  475. public_a = '<a href="#" class="public_submit">' + btn_text[0] + '</a> <a href="#" class="public_cancel">' + btn_text[1] + '</a>';
  476. }
  477. var public_html = '<div class="public_mask"></div><div class="public_cont ' + public_cont_class + '"><div class="public_title"><h3>' + note_text + '</h3><div class="public_close"></div></div><div class="public_text">' + public_text + '</div><div class="public_btn">' + public_a + '</div></div>';
  478. $("body").append(public_html);
  479. $(".public_close").click(function () {
  480. $(".public_mask").remove();
  481. $(".public_cont").remove();
  482. });
  483. $(".public_mask").click(function () {
  484. $(".public_mask").remove();
  485. $(".public_cont").remove();
  486. });
  487. if (btn_num == 1) {
  488. $(".public_submit").click(function () {
  489. submit_fun();
  490. })
  491. } else {
  492. $(".public_submit").click(function () {
  493. submit_fun();
  494. });
  495. $(".public_cancel").click(function () {
  496. cancel_fun();
  497. })
  498. }
  499. }
  500.  
  501. // 获取url中参数的值
  502. function getUrlParam(name) {
  503. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
  504. var r = window.location.search.substr(1).match(reg);
  505. if (r!=null) return (r[2]); return null;
  506. }
  507.  
  508. // 添加 修改 url中参数的值
  509. function UpdateUrlParam(name, val) {
  510. let thisURL = document.location.href;
  511.  
  512. // 如果 url中包含这个参数 则修改
  513. if (thisURL.indexOf(name+'=') > 0) {
  514. let v = getUrlParam(name);
  515. if (v != null) {// 是否包含参数
  516. thisURL = thisURL.replace(name + '=' + v, name + '=' + val);
  517. }
  518. else {
  519. thisURL = thisURL.replace(name + '=', name + '=' + val);
  520. }
  521. }
  522. else {// 不包含这个参数 则添加
  523. if (thisURL.indexOf("?") > 0) {
  524. thisURL = thisURL + "&" + name + "=" + val;
  525. }
  526. else {
  527. thisURL = thisURL + "?" + name + "=" + val;
  528. }
  529. }
  530.  
  531. if (thisURL != document.location.href) document.location.href = thisURL;
  532. };
  533.  
  534. //注册油猴提示菜单
  535. function RegisterTipMenu(id, menu_text, tip_text) {
  536. let id_menu = GM_registerMenuCommand (menu_text, function(){
  537. if (GM_getValue(id)) {
  538. GM_setValue(id, false);
  539. alert_note(1, ["关闭"], "提示", '<p>已关闭 ' + tip_text, 'public_cont1', function () {
  540. $(".public_close").click();
  541. });
  542. }
  543. else {
  544. GM_setValue(id, true);
  545. alert_note(1, ["关闭"], "提示", '<p>已开启 ' + tip_text, 'public_cont1', function () {
  546. $(".public_close").click();
  547. });
  548. }
  549. });
  550. }
  551.  
  552. //以同步方式发送跨域请求
  553. function SyncXmlHttpRequest(request_url, method_type) {
  554. return new Promise((resolve, reject) => {
  555. GM_xmlhttpRequest({
  556. method: method_type,
  557. url: request_url,
  558. headers: {
  559. "Accept": "application/json, text/plain, */*",
  560. "Accept-Encoding": "gzip, deflate, br",
  561. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"
  562. },
  563. onload: function(response) {
  564. if (response.status != 200){
  565. return reject("Search GET response Not 200 OK!");
  566. }
  567. //console.log("[Debug] " + response.responseText);
  568. return resolve(response.responseText);
  569. },
  570. onerror: function(err) {
  571. return reject(err);
  572. }
  573. });
  574. });
  575. }
  576.  
  577. //纯字符串操作的方式 删去答案和选项中html标签中的杂项
  578. function DelMiscContent(val){
  579. let start = -1, end = -1, pos = -1, ele = "div";
  580. while((pos = val.indexOf('text-indent')) != -1){
  581. start = val.lastIndexOf('<', pos);
  582. ele = val.substring(start + 1, val.indexOf(" ", start));
  583. if (val.indexOf("/>", pos) != -1){
  584. end = val.indexOf("/>", pos) + 2;
  585. }
  586. else{
  587. end = val.indexOf("</" + ele, pos) + 6;
  588. }
  589. val = val.substring(0, start) + val.substr(end);
  590. }
  591. return GetPlainText(val);
  592. }
  593.  
  594. //去除文本中的html标签
  595. function GetPlainText(val) {
  596. if (val != null && val != "") {
  597. var re1 = new RegExp("<.+?>|&.+?;","g"); //匹配html标签的正则表达式,"g"是搜索匹配多个符合的内容
  598. var msg = val.replace(re1,""); //执行替换成空字符
  599. msg = msg.replace(/\s/g,""); //去掉所有的空格(中文空格、英文空格都会被替换)
  600. msg = msg.replace(/[\r\n]/g,""); //去掉所有的换行符
  601. return msg;
  602. } else return ''
  603. }
  604.  
  605. //获取<img>中的src的值
  606. function GetImgSrc(article) {
  607. let reg = /(< img|<img).*?(?:>|\/>)/gim //匹配所有图片标签
  608. let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i // 匹配图片中的src
  609. return article.match(reg).map(val => {
  610. let src = val.match(srcReg)
  611. return src[1]
  612. });
  613. }