智慧职教MOOC学院 --网课助手 (蓝版)

智慧职教简易自动学习脚本,解除Ctrl+C限制,自动评论/讨论

  1. // ==UserScript==
  2. // @name 智慧职教MOOC学院 --网课助手 (蓝版)
  3. // @version 1.08
  4. // @description 智慧职教简易自动学习脚本,解除Ctrl+C限制,自动评论/讨论
  5. // @author tuChanged
  6. // @run- document-end
  7. // @grant unsafeWindow
  8. // @match *://mooc.icve.com.cn/study/*
  9. // @license GPL
  10. // @namespace https://greasyfork.org/users/449085
  11. // @supportURL https://tuchg.github.io
  12. // @contributionURL https://greasyfork.org/users/449085
  13. // ==/UserScript==
  14. (function () {
  15. 'use strict';
  16. const setting = {
  17. // 随机评论
  18. randomComment: ["6666", "好", "讲解得很精辟"],
  19. //是否启用评论,
  20. isOpenComment: false,
  21. //最高延迟
  22. maxDelayTime: 5000,
  23. //最低3秒
  24. minDelayTime: 3000,
  25. //0-高清 1-清晰 2-流畅 3-原画
  26. videoQuality: 2,
  27. //2倍速
  28. videoPlaybackRate: 2
  29. }, _self = unsafeWindow,
  30. url = location.pathname,
  31. top = _self
  32.  
  33. try {
  34. while (top != _self.top) top = top.parent.document ? top.parent : _self.top;
  35. } catch (err) {
  36. console.log(err);
  37. top = _self;
  38. }
  39. var $ = _self.jQuery || top.jQuery;
  40.  
  41. //产生区间随机
  42. var rnd = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
  43. /**
  44. * 随机延迟执行方法
  45. * @param {需委托执行的函数} func 函数
  46. */
  47. var delayExec = (func) => setTimeout(func, rnd(setting.minDelayTime, setting.maxDelayTime));
  48. //跳转到某小节 通过顶栏
  49. var gotoUrl = (page) => page.contents()[3].click();
  50. //跳转下一页
  51. // var nextCourse = () => $(".next").click();
  52.  
  53.  
  54. //入口
  55. switch (url) {
  56. case "/study/courseLearn/resourcesStudy.html":
  57. _main();
  58. break;
  59. case "/study/discussionArea/topicReply.html":
  60. discussHandler();
  61. break;
  62. case "/study/workExam/testWork/preview.html":
  63. case "/study/workExam/onlineExam/preview.html":
  64. homeworkHandler();
  65. break;
  66. case "/study/workExam/homeWork/history.html":
  67. case "/study/workExam/onlineExam/history.html":
  68. case "/study/workExam/testWork/history.html":
  69. floatHandler();
  70. break;
  71. default:
  72. console.log(`脚本已准备启动 当前位置:${url}`);
  73. break;
  74. }
  75.  
  76. //当前页
  77. let current;
  78.  
  79. //刷课主逻辑
  80. function _main() {
  81. //请求数据
  82. $("#olTempleteCellModul").click();
  83. //main函数
  84. setTimeout(() => {
  85. //当前小节
  86. current = $("li.np--level.np--level-3.active");
  87. switch (current.data().categoryname) {
  88. case "pt":
  89. case "文档":
  90. pptHandler(current);
  91. break;
  92. case "视频":
  93. videoHandler(current);
  94. break;
  95. }
  96. console.log("当前处理逻辑安排完成,等待执行结果中");
  97. }, 10000);
  98. }
  99.  
  100. /**
  101. * 检测课程类别 并深层递归
  102. */
  103. function check(current) {
  104. //多级跳转
  105. if (current.next().length == 0) {
  106. // current.end();
  107. //往树根遍历
  108. //小章节
  109. let parent = current.closest(".np--level-2");
  110. if (parent.next().length == 0) {
  111. //大章
  112. let ancestor = parent.closest(".np--level-1")
  113. //检测是否到终章
  114. if (ancestor.next().length == 0) {
  115. alert("任务完成");
  116. //关闭当前窗口
  117. // closeTab();
  118. } else {
  119. check(ancestor.next().find(".np--level-3").first());
  120. }
  121. } else {
  122. check(parent.next().find(".np--level-3").first())
  123. }
  124. return;
  125. }
  126. //查询下一个是否已完成
  127. if (current.next().find("span.np--type.active").length > 0) {
  128. check(current.next());
  129. return;
  130. }
  131. //查询下一项所属类别
  132. switch (current.next().data().categoryname) {
  133. case ""://目录
  134. case "作业":
  135. case "测验":
  136. check(current.next());
  137. break;
  138. case "讨论":
  139. setTimeout(() => {
  140. gotoUrl(current.next())
  141. }, 20000);
  142. check(current.next());
  143. break;
  144. case "pt":
  145. case "视频":
  146. case "文档":
  147. gotoUrl(current.next());
  148. _main();
  149. break;
  150. }
  151. }
  152. /**
  153. * 作业处理
  154. */
  155. function homeworkHandler() {
  156. uncageCopyLimit()
  157. }
  158. /*
  159. * 解除文本限制
  160. */
  161. function uncageCopyLimit() {
  162. let arr = ["oncontextmenu", "ondragstart", "onselectstart", "onselect", "oncopy", "onbeforecopy"]
  163. for (let i of arr)
  164. $(".hasNoLeft").attr(i, "return true")
  165. console.log("已成功解除限制")
  166. }
  167. /**
  168. * 视频类处理
  169. */
  170. function videoHandler(current) {
  171. let player = top.jwplayer($(".jwplayer").attr("id"));
  172. //播放回调
  173. if (player.getState() == "complete") {
  174. console.log("视频原已播放完毕\n");
  175. delayExec(commentHandler(current));
  176. return;
  177. }
  178. //配置
  179. player.setMute(true)//静音
  180. player.setPlaybackRate(setting.videoPlaybackRate);
  181. player.setCurrentQuality(setting.videoQuality);
  182. //播放回调
  183. player.on("playlistComplete", () => {
  184. console.log("视频播放完成\n");
  185. delayExec(commentHandler(current));
  186. });
  187. }
  188. /**
  189. * PPT类别处理
  190. */
  191. function pptHandler(current) {
  192. //等待2秒后执行,避免不正常操作加载时间
  193. //延迟提交评论
  194. delayExec(commentHandler(current));
  195. }
  196. /**
  197. * 提取当前页内容
  198. */
  199. function exactProblem() {
  200. const arr = $(".e-q-body");
  201. let text = "";
  202.  
  203. for (let x = 0; x < arr.length; x++)
  204. text += arr[x].innerText;
  205. $("#_content").val(text);
  206.  
  207. }
  208. /**
  209. * 提取题目
  210. */
  211. function floatHandler() {
  212. const div = `<div style="border:#42b983 solid 2px;width: 330px; position: fixed; top: 0; right: 10px; z-index: 99999">
  213. <button id="extract_btn">提取</button>
  214. <hr/>
  215. <textarea id="_content" style="width: 100%;height: 300px;border: #B3C0D1 solid 2px;overflow: auto;font-size: x-small" />
  216. </div>`;
  217. $(div).appendTo('body')
  218. $("#extract_btn").bind('click', () => exactProblem())
  219. }
  220.  
  221.  
  222.  
  223. /**
  224. * 提交评论
  225. */
  226. function commentHandler(current) {
  227.  
  228. if (setting.isOpenComment) {
  229. //评5星
  230. $("#star #starImg4").click();
  231. //随机从词库填写评论
  232. $("iframe#ueditor_0").contents().find("body.view")[0].innerText = setting.randomComment[rnd(0, setting.randomComment.length - 1)];
  233. //提交
  234. delayExec(() => {
  235. $("#btnComment").click();
  236. delayExec(() => {
  237. $(".sgBtn.ok").click();
  238. console.log("评论成功\n");
  239. check(current);
  240. });
  241. });
  242. } else {
  243. check(current);
  244. }
  245.  
  246. }
  247. /**
  248. * 提交讨论
  249. */
  250. function discussHandler() {
  251. setTimeout(() => {
  252. //获取上一位的评论 隔两个索引为评论 字数太少往下查找,避免太水
  253. let vaildComment = findVaildDiscuss();
  254. // //开启HTML输入模式
  255. // $EDITORUI["edui945"]._onClick();
  256. //填充评论
  257. $("iframe#ueditor_0").contents().find("body.view")[0].innerText = vaildComment;
  258. //提交
  259. delayExec(() => {
  260. $(".btn_replyTopic").click();
  261. console.log("讨论成功\n");
  262. }
  263. );
  264. }, 10000);
  265. /* //返回上一页
  266. delayExec(() => window.history.go(-1)); */
  267. }
  268.  
  269. /**
  270. * 简单地找出一个有效的讨论
  271. */
  272. function findVaildDiscuss() {
  273. let arr = $(".mc-learning-table tbody tr div[id^='istext_']"), element;
  274. for (let i = 0; i < arr.length; i++) {
  275. element = arr[i].innerText;
  276. if (element.length > 10)
  277. return element;
  278. }
  279. return element;
  280. }
  281. })();