Greasy Fork is available in English.

超星网课助手

自动挂机看尔雅MOOC,支持视频、音频、文档、图书自动完成,章节测验自动答题提交,支持自动切换任务点、挂机阅读时长、自动登录等,解除各类功能限制,开放自定义参数

  1. // ==UserScript==
  2. // @name 超星网课助手
  3. // @namespace wyn665817@163.com
  4. // @version 4.1.1
  5. // @description 自动挂机看尔雅MOOC,支持视频、音频、文档、图书自动完成,章节测验自动答题提交,支持自动切换任务点、挂机阅读时长、自动登录等,解除各类功能限制,开放自定义参数
  6. // @author wyn665817
  7. // @match *://*.chaoxing.com/*
  8. // @match *://*.edu.cn/*
  9. // @connect forestpolice.org
  10. // @run-at document-end
  11. // @grant unsafeWindow
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_setClipboard
  14. // @supportURL https://greasyfork.org/zh-CN/scripts/369625/feedback
  15. // @license MIT
  16. // ==/UserScript==
  17.  
  18. // 设置修改后,需要刷新或重新打开网课页面才会生效
  19. var setting = {
  20. // 5E3 == 5000,科学记数法,表示毫秒数
  21. time: 5E3 // 默认响应速度为5秒,不建议小于3秒
  22. ,review: 0 // 复习模式,完整挂机视频(音频)时长,支持挂机任务点已完成的视频和音频,默认关闭
  23. ,queue: 1 // 队列模式,开启后任务点逐一完成,关闭则单页面所有任务点同时进行,默认开启
  24.  
  25. // 1代表开启,0代表关闭
  26. ,video: 0 // 视频支持后台、切换窗口不暂停,支持多视频,默认关闭
  27. ,work: 1 // 自动答题功能(章节测验),作业需要手动开启查询,高准确率,默认开启
  28. ,audio: 0 // 音频自动播放,与视频功能共享vol和rate参数,默认关闭
  29. ,book: 0 // 图书阅读任务点,非课程阅读任务点,默认关闭
  30. ,docs: 0 // 文档阅读任务点,PPT类任务点自动完成阅读任务,默认关闭
  31. // 本区域参数,上方为任务点功能,下方为独立功能
  32. ,jump: 0 // 自动切换标签、章节、课程(需要配置course参数),默认关闭
  33. ,read: '0' // 挂机课程阅读时间,单位是分钟,'65'代表挂机65分钟,请手动打开阅读页面,默认'0'分钟
  34. ,face: 0 // 解除面部识别(不支持二维码类面部采集),此功能仅为临时解除,默认关闭
  35. ,total: 0 // 显示课程进度的统计数据,在学习进度页面的上方展示,默认关闭
  36.  
  37. // 仅开启video(audio)时,修改此处才会生效
  38. ,line: '公网1' // 视频播放的默认资源线路,此功能适用于系统默认线路无资源,默认'公网1'
  39. ,http: '标清' // 视频播放的默认清晰度,无效参数则使用系统默认清晰度,默认'标清'
  40. // 本区域参数,上方为video功能独享,下方为audio功能共享
  41. ,vol: '0' // 默认音量的百分数,设定范围:[0,100],'0'为静音,默认'0'
  42. ,rate: '1' // 视频播放默认倍率,参数范围0∪[0.0625,16],'0'为秒过,默认'1'倍
  43.  
  44. // 仅开启work时,修改此处才会生效
  45. ,auto: 0 // 答题完成后自动提交,默认开启
  46. ,none: 0 // 无匹配答案时执行默认操作,关闭后若题目无匹配答案则会暂时保存已作答的题目,默认开启
  47. ,scale: 0 // 富文本编辑器高度自动拉伸,用于文本类题目,答题框根据内容自动调整大小,默认关闭
  48.  
  49. // 仅开启jump时,修改此处才会生效
  50. ,course: 0 // 当前课程完成后自动切换课程,仅支持按照根目录课程顺序切换,默认关闭
  51. ,lock: 1 // 跳过未开放(图标是锁)的章节,即闯关模式或定时发放的任务点,默认开启
  52.  
  53. // 自动登录功能配置区
  54. ,school: '账号为手机号可以不修改此参数' // 学校/单位/机构码,要求完整有效可查询,例如'清华大学'
  55. ,username: '' // 学号/工号/借书证号(邮箱/手机号/账号),例如'2018010101',默认''
  56. ,password: '' // 密码,例如'123456',默认''
  57. },
  58. _self = unsafeWindow,
  59. url = location.pathname,
  60. top = _self;
  61.  
  62. if (url != '/studyApp/studying' && top != _self.top) document.domain = location.host.replace(/.+?\./, '');
  63.  
  64. try {
  65. while (top != _self.top) {
  66. top = top.parent.document ? top.parent : _self.top;
  67. if (top.location.pathname == '/mycourse/studentstudy') break;
  68. }
  69. } catch (err) {
  70. // console.log(err);
  71. top = _self;
  72. }
  73.  
  74. var $ = _self.jQuery || top.jQuery,
  75. parent = _self == top ? self : _self.parent,
  76. Ext = _self.Ext || parent.Ext || {},
  77. UE = _self.UE,
  78. vjs = _self.videojs,
  79. dl = 'https://d0.ananas.chaoxing.com/download/';
  80.  
  81. String.prototype.toCDB = function() {
  82. return this.replace(/\s/g, '').replace(/[\uff01-\uff5e]/g, function(str) {
  83. return String.fromCharCode(str.charCodeAt(0) - 65248);
  84. }).replace(/[“”]/g, '"').replace(/[‘’]/g, "'").replace(/。/g, '.');
  85. };
  86. _self.alert = console.log;
  87.  
  88. setting.normal = ''; // ':visible'
  89. // setting.time += Math.ceil(setting.time * Math.random()) - setting.time / 2;
  90. setting.job = [':not(*)'];
  91.  
  92. setting.video && setting.job.push('iframe[src*="/video/index.html"]');
  93. setting.work && setting.job.push('iframe[src*="/work/index.html"]');
  94. setting.audio && setting.job.push('iframe[src*="/audio/index.html"]');
  95. setting.book && setting.job.push('iframe[src*="/innerbook/index.html"]');
  96. setting.docs && setting.job.push('iframe[src*="/ppt/index.html"]', 'iframe[src*="/pdf/index.html"]');
  97.  
  98. if (url == '/mycourse/studentstudy') {
  99. _self.checkMobileBrowerLearn = $.noop;
  100. var classId = location.search.match(/cla[zs]{2}id=(\d+)/i)[1] || 0,
  101. courseId = _self.courseId || location.search.match(/courseId=(\d+)/i)[1] || 0;
  102. !setting.jump || setting.lock || $('#coursetree').on('click', '[onclick*=void], [href*=void]', function() {
  103. _self.getTeacherAjax(courseId, classId, $(this).parent().attr('id').slice(3));
  104. });
  105. } else if (url == '/ananas/modules/video/index.html' && setting.video) {
  106. if (setting.review) _self.greenligth = Ext.emptyFn;
  107. vjs.hook('beforesetup', hookVideoB);
  108. vjs.hook('setup', hookVideoS);
  109. Ext.isIos = Ext.isAndroid = false;
  110. } else if (url == '/work/doHomeWorkNew' || url == '/api/work' || url == '/work/addStudentWorkNewWeb') {
  111. if (!UE) {
  112. var len = ($ || Ext.query || Array)('font:contains(未登录)', document).length;
  113. setTimeout(len == 1 ? top.location.reload : parent.greenligth, setting.time);
  114. } else if (setting.work) {
  115. setTimeout(relieveLimit, 0);
  116. beforeFind();
  117. }
  118. } else if (url == '/ananas/modules/audio/index.html' && setting.audio) {
  119. if (setting.review) _self.greenligth = Ext.emptyFn;
  120. vjs.hook('beforesetup', hookAudioB);
  121. vjs.hook('setup', hookAudioS);
  122. } else if (url == '/ananas/modules/innerbook/index.html' && setting.book) {
  123. setTimeout(function() {
  124. if (getTip()) _self.setting ? _self.top.onchangepage(_self.getFrameAttr('end')) : _self.greenligth();
  125. }, setting.time);
  126. } else if (url.match(/^\/ananas\/modules\/(ppt|pdf)\/index\.html$/) && setting.docs) {
  127. setTimeout(function() {
  128. if (getTip()) _self.setting ? _self.finishJob() : _self.greenligth();
  129. }, setting.time);
  130. frameElement.setAttribute('download', 1);
  131. if (_self.downloadNum == '') _self.downloadNum = '1';
  132. } else if (url == '/knowledge/cards') {
  133. $ && checkToNext();
  134. } else if (url.match(/^\/(course|zt)\/\d+\.html$/)) {
  135. setTimeout(function() {
  136. +setting.read && _self.sendLogs && $('.course_section:eq(0) .chapterText').click();
  137. }, setting.time);
  138. } else if (url == '/ztnodedetailcontroller/visitnodedetail') {
  139. setting.read *= 60 / $('.course_section').length;
  140. setting.read && _self.sendLogs && autoRead();
  141. } else if (url.match(/^\/visit\/(courses|interaction)$/)) {
  142. setting.face && $('.zmodel').on('click', '[onclick^=openFaceTip]', function() {
  143. var id = $(this).attr('onclick').match(/(\d+).+?(\d+)/) || [];
  144. $(this).closest('li').find('[onclick^=openFaceTip]').removeAttr('onclick').attr({
  145. target: '_blank',
  146. href: 'stucoursemiddle?courseid=' + id[1] + '&clazzid=' + id[2]
  147. });
  148. alert('本课程已临时解除面部识别');
  149. });
  150. } else if (url == '/mycourse/studentcourse') {
  151. var gv = location.search.match(/d=\d+&/g);
  152. setting.total && $('<a>', {
  153. href: '/moocAnalysis/chapterStatisticByUser?classI' + gv[1] + 'courseI' + gv[0] + 'userId=' + _self.getCookie('_uid') + '&ut=s',
  154. target: '_blank',
  155. title: '点击查看章节统计',
  156. style: 'margin: 0 25px;',
  157. html: '本课程共' + $('.icon').length + '节,剩余' + $('em:not(.openlock)').length + '节未完成'
  158. }).appendTo('.zt_logo').parent().width('auto');
  159. } else if (location.host.match(/^passport2/)) {
  160. setting.username && getSchoolId();
  161. } else if (location.hostname == 'i.mooc.chaoxing.com') {
  162. _self.layui.use('layer', function() {
  163. this.layer.open({content: '拖动进度条、倍速播放、秒过会导致不良记录!', title: '超星网课助手提示', btn: '我已知悉', offset: 't', closeBtn: 0});
  164. });
  165. } else if (url == '/work/selectWorkQuestionYiPiYue') {
  166. submitAnswer(getIframe().parent(), $.extend(true, [], parent._data));
  167. }
  168.  
  169. function getTip() {
  170. return top != _self && jobSort($ || Ext.query);
  171. }
  172.  
  173. function jobSort($) {
  174. var fn = $.fn ? [getIframe(1), 'length'] : [self, 'dom'],
  175. sel = setting.job.join(', :not(.ans-job-finished) > .ans-job-icon' + setting.normal + ' ~ ');
  176. if (!getIframe()[fn[1]] || getIframe().parent().is('.ans-job-finished')) return 0;
  177. if (!setting.queue || $(sel, fn[0].parent.document)[0] == fn[0].frameElement) return 1;
  178. setInterval(function() {
  179. $(sel, fn[0].parent.document)[0] == fn[0].frameElement && fn[0].location.reload();
  180. }, setting.time);
  181. }
  182.  
  183. function getIframe(tip, win, job) {
  184. if (!$) return Ext.get(frameElement || []).parent().child('.ans-job-icon') || Ext.get([]);
  185. do {
  186. win = win ? win.parent : _self;
  187. job = $(win.frameElement).prevAll('.ans-job-icon');
  188. } while (!job.length && win.parent.frameElement);
  189. return tip ? win : job;
  190. }
  191.  
  192. function hookVideoB(el, config) {
  193. var ExtArr = Ext.Array,
  194. line = ExtArr.filter(ExtArr.map(config.playlines, function(value, index) {
  195. return value.label == setting.line && index;
  196. }), function(value) {
  197. return Ext.isNumber(value);
  198. })[0] || 0,
  199. http = ExtArr.filter(config.sources, function(value) {
  200. return value.label == setting.http;
  201. })[0];
  202. config.playlines.unshift(config.playlines[line]);
  203. config.playlines.splice(line + 1, 1);
  204. config.plugins.videoJsResolutionSwitcher.default = http ? http.res : 360;
  205. config.plugins.studyControl.enableSwitchWindow = 1;
  206. config.plugins.timelineObjects.url = '/richvideo/initdatawithviewer?';
  207. config.plugins.seekBarControl.enableFastForward = 1;
  208. config.playbackRates = [1, 1.25, 1.5, 2];
  209. setting.queue || vjs.registerPlugin('studyControl', Ext.emptyFn);
  210. // config.preload = setting.tip ? 'auto' : 'none';
  211. return config;
  212. }
  213.  
  214. function hookVideoS(player) {
  215. var a = '<a href="' + dl + _self.config('objectid') + '" target="_blank">',
  216. img = '<img src="' + dl + 'e363b256c0e9bc5bd8266bf99dd6d6bb" style="margin: 6px 0 0 6px;">';
  217. player.volume(Math.round(setting.vol) / 100 || 0);
  218. Ext.fly(player.controlBar.addChild('Button').el_).setHTML(a + img + '</a>').dom.title = '下载视频';
  219. player.on('loadstart', function() {
  220. getTip() && this.play().catch(Ext.emptyFn);
  221. this.playbackRate(setting.rate > 16 || setting.rate < 0.0625 ? 1 : setting.rate);
  222. });
  223. player.one(['loadedmetadata', 'firstplay'], function() {
  224. setting.two = setting.rate === '0' && setting.two < 1;
  225. setting.two && this.options_.plugins.seekBarControl.sendLog(this.children_[0], 'ended', Math.floor(this.cache_.duration));
  226. });
  227. player.on('ended', function() {
  228. Ext.fly(frameElement).parent().addCls('ans-job-finished');
  229. });
  230. }
  231.  
  232. function hookAudioB(el, config) {
  233. config.plugins.studyControl.enableSwitchWindow = 1;
  234. config.plugins.seekBarControl.enableFastForward = 1;
  235. setting.queue || vjs.registerPlugin('studyControl', Ext.emptyFn);
  236. return config;
  237. }
  238.  
  239. function hookAudioS(player) {
  240. var a = '<a href="' + dl + _self.config('objectid') + '" target="_blank">',
  241. img = '<img src="' + dl + 'e363b256c0e9bc5bd8266bf99dd6d6bb" style="margin: 6px 0 0 6px;">';
  242. player.volume(Math.round(setting.vol) / 100 || 0);
  243. player.playbackRate(setting.rate > 16 || setting.rate < 0.0625 ? 1 : setting.rate);
  244. Ext.fly(player.controlBar.addChild('Button').el_).setHTML(a + img + '</a>').dom.title = '下载音频';
  245. player.on('loadeddata', function() {
  246. getTip() && this.play().catch(Ext.emptyFn);
  247. });
  248. player.one('firstplay', function() {
  249. setting.rate === '0' && this.options_.plugins.seekBarControl.sendLog(this.children_[0], 'ended', Math.floor(this.cache_.duration));
  250. });
  251. player.on('ended', function() {
  252. Ext.fly(frameElement).parent().addCls('ans-job-finished');
  253. });
  254. }
  255.  
  256. function relieveLimit() {
  257. if (setting.scale) _self.UEDITOR_CONFIG.scaleEnabled = false;
  258. $.each(UE.instants, function() {
  259. var key = this.key;
  260. this.ready(function() {
  261. this.destroy();
  262. UE.getEditor(key);
  263. });
  264. });
  265. }
  266.  
  267. function beforeFind() {
  268. setting.regl = parent.greenligth || $.noop;
  269. if ($.type(parent._data) == 'array') return setting.regl();
  270. setting.div = $(
  271. '<div style="border: 2px dashed rgb(0, 85, 68); width: 330px; position: fixed; top: 0; right: 0; z-index: 99999; background-color: rgba(70, 196, 38, 0.6); overflow-x: auto;">' +
  272. '<span style="font-size: medium;"></span>' +
  273. '<div style="font-size: medium;">正在搜索答案...</div>' +
  274. '<button style="margin-right: 10px;">暂停答题</button>' +
  275. '<button style="margin-right: 10px;">' + (setting.auto ? '取消本次自动提交' : '开启本次自动提交') + '</button>' +
  276. '<button style="margin-right: 10px;">重新查询</button>' +
  277. '<button>折叠面板</button>' +
  278. '<div style="max-height: 300px; overflow-y: auto;">' +
  279. '<table border="1" style="font-size: 12px;">' +
  280. '<thead>' +
  281. '<tr>' +
  282. '<th style="width: 25px; min-width: 25px;">题号</th>' +
  283. '<th style="width: 60%; min-width: 130px;">题目(点击可复制)</th>' +
  284. '<th style="min-width: 130px;">答案(点击可复制)</th>' +
  285. '</tr>' +
  286. '</thead>' +
  287. '<tfoot style="display: none;">' +
  288. '<tr>' +
  289. '<th colspan="3">答案提示框 已折叠</th>' +
  290. '</tr>' +
  291. '</tfoot>' +
  292. '<tbody>' +
  293. '<tr>' +
  294. '<td colspan="3" style="display: none;"></td>' +
  295. '</tr>' +
  296. '</tbody>' +
  297. '</table>' +
  298. '</div>' +
  299. '</div>'
  300. ).appendTo('body').on('click', 'button, td', function() {
  301. var len = $(this).prevAll('button').length;
  302. if (this.nodeName == 'TD') {
  303. $(this).prev().length && GM_setClipboard($(this).text());
  304. } else if (!$(this).siblings().length) {
  305. $(this).parent().text('正在搜索答案...');
  306. setting.num++;
  307. } else if (len === 0) {
  308. if (setting.loop) {
  309. clearInterval(setting.loop);
  310. delete setting.loop;
  311. len = ['已暂停搜索', '继续答题'];
  312. } else {
  313. setting.loop = setInterval(findAnswer, setting.time);
  314. len = ['正在搜索答案...', '暂停答题'];
  315. }
  316. setting.div.children('div:eq(0)').html(function() {
  317. return $(this).data('html') || len[0];
  318. }).removeData('html');
  319. $(this).html(len[1]);
  320. } else if (len == 1) {
  321. setting.auto = !setting.auto;
  322. $(this).html(setting.auto ? '取消本次自动提交' : '开启本次自动提交');
  323. } else if (len == 2) {
  324. parent.location.reload();
  325. } else if (len == 3) {
  326. setting.div.find('tbody, tfoot').toggle();
  327. }
  328. }).find('table, td, th').css('border', '1px solid').end();
  329. setting.lose = setting.num = 0;
  330. setting.data = parent._data = [];
  331. setting.over = '<button style="margin-right: 10px;">跳过此题</button>';
  332. setting.curs = $('script:contains(courseName)', top.document).text().match(/courseName:\'(.+?)\'|$/)[1] || $('h1').text().trim() || '无';
  333. setting.loop = setInterval(findAnswer, setting.time);
  334. var tip = ({undefined: '任务点排队中', 0: '等待切换中'})[getTip()];
  335. tip && setting.div.children('div:eq(0)').data('html', tip).siblings('button:eq(0)').click();
  336. }
  337.  
  338. function findAnswer() {
  339. if (setting.num >= $('.TiMu').length) {
  340. var arr = setting.lose ? ['共有 <font color="red">' + setting.lose + '</font> 道题目待完善(已深色标注)', saveThis] : ['答题已完成', submitThis];
  341. setting.div.children('div:eq(0)').data('html', arr[0]).siblings('button:eq(0)').hide().click();
  342. return setTimeout(arr[1], setting.time);
  343. }
  344. var $TiMu = $('.TiMu').eq(setting.num),
  345. question = filterImg($TiMu.find('.Zy_TItle:eq(0) .clearfix')).replace(/^【.*?】\s*/, '').replace(/\s*(\d+\.\d+分)$/, ''),
  346. type = $TiMu.find('input[name^=answertype]:eq(0)').val() || '-1';
  347. GM_xmlhttpRequest({
  348. method: 'POST',
  349. url: 'http://mooc.forestpolice.org/cx/0/' + encodeURIComponent(question),
  350. headers: {
  351. 'Content-type': 'application/x-www-form-urlencoded'
  352. },
  353. data: 'question=' + encodeURIComponent(question) + '&type=' + type,
  354. timeout: setting.time,
  355. onload: function(xhr) {
  356. if (!setting.loop) {
  357. } else if (xhr.status == 200) {
  358. var obj = $.parseJSON(xhr.responseText) || {};
  359. if (obj.code) {
  360. setting.div.children('div:eq(0)').text('正在搜索答案...');
  361. var td = '<td style="border: 1px solid;',
  362. data = String(obj.data).replace(/&/g, '&amp;').replace(/<(?!img)/g, '&lt;');
  363. obj.data = /^http/.test(data) ? '<img src="' + obj.data + '">' : obj.data;
  364. $(
  365. '<tr>' +
  366. td + ' text-align: center;">' + $TiMu.find('.Zy_TItle:eq(0) i').text().trim() + '</td>' +
  367. td + '" title="点击可复制">' + (question.match('<img') ? question : question.replace(/&/g, '&amp;').replace(/</g, '&lt')) + '</td>' +
  368. td + '" title="点击可复制">' + (/^http/.test(data) ? obj.data : '') + data + '</td>' +
  369. '</tr>'
  370. ).appendTo(setting.div.find('tbody')).css('background-color', fillAnswer($TiMu.find('ul:eq(0)').find('li'), obj, type) ? '' : 'rgba(0, 150, 136, 0.6)');
  371. setting.data[setting.num++] = {
  372. code: obj.code > 0 ? 1 : 0,
  373. question: question,
  374. option: obj.data,
  375. type: Number(type)
  376. };
  377. } else {
  378. setting.div.children('div:eq(0)').html(obj.data || setting.over + '服务器繁忙,正在重试...');
  379. }
  380. setting.div.children('span').html(obj.msg || '');
  381. } else if (xhr.status == 403) {
  382. var html = xhr.responseText.indexOf('{') ? '请求过于频繁,建议稍后再试' : $.parseJSON(xhr.responseText).data;
  383. setting.div.children('div:eq(0)').data('html', html).siblings('button:eq(0)').click();
  384. } else {
  385. setting.div.children('div:eq(0)').html(setting.over + '服务器异常,正在重试...');
  386. }
  387. },
  388. ontimeout: function() {
  389. setting.loop && setting.div.children('div:eq(0)').html(setting.over + '服务器超时,正在重试...');
  390. }
  391. });
  392. }
  393.  
  394. function fillAnswer($li, obj, type) {
  395. var $input = $li.find(':radio, :checkbox'),
  396. str = String(obj.data).toCDB() || new Date().toString(),
  397. data = str.split(/#|\x01|\|/),
  398. opt = obj.opt || str,
  399. state = setting.lose;
  400. // $li.find(':radio:checked').prop('checked', false);
  401. obj.code > 0 && $input.each(function(index) {
  402. if (this.value == 'true') {
  403. data.join().match(/(^|,)(正确|是|对|√|T|ri|right|true)(,|$)/) && this.click();
  404. } else if (this.value == 'false') {
  405. data.join().match(/(^|,)(错误|否|错|×|F|wr|wrong|false)(,|$)/) && this.click();
  406. } else {
  407. var tip = filterImg($li.eq(index).find('.after')).toCDB() || new Date().toString();
  408. Boolean($.inArray(tip, data) + 1 || (type == '1' && str.indexOf(tip) + 1)) == this.checked || this.click();
  409. }
  410. }).each(function() {
  411. if (!/^A?B?C?D?E?F?G?$/.test(opt)) return false;
  412. Boolean(opt.match(this.value)) == this.checked || this.click();
  413. });
  414. if (type.match(/^[013]$/)) {
  415. $input.is(':checked') || (setting.none ? ($input[Math.floor(Math.random() * $input.length)] || $()).click() : setting.lose++);
  416. } else if (type.match(/^(2|[4-9]|1[08])$/)) {
  417. data = String(obj.data).split(/#|\x01|\|/);
  418. str = $li.end().find('textarea').each(function(index) {
  419. index = (obj.code > 0 && data[index]) || this.value || '';
  420. UE.getEditor(this.name).setContent(index.trim());
  421. }).length;
  422. (obj.code > 0 && data.length == str) || setting.none || setting.lose++;
  423. } else {
  424. setting.none || setting.lose++;
  425. }
  426. return state == setting.lose;
  427. }
  428.  
  429. function saveThis() {
  430. if (!setting.auto) return setTimeout(saveThis, setting.time);
  431. setting.div.children('button:lt(3)').hide().eq(1).click();
  432. $('#tempsave').click();
  433. setting.regl();
  434. }
  435.  
  436. function submitThis() {
  437. if (!setting.auto) {
  438. } else if (!$('.Btn_blue_1:visible').length) {
  439. setting.div.children('button:lt(3)').hide().eq(1).click();
  440. return setting.regl();
  441. } else if ($('#confirmSubWin:visible').length) {
  442. var btn = $('#tipContent + * > a').offset() || {top: 0, left: 0},
  443. mouse = document.createEvent('MouseEvents');
  444. btn = [btn.left + Math.ceil(Math.random() * 46), btn.top + Math.ceil(Math.random() * 26)];
  445. mouse.initMouseEvent('click', true, true, document.defaultView, 0, 0, 0, btn[0], btn[1], false, false, false, false, 0, null);
  446. _self.event = $.extend(true, {}, mouse);
  447. delete _self.event.isTrusted;
  448. _self.form1submit();
  449. } else {
  450. $('.Btn_blue_1')[0].click();
  451. }
  452. setTimeout(submitThis, Math.ceil(setting.time * Math.random()) * 2);
  453. }
  454.  
  455. function checkToNext() {
  456. var $tip = $(setting.job.join(', '), document).prevAll('.ans-job-icon' + setting.normal);
  457. setInterval(function() {
  458. $tip.parent(':not(.ans-job-finished)').length || setting.jump && toNext();
  459. }, setting.time);
  460. }
  461.  
  462. function toNext() {
  463. var $cur = $('#cur' + $('#chapterIdid').val()),
  464. $tip = $('span.currents ~ span'),
  465. sel = setting.review ? 'html' : '.blue';
  466. if (!$cur.has(sel).length && $tip.length) return $tip.eq(0).click();
  467. $tip = $('.roundpointStudent, .roundpoint').parent();
  468. $tip = $tip.slice($tip.index($cur) + 1).not(':has(' + sel + ')');
  469. $tip.not(setting.lock ? ':has(.lock)' : 'html').find('span').eq(0).click();
  470. $tip.length || setting.course && switchCourse();
  471. }
  472.  
  473. function switchCourse() {
  474. GM_xmlhttpRequest({
  475. method: 'GET',
  476. url: '/visit/courses/study?isAjax=true&fileId=0&debug=',
  477. headers: {
  478. 'Referer': location.origin + '/visit/courses',
  479. 'X-Requested-With': 'XMLHttpRequest'
  480. },
  481. onload: function(xhr) {
  482. var $list = $('.curFile .courseName', xhr.responseText),
  483. index = $list.index($list.filter('[href*="courseid=' + top.courseId + '&"]')) + 1;
  484. index = index && $list.eq(index).attr('href');
  485. setting.course = index && goCourse(index);
  486. }
  487. });
  488. }
  489.  
  490. function goCourse(url) {
  491. GM_xmlhttpRequest({
  492. method: 'GET',
  493. url: url,
  494. onload: function(xhr) {
  495. $.globalEval('location.href = "' + $('.articlename a[href]', xhr.responseText).attr('href') + '";');
  496. }
  497. });
  498. }
  499.  
  500. function autoRead() {
  501. $('html, body').animate({
  502. scrollTop: $(document).height() - $(window).height()
  503. }, Math.round(setting.read) * 1E3, function() {
  504. $('.nodeItem.r i').click();
  505. }).one('click', '#top', function(event) {
  506. $(event.delegateTarget).stop();
  507. });
  508. }
  509.  
  510. function getSchoolId() {
  511. var school = /^1\d{10}$/.test(setting.username) ? '' : setting.school;
  512. if (!isNaN(school)) return setTimeout(toLogin, setting.time, school);
  513. if (school == '账号为手机号可以不修改此参数') return alert('请修改school参数');
  514. $.getJSON('/org/searchUnis?filter=' + encodeURI(school) + '&product=44', function(data) {
  515. if (!data.result) return alert('学校查询错误');
  516. var msg = $.grep(data.froms, function(value) {
  517. return value.name == school;
  518. })[0];
  519. msg ? setTimeout(toLogin, setting.time, msg.schoolid) : alert('学校名称不完整');
  520. });
  521. }
  522.  
  523. function toLogin(fid) {
  524. GM_xmlhttpRequest({
  525. method: 'GET',
  526. url: '/api/login?name=' + setting.username + '&pwd=' + setting.password + '&schoolid=' + fid + '&verify=0',
  527. onload: function(xhr) {
  528. var obj = $.parseJSON(xhr.responseText) || {};
  529. obj.result ? location.href = decodeURIComponent($('[id^=ref]').val()) : alert(obj.errorMsg || 'Error');
  530. }
  531. });
  532. }
  533.  
  534. function submitAnswer($job, data) {
  535. $job.removeClass('ans-job-finished');
  536. data = data.length ? $(data) : $('.TiMu').map(function() {
  537. var title = filterImg($('.Zy_TItle .clearfix', this));
  538. return {
  539. question: title.replace(/^【.*?】\s*/, ''),
  540. type: ({单选题: 0, 多选题: 1, 填空题: 2, 判断题: 3})[title.match(/^【(.*?)】|$/)[1]]
  541. };
  542. });
  543. data = $.grep(data.map(function(index) {
  544. var $TiMu = $('.TiMu').eq(index);
  545. if (!($.isPlainObject(this) && this.type < 4 && $TiMu.find('.fr').length)) {
  546. return false;
  547. } else if (this.type == 2) {
  548. var $ans = $TiMu.find('.Py_tk, .Py_answer').eq(0);
  549. if (!$TiMu.find('.cuo').length && this.code) {
  550. return false;
  551. } else if (!$ans.find('.cuo').length) {
  552. this.option = $ans.find('.clearfix').map(function() {
  553. return filterImg(this);
  554. }).get().join('#') || '无';
  555. } else if (this.code) {
  556. this.code = -1;
  557. } else {
  558. return false;
  559. }
  560. } else if (this.type == 3) {
  561. var ans = $TiMu.find('.font20:last').text();
  562. if ($TiMu.find('.cuo').length) {
  563. this.option = ({'√': '错误', '×': '正确'})[ans] || '无';
  564. } else if (!this.code) {
  565. this.option = ({'√': '正确', '×': '错误'})[ans] || '无';
  566. } else {
  567. return false;
  568. }
  569. } else {
  570. var text = $TiMu.find('.Py_answer > span:eq(0)').text();
  571. if ($TiMu.find('.dui').length && this.code && !/^A?B?C?D?E?F?G?$/.test(this.option)) {
  572. return false;
  573. } else if ($TiMu.find('.dui').length || text.match('正确答案')) {
  574. text = text.match(/[A-G]/gi) || [];
  575. this.option = $.map(text, function(value) {
  576. return filterImg($TiMu.find('.fl:contains(' + value + ') + a'));
  577. }).join('#') || '无';
  578. this.key = text.join('');
  579. } else if (this.code) {
  580. this.code = -1;
  581. } else {
  582. return false;
  583. }
  584. }
  585. return this;
  586. }), function(value) {
  587. return value && value.option != '无';
  588. });
  589. setting.curs = $('script:contains(courseName)', top.document).text().match(/courseName:\'(.+?)\'|$/)[1] || $('h1').text().trim() || '无';
  590. data.length && GM_xmlhttpRequest({
  591. method: 'POST',
  592. url: 'http://mooc.forestpolice.org/upload/cx/0/?workRelationId=' + $('#workId').val(),
  593. headers: {
  594. 'Content-type': 'application/x-www-form-urlencoded'
  595. },
  596. data: 'course=' + encodeURIComponent(setting.curs) + '&data=' + encodeURIComponent((Ext.encode || JSON.stringify)(data)) + '&id=' + $('#jobid').val().slice(5)
  597. });
  598. $job.addClass('ans-job-finished');
  599. }
  600.  
  601. function filterImg(dom) {
  602. return $(dom).clone().find('img[src]').replaceWith(function() {
  603. return $('<p></p>').text('<img src="' + $(this).attr('src') + '">');
  604. }).end().find('iframe[src]').replaceWith(function() {
  605. return $('<p></p>').text('<iframe src="' + $(this).attr('src') + '"></irame>');
  606. }).end().text().trim();
  607. }