icve-helper

icve-funs

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/399050/787355/icve-helper.js

  1. // ==UserScript==
  2. // @name icve-helper
  3. // @namespace 2196760287@qq.com
  4. // @version 1.0.0
  5. // @description icve-funs
  6. // @author AI_童话
  7. // @grant GM_xmlhttpRequest
  8. // ==/UserScript==
  9.  
  10. // ========================================================router.js=================================================
  11. let _apiserver = 'https://zjy2.icve.com.cn/api'
  12. let _config = {
  13. study: _apiserver + '/study/',
  14. com: _apiserver + '/common/',
  15. student: _apiserver + '/student/'
  16. }
  17.  
  18. let _securityOrigin = 'https://security.zjy2.icve.com.cn/api'
  19. let _securityConfig = {
  20. study: _securityOrigin + '/study/'
  21. }
  22. let urls = {
  23. login: _config.study + 'login/login',
  24. myHomework_getMyHomeworkList: _config.student + 'myHomework/getMyHomeworkList',
  25. homework_detail: _securityConfig.study + '/homework/detail',
  26. homework_history: _securityConfig.study + 'homework/history'
  27. };
  28. // ========================================================router.js=================================================
  29.  
  30.  
  31. // ========================================================class.js==================================================
  32. /** 学生类
  33. * @class Student
  34. */
  35. class Student {
  36. constructor(userName, userPwd) {
  37. this.userName = userName;
  38. this.userPwd = userPwd;
  39. }
  40.  
  41. /** 学生登录
  42. * @method login
  43. * @returns 登录成功信息
  44. */
  45. login() {
  46. return new Promise((resolve, reject) => {
  47. GM_xmlhttpRequest({
  48. method: 'POST',
  49. url: urls.login,
  50. headers: {
  51. 'Content-type': 'application/x-www-form-urlencoded'
  52. },
  53. data: 'userName=' + this.userName +
  54. '&userPwd=' + this.userPwd +
  55. '&verifyCode=' + ''
  56. ,
  57. timeout: setting.time,
  58. onload: xhr => {
  59. if (xhr.status == 200) {
  60. let obj = JSON.parse(xhr.responseText);
  61. resolve(obj);
  62. }
  63. }
  64. });
  65. });
  66. }
  67.  
  68. /** 获取我的作业列表
  69. * @method getMyHomeworkList
  70. * @param {boolean} unprocessed 是否未完成 0 已完成 1未完成
  71. * @return 作业列表
  72. */
  73. getMyHomeworkList(unprocessed) {
  74. return new Promise((resolve, reject) => {
  75. GM_xmlhttpRequest({
  76. url: urls.myHomework_getMyHomeworkList,
  77. method: 'POST',
  78. headers: {
  79. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  80. },
  81. data: 'unprocessed=' + unprocessed || 0,
  82. timeout: setting.timeout,
  83. onload: xhr => {
  84. if (xhr.status == 200) {
  85. var obj = JSON.parse(xhr.responseText);
  86. this.hmwrkList = obj.list; // list
  87. resolve(this.hmwrkList);
  88. }
  89. }
  90. });
  91. });
  92. }
  93.  
  94. // 不写了 累
  95. getDetail(hmwrk) {
  96. if (hmwrk instanceof HomeWork) {
  97.  
  98. }
  99. }
  100.  
  101. getHistory(hmwrk) {
  102. if (hmwrk instanceof HomeWork) {
  103.  
  104. }
  105. }
  106. }
  107.  
  108. // 我 是 学生
  109. class I extends Student {
  110. constructor(userName, userPwd) {
  111. super(userName, userPwd);
  112. }
  113.  
  114. /** 获取我的作业信息
  115. * @method getPerivewInfo
  116. * @return 我的作业对象
  117. */
  118. getPerivewInfo() {
  119. let courseOpenId = $('[name=courseOpenId]')[0].value;
  120. let openClassId = $('[name=openClassId]')[0].value;
  121. let homeWorkId = $('[name=homeworkId]')[0].value;
  122. let hkTermTimeId = ($('[name=hkTermTimeId]')[0] || $('[name=homeworkTermTimeId]')[0]).value;
  123. this.hmwrk = new HomeWork(courseOpenId, openClassId, homeWorkId, hkTermTimeId); // 获取我的作业信息
  124. return this.hmwrk;
  125. }
  126.  
  127. copy(hmwrk) {
  128. if (!(hmwrk instanceof HomeWork)) {
  129. return '不是作业没办法复制呢!';
  130. }
  131. fillAnswer(hmwrk.history);
  132. }
  133. }
  134.  
  135. // 我朋友 是 学生
  136. class MyFriend extends Student {
  137. constructor(userName, userPwd) {
  138. super(userName, userPwd);
  139. }
  140.  
  141. // 我的朋友帮助我
  142. async helpWith(hmwrk) {
  143. if (!(hmwrk instanceof HomeWork)) { // 如果是 HomeWork
  144. return '数据类型错误!'; // 传过来的不是作业
  145. }
  146.  
  147. console.log('我朋友的作业列表: ');
  148. console.log(await this.getMyHomeworkList()); // 获取我的作业列表 hmwrkList
  149.  
  150. let isfndCourse = false; // 是否找到课程
  151. for (let i = 0; i < this.hmwrkList.length; i++) {
  152. let hk = this.hmwrkList[i];
  153. if (hk.courseOpenId == hmwrk.courseOpenId) {
  154. isfndCourse = true; // 找到相应课程
  155. this.hmwrkList = hk.homeworkList; // 根据courseOpenId 获取 homeworkList
  156. break;
  157. }
  158. }
  159.  
  160. if (!isfndCourse) { // 如果找到相应 课程
  161. return '你们没有报名相同的课程.';
  162. }
  163.  
  164. let isfndHmwrk = false; // 是否找该作业
  165. for (let i = 0; i < this.hmwrkList.length; i++) {
  166. let hk = this.hmwrkList[i];
  167. if (hk.homeworkId == hmwrk.homeWorkId) {
  168. isfndHmwrk = true;
  169. if (!hk.stuHomeworkCount) return '该学生还未做答!'; // 如果作答次数为0, 直接返回
  170.  
  171. // 朋友的作业
  172. this.hmwrk = new HomeWork(hk.courseOpenId, hk.openClassId, hk.homeWorkId,
  173. hk.hkTermTimeId)
  174. ;
  175.  
  176. this.hmwrk.info = hk; // 朋友作业的官方信息
  177. await this.hmwrk.getDetail(); // 朋友获取作业的详细
  178. console.log(await this.hmwrk.getHistory()); // 朋友获取作答记录
  179. return '成功获取朋友的作业.';
  180. }
  181. }
  182.  
  183. return '你的朋友没有这个作业!';
  184. }
  185. }
  186.  
  187. // 作业
  188. class HomeWork {
  189. constructor(courseOpenId, openClassId, homeWorkId, hkTermTimeId) {
  190. this.courseOpenId = courseOpenId;
  191. this.openClassId = openClassId;
  192. this.homeWorkId = homeWorkId; // 作业id
  193. this.hkTermTimeId = hkTermTimeId;
  194. }
  195.  
  196. /** 获取该作业的详细信息
  197. * @method getDetail
  198. * @return this.detail
  199. */
  200. getDetail() {
  201. return new Promise((resolve, reject) => {
  202. GM_xmlhttpRequest({
  203. method: 'POST',
  204. url: urls.homework_detail,
  205. headers: {
  206. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  207. },
  208. data: 'courseOpenId=' + this.info.courseOpenId +
  209. '&openClassId=' + this.info.openClassId +
  210. '&homeworkId=' + this.info.homeworkId +
  211. '&hkTermTimeId=' + this.info.hkTermTimeId
  212. // '&dtype=1&viewType=2&unprocessed=0'
  213. ,
  214. timeout: setting.time,
  215. onload: xhr => {
  216. if (xhr.status == 200) {
  217. this.detail = JSON.parse(xhr.responseText);
  218. resolve(this.detail);
  219. }
  220. }
  221. });
  222. })
  223.  
  224. }
  225.  
  226. /** 根据 stuHomeworkId 获取 批过的试卷
  227. * @method getHistory
  228. * @return this.history
  229. */
  230. getHistory() {
  231. return new Promise((resolve, reject) => {
  232. let index = this.detail.homeworkStulist.length - 1; // 最后一次提交
  233.  
  234. GM_xmlhttpRequest({
  235. method: 'POST',
  236. url: urls.homework_history,
  237. headers: {
  238. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
  239. },
  240. data: 'courseOpenId=' + this.detail.courseOpenId +
  241. '&homeWorkId=' + this.detail.homeworkId +
  242. '&studentWorkId=' + this.detail.homeworkStulist[index].Id
  243. ,
  244. timeout: setting.time,
  245. onload: xhr => {
  246. if (xhr.status == 200) {
  247. this.history = JSON.parse(xhr.responseText);
  248. resolve(this.history); // history object
  249. }
  250. }
  251. });
  252. })
  253. }
  254. }
  255.  
  256. // ========================================================class.js==================================================
  257.  
  258.  
  259. // ========================================================handler.js================================================
  260. /** 向控制台输出 hello world!
  261. * @method hello
  262. */
  263. function hello() {
  264. console.log("hello world");
  265. }
  266.  
  267. /** 获取网站的jQuery, 并添加自己的函数
  268. * @method getjQuery
  269. * @param window unsafewindow
  270. * @returns $
  271. */
  272. function getjQuery(window) {
  273.  
  274. /** 等待元素出现
  275. * @method wait
  276. * @param func 找到元素后执行
  277. * @param times 检测次数 -1 一直检测
  278. * @param interval 检测间隔 默认20s
  279. */
  280. window.jQuery.fn.wait = function (func, times, interval) {
  281. var _times = times || -1, // 100次
  282. _interval = interval || 20, // 20毫秒每次
  283. _self = this,
  284. _selector = this.selector, // 选择器
  285. _iIntervalID; // 定时器id
  286. if (this.length) { // 如果已经获取到了,就直接执行函数
  287. func && func.call(this);
  288. } else {
  289. _iIntervalID = setInterval(function () {
  290. if (!_times) { // 是0就退出
  291. clearInterval(_iIntervalID);
  292. }
  293. _times <= 0 || _times--; // 如果是正数就 --
  294.  
  295. _self = $(_selector); // 再次选择
  296. if (_self.length) { // 判断是否取到
  297. func && func.call(_self);
  298. clearInterval(_iIntervalID);
  299. }
  300. }, _interval);
  301. }
  302. }
  303.  
  304. return window.jQuery;
  305. }
  306.  
  307. /*
  308. * 职教云作业解封文本限制 @tuChanged
  309. */
  310. function uncageCopyLimit() {
  311. let arr = ["oncontextmenu", "ondragstart", "onselectstart", "onselect", "oncopy", "onbeforecopy"]
  312. for (let i of arr)
  313. $(".hasNoLeft").attr(i, "return true")
  314. console.log("已成功复制解除限制,📣如果您有软件定制(管理系统,APP,小程序等),毕设困扰,又或者课程设计困扰等欢迎联系,价格从优,源码调试成功再付款💰,实力保证,包远程,包讲解 QQ:2622321887")
  315. }
  316.  
  317. function num2zimu(t) {
  318. return new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-')[t];
  319. }
  320.  
  321.  
  322. function _get_tamplate(asw) {
  323. let s = ''
  324. for (let i = 0; i < asw.length; i++) {
  325. if (i > 0) {
  326. s += ', ';
  327. }
  328. s += num2zimu(asw[i]);
  329. }
  330.  
  331. return document.createTextNode('搬运答案: ' + s);
  332. }
  333.  
  334. /** 自动填写答案
  335. * @method fillAnswer
  336. * @param {HomeWork.history} history 作业记录
  337. */
  338. function fillAnswer(history) {
  339. console.log("开始填写答案!");
  340. let questions = history.questions;
  341. let questbodys = $('.e-q-body'); // 题目div数组
  342.  
  343. // 遍历 questions 数组 根据questionTitle找到questionBody 之后 判断字符串 点击
  344. for (let i = 0; i < questions.length; i++) {
  345. let q = questions[i];
  346. let qt = q.questionType;
  347.  
  348. // 分步乘法计数原理 遍历 Body
  349. for (let j = 0; j < questbodys.length; j++) {
  350. let qbody = questbodys[j];
  351.  
  352. if (qbody.getAttribute('data-questionid') == q.questionId) { // 对比 quesiotnId
  353. if (qt <= 3) // 单选、多选、判断
  354. {
  355. let asw = q.Answer;
  356. let stuAsw = q.studentAnswer.split(',');
  357. asw = asw || stuAsw;
  358. let optli = qbody.getElementsByTagName('li'); // 获取选项
  359.  
  360. if (qt == 1 || qt == 2) { // 单选题 或者 多选题
  361. let aswli = q.answerList;
  362.  
  363. // 遍历 答案列表
  364. for (let k = 0; k < asw.length; k++) {
  365. let aswCntnt = aswli[asw[k]].Content;
  366. for (let l = 0; l < optli.length; l++) {
  367. let dstryTtlBtn = optli[l].getElementsByTagName('div')[0];
  368. // console.log('html: ' + dstryTtlBtn.innerText);
  369. // console.log('数据答案: ' + aswCntnt);
  370. // if (aswCntnt.indexOf(dstryTtlBtn.innerText) !== -1) { // destoryTitleButton
  371. if (zyxformat(aswCntnt) == zyxformat(dstryTtlBtn.innerText)) {
  372. optli[l].style.color = 'green';
  373. optli[l].click();
  374. }
  375. else {
  376. if (optli[l].style.color != 'green') {
  377. optli[l].style.color = 'red';
  378. }
  379. }
  380. }
  381. }
  382. }
  383. else if (qt == 3) { // 判断题
  384. for (let k = 0; k < asw.length; k++) // 判断题 相反
  385. {
  386. optli[asw[k]].style.color = 'red';
  387. optli[asw[k] ^ 1].style.color = 'green';
  388. optli[asw[k] ^ 1].click();
  389. }
  390. }
  391. // 加入答案面板
  392. qbody.appendChild(_get_tamplate(asw));
  393. }
  394. // <!-- 8:阅读理解 9:完形填空 11:视听题 -->
  395. else if (questions[i].questionType == 8 || questions[i].questionType == 9 || questions[i].questionType == 11) { // 完型填空
  396. console.log(history);
  397. let subQuestions = history.subQuestions; // 数据
  398. let forms = Array.from(questbodys[j].getElementsByTagName('form')); // 实体
  399. console.log(forms);
  400.  
  401. subQuestions[Id].forEach(subQuestion => {
  402. // let qid = subQuestion.Id; // question Id
  403. // let qttl = subQuestion.title; // question Title
  404. // let qt = subQuestion.subQuestionType; // question type
  405. // let asw = subQuestion.questionAnswer; // answer array
  406. // let aswli = subQuestion.subAnswerList; // anserList array
  407. // let stuasw = subQuestion.studentAnswer; //
  408.  
  409. forms.forEach(f => {
  410. if (f.querySelector('[name=subQuestionId]').value == subQuestion.Id) {
  411. if (subQuestion.subQuestionType == 1 || subQuestion.subQuestionType == 2) {
  412. // (subQuestion.questionAnswer || subQuestion.studentAnswer).forEach(answer => {
  413. let as = subQuestion.questionAnswer || subQuestion.studentAnswer;
  414. console.log('sub答案: ' + as);
  415. Array.from(f.getElementsByTagName('li')).forEach(opt => {
  416. console.log(opt.getElementsByClassName('destroyTitleButton')[0].innerText);
  417. console.log(subQuestion.subAnswerList[as].Content);
  418. if (opt.getElementsByClassName('destroyTitleButton')[0].innerText == subQuestion.subAnswerList[as].Content) {
  419. opt.style.color = 'green';
  420. opt.click();
  421. } else {
  422. opt.style.color = 'red';
  423. }
  424. });
  425. // });
  426. }
  427. else {
  428. Array.from(f.getElementsByTagName('li')).forEach(opt => {
  429. if (opt.getAttribute('data-index') == subQuestion.questionAnswer || subQuestion.studentAnswer) {
  430. opt.style.color = 'green';
  431. opt.click();
  432. } else {
  433. opt.style.color = 'red';
  434. }
  435. });
  436. }
  437. }
  438. });
  439. });
  440. }
  441. }
  442. }
  443. // else if (qt == 6) // 问答题
  444. // {
  445. // var txa = questbodys[i].getElementsByTagName('textarea')[0];
  446. // (function (qid, txa, a, i) {
  447. // setTimeout(function () {
  448. // txa.value = a[0];
  449. // GM_xmlhttpRequest({
  450. // method: 'POST',
  451. // url: onlineHomeworkAnswer,
  452. // headers: {
  453. // 'Content-type': 'application/x-www-form-urlencoded'
  454. // },
  455. // data: 'studentWorkId=' + qid +
  456. // '&answer=' + a[0]
  457. // ,
  458. // timeout: 5E3,
  459. // onload: function (xhr) {
  460. // if (xhr.status == 200) {
  461. // var obj = JSON.parse(xhr.responseText);
  462. // if (obj.code) {
  463. // console.log('ok');
  464. // }
  465. // }
  466. // }
  467. // });
  468. // }, (i + 1) * 1000);
  469. // })(qid, txa, asw, i);
  470. // }
  471. }
  472. }
  473.  
  474. // @感谢中国大学mooc网课助手作者 democrazy 的字符串处理
  475. let zyxtrim = function (str) { return str.replace(/\s+/g, ""); }; // 修剪
  476. let zyxformat = function (str) { // format
  477. let htmlDecode = function (_str) {
  478. var s = "";
  479. if (_str.length == 0) return "";
  480. s = _str.replace(/&lt;/g, "<");
  481. s = s.replace(/&gt;/g, ">");
  482. s = s.replace(/&nbsp;/g, " ");
  483. s = s.replace(/&#39;/g, "\'");
  484. s = s.replace(/&quot;/g, "\"");
  485. s = s.replace(/&amp;/g, "&");
  486. return s;
  487. }
  488. var regx = /<[img ]{3,}[\S]+?[https]{3,4}:\/\/([\S]+?\.[pngjeifbm]{3,4})[\S]+?>/gi;
  489. var regx2 = /\<[\S ]+?\>/ig;
  490. return zyxtrim(htmlDecode(str)).replace(regx, "$1").replace(regx2, "");
  491. }
  492. // ========================================================handler.js================================================
  493.