超星||学习通超星考试助手(旧版考试)

超星考试助手,支持旧版考试

  1. // ==UserScript==
  2. // @name 超星||学习通超星考试助手(旧版考试)
  3. // @namespace badegg
  4. // @version 1.0.5.1
  5. // @description 超星考试助手,支持旧版考试
  6. // @author wyn665817 & badegg
  7. // @match *://*.chaoxing.com/exam/test/reVersionTestStartNew*
  8. // @match *://*.edu.cn/exam/test/reVersionTestStartNew*
  9. // @match *://*.chaoxing.com/exam-ans/exam/test/reVersionTestStartNew*
  10. // @connect api.caesa.vip
  11. // @connect api.api.thsk.me
  12. // @run-at document-end
  13. // @grant unsafeWindow
  14. // @grant GM_xmlhttpRequest
  15. // @grant GM_setClipboard
  16. // @license MIT
  17. // ==/UserScript==
  18.  
  19. // 设置修改后,需要刷新或重新打开网课页面才会生效
  20. var queryapi = [
  21. //接口可以定义,参数可以自行理解
  22.  
  23. {"url" : "http://api.caesa.vip/cxapi/index.php","postIssueParam":"question","keyParam":"answer","method":"post"},
  24. ];
  25.  
  26.  
  27. var setting = {
  28. api: 0 //默认接口序号(0开始)
  29. // 5E3 == 8000,科学记数法,表示毫秒数
  30. ,
  31. time: 8E3 // 默认响应速度为8秒,不建议小于5秒
  32. // 1代表开启,0代表关闭
  33. ,
  34. none: 1 // 未找到答案或无匹配答案时执行默认操作,默认关闭
  35. ,
  36. jump: 1 // 答题完成后自动切换,默认开启
  37. ,
  38. copy: 0 // 自动复制答案到剪贴板,也可以通过手动点击按钮或答案进行复制,默认关闭
  39.  
  40. // 非自动化操作
  41. ,
  42. hide: 0 // 不加载答案搜索提示框,键盘↑和↓可以临时移除和加载,默认关闭
  43. ,
  44. scale: 0 // 富文本编辑器高度自动拉伸,用于文本类题目,答题框根据内容自动调整大小,默认关闭
  45. },
  46. _self = unsafeWindow,
  47. $ = _self.jQuery,
  48. UE = _self.UE;
  49.  
  50. String.prototype.toCDB = function () {
  51. return this.replace(/\s/g, '').replace(/[\uff01-\uff5e]/g, function (str) {
  52. return String.fromCharCode(str.charCodeAt(0) - 65248);
  53. }).replace(/[“”]/g, '"').replace(/[‘’]/g, "'").replace(/。/g, '.');
  54. };
  55.  
  56. // setting.time += Math.ceil(setting.time * Math.random()) - setting.time / 2;
  57. setting.TiMu = [
  58. filterImg('.Cy_TItle .clearfix').replace(/\s*(\d+\.\d+分)$/, ''),
  59. $('[name^=type]:not([id])').val() || '-1',
  60. $('.cur a').text().trim() || '无',
  61. $('li .clearfix').map(function () {
  62. return filterImg(this);
  63. })
  64. ];
  65.  
  66. setting.div = $(
  67. '<div style="border: 2px dashed rgba(138, 243, 247,0.7); width: 330px; position: fixed; top: 0; right: 0; z-index: 99999; background-color: rgba(197, 252, 255,0.7); overflow-x: auto;">' +
  68. '<span style="font-size: medium;"></span>' +
  69. '<div style="font-size: medium;">正在搜索答案...</div>' +
  70. '<button style="margin-right: 10px;">暂停答题</button>' +
  71. '<button style="margin-right: 10px;' + (setting.jump ? '' : ' display: none;') + '">点击停止本次切换</button>' +
  72. '<button style="margin-right: 10px;">重新查询</button>' +
  73. '<button style="margin-right: 10px; display: none;">复制答案</button>' +
  74. '<button style="margin-right: 10px;">切换接口</button>' +
  75. '<button >答题详情</button>' +
  76. '<div style="max-height: 200px; overflow-y: auto;">' +
  77. '<table border="1" style="font-size: 12px;">' +
  78. '<thead>' +
  79. '<tr>' +
  80. '<th colspan="2">' + ($('#randomOptions').val() == 'false' ? '' : '<font color="red">本次考试的选项为乱序 脚本会选择正确的选项</font>') + '</th>' +
  81. '</tr>' +
  82. '<tr>' +
  83. '<th style="width: 60%; min-width: 130px;">题目(点击可复制)</th>' +
  84. '<th style="min-width: 130px;">答案(点击可复制)</th>' +
  85. '</tr>' +
  86. '</thead>' +
  87. '<tfoot style="' + (setting.jump ? ' display: none;' : '') + '">' +
  88. '<tr>' +
  89. '<th colspan="2">已关闭 本次自动切换</th>' +
  90. '</tr>' +
  91. '</tfoot>' +
  92. '<tbody>' +
  93. '<tr>' +
  94. '<td colspan="2" style="display: none;"></td>' +
  95. '</tr>' +
  96. '</tbody>' +
  97. '</table>' +
  98. '</div>' +
  99. '</div>'
  100. ).appendTo('body').on('click', 'button, td', function () {
  101. var num = setting.$btn.index(this);
  102. if (num == -1) {
  103. GM_setClipboard($(this).text());
  104. }
  105. else if (num === 0) {
  106. if (setting.loop) {
  107. clearInterval(setting.loop);
  108. delete setting.loop;
  109. num = ['已暂停搜索', '继续答题'];
  110. }
  111. else {
  112. setting.loop = setInterval(findTiMu, setting.time);
  113. num = ['正在搜索答案...', '暂停答题'];
  114. }
  115. setting.$div.html(function () {
  116. return $(this).data('html') || num[0];
  117. }).removeData('html');
  118. $(this).html(num[1]);
  119. }
  120. else if (num == 1) {
  121. setting.jump = 0;
  122. setting.$div.html(function () {
  123. return arguments[1].replace('即将切换下一题', '未开启自动切换');
  124. });
  125. setting.div.find('tfoot').add(this).toggle();
  126. }
  127. else if (num == 2) {
  128. location.reload();
  129. }
  130. else if (num == 3) {
  131. GM_setClipboard(setting.div.find('td:last').text());
  132. }
  133. else if (num == 4) {
  134. setting.api < queryapi.length - 1 ? setting.api += 1 : setting.api = 0;
  135. $(this).html('切换接口,当前:' + setting.api);
  136. //重新请求
  137. clearInterval(setting.loop);
  138. delete setting.loop;
  139. setting.loop = setInterval(findTiMu, setting.time);
  140. //num = ['正在搜索答案...', '暂停答题'];
  141. }
  142. else if (num == 5) {
  143. ($('.leftCard .saveYl')[0] || $()).click();
  144. }
  145. }).detach(setting.hide ? '*' : 'html');
  146. setting.$btn = setting.div.children('button');
  147. setting.$div = setting.div.children('div:eq(0)');
  148.  
  149. $(document).keydown(function (event) {
  150. if (event.keyCode == 38) {
  151. setting.div.detach();
  152. }
  153. else if (event.keyCode == 40) {
  154. setting.div.appendTo('body');
  155. }
  156. });
  157.  
  158. if (setting.scale) _self.UEDITOR_CONFIG.scaleEnabled = false;
  159. $.each(UE.instants, function () {
  160. var key = this.key;
  161. this.ready(function () {
  162. this.destroy();
  163. UE.getEditor(key);
  164. });
  165. });
  166. setting.loop = setInterval(findTiMu, setting.time);
  167.  
  168. function findTiMu() {
  169. GM_xmlhttpRequest({
  170. method: 'POST',
  171. url: 'http://api.caesa.vip/cxapi/index.php',
  172. headers: {
  173. 'Content-type': 'application/x-www-form-urlencoded'
  174. },
  175. data: queryapi[setting.api].postIssueParam + '=' + encodeURIComponent(setting.TiMu[0]) + '&type=' + setting.TiMu[1],
  176. timeout: setting.time,
  177. onload: function (xhr) {
  178. if (!setting.loop) {}
  179. else if (xhr.status == 200) {
  180. var obj = $.parseJSON(xhr.responseText) || {};
  181. if (obj.answer) {}
  182. else obj.answer = obj.data || obj.answer;
  183. obj.code = obj.code == null ? 1 : obj.code;
  184. if (obj.code == 1 || obj.tm) {
  185. var data = String(obj.answer).replace(/&/g, '&amp;').replace(/<(?!img)/g, '&lt;'),
  186. que = setting.TiMu[0].match('<img') ? setting.TiMu[0] : setting.TiMu[0].replace(/&/g, '&amp;').replace(/</g, '&lt');
  187. obj.answer = /^http/.test(data) ? '<img src="' + obj.answer + '">' : obj.answer;
  188. setting.div.find('tbody').append(
  189. '<tr>' +
  190. '<td title="点击可复制">' + que + '</td>' +
  191. '<td title="点击可复制">' + (/^http/.test(data) ? obj.answer : '') + data + '</td>' +
  192. '</tr>'
  193. );
  194. setting.copy && GM_setClipboard(obj.answer);
  195. setting.$btn.eq(3).show();
  196. fillAnswer(obj);
  197. }
  198. else {
  199. setting.$div.html(obj.data || '服务器繁忙,正在重试...');
  200. }
  201. setting.div.children('span').html(obj.msg || '');
  202. }
  203. else if (xhr.status == 403) {
  204. var html = xhr.responseText.indexOf('{') ? '请求过于频繁,建议稍后再试' : $.parseJSON(xhr.responseText).data;
  205. setting.$div.data('html', html).siblings('button:eq(0)').click();
  206. }
  207. else {
  208. setting.$div.text('服务器异常,正在重试...');
  209. }
  210. },
  211. ontimeout: function () {
  212. setting.loop && setting.$div.text('服务器超时,正在重试...');
  213. }
  214. });
  215. }
  216.  
  217. function fillAnswer(obj, tip) {
  218. var $input = $(':radio, :checkbox', '.Cy_ulBottom'),
  219. str = String(obj.answer).toCDB() || new Date().toString(),
  220. data = str.split(/#|\x01|\|/),
  221. opt = obj.opt || str,
  222. btn = $('.saveYl:contains(下一题)').offset();
  223. // $input.filter(':radio:checked').prop('checked', false);
  224. obj.code > 0 && $input.each(function (index) {
  225. if (this.value == 'true') {
  226. data.join().match(/(^|,)(正确|是|对|√|T|ri)(,|$)/) && this.click();
  227. }
  228. else if (this.value == 'false') {
  229. data.join().match(/(^|,)(错误|否|错|×|F|wr)(,|$)/) && this.click();
  230. }
  231. else {
  232. index = setting.TiMu[3][index].toCDB() || new Date().toString();
  233. index = $.inArray(index, data) + 1 || (setting.TiMu[1] == '1' && str.indexOf(index) + 1);
  234. Boolean(index) == this.checked || this.click();
  235. }
  236. }).each(function () {
  237. if (!/^A?B?C?D?E?F?G?$/.test(opt)) return false;
  238. Boolean(opt.match(this.value)) == this.checked || this.click();
  239. });
  240. if (setting.TiMu[1].match(/^[013]$/)) {
  241. tip = $input.is(':checked') || setting.none && (($input[Math.floor(Math.random() * $input.length)] || $()).click(), ' ');
  242. }
  243. else if (setting.TiMu[1].match(/^(2|[4-9]|1[08])$/)) {
  244. data = String(obj.data).split(/#|\x01|\|/);
  245. tip = $('.Cy_ulTk textarea').each(function (index) {
  246. index = (obj.code > 0 && data[index]) || '';
  247. UE.getEditor(this.name).setContent(index.trim());
  248. }).length;
  249. tip = (obj.code > 0 && data.length == tip) || setting.none && ' ';
  250. setting.len = str.length * setting.time / 10;
  251. }
  252. if (tip == ' ') {
  253. tip = '已执行默认操作';
  254. }
  255. else if (tip) {
  256. tip = '自动答题已完成';
  257. }
  258. else if (tip === undefined) {
  259. tip = '该题型不支持自动答题';
  260. }
  261. else {
  262. tip = '未找到有效答案';
  263. }
  264. if (btn) {
  265. tip += setting.jump ? ',即将切换下一题' : ',未开启自动切换';
  266. setInterval(function () {
  267. if (!setting.jump) return;
  268. var mouse = document.createEvent('MouseEvents'),
  269. arr = [btn.left + Math.ceil(Math.random() * 80), btn.top + Math.ceil(Math.random() * 26)];
  270. mouse.initMouseEvent('click', true, true, document.defaultView, 0, 0, 0, arr[0], arr[1], false, false, false, false, 0, null);
  271. _self.event = $.extend(true, {}, mouse);
  272. delete _self.event.isTrusted;
  273. _self.getTheNextQuestion(1);
  274. }, setting.len || Math.ceil(setting.time * Math.random()) * 2);
  275. }
  276. else {
  277. setting.$btn.eq(1).hide();
  278. tip = '答题已完成,请自行查看答题详情';
  279. }
  280. setting.$div.data('html', tip).siblings('button:eq(0)').hide().click();
  281. }
  282.  
  283. function filterImg(dom) {
  284. return $(dom).clone().find('img[src]').replaceWith(function () {
  285. return $('<p></p>').text('<img src="' + $(this).attr('src') + '">');
  286. }).end().find('iframe[src]').replaceWith(function () {
  287. return $('<p></p>').text('<iframe src="' + $(this).attr('src') + '"></irame>');
  288. }).end().text().trim();
  289. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址