// ==UserScript== // @name mooc/优课 查题小组手 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 进入做题界面自动查询答案并且填充内容 // @author shulan // @match http://www.uooc.net.cn/exam/* // @grant unsafeWindow // @grant GM_xmlhttpRequest // @grant window.onload // @grant window.console // @license MIT // @downloadURL none // ==/UserScript== (() => { 'use strict'; var t, n, e = (function () { function n(n, e, o) { void 0 === n && (n = ''), void 0 === e && (e = []), void 0 === o && (o = t.Radio), (this.question = n), (this.options = e), (this.type = o); } return ( (n.prototype.set_answer = function (t) { this.answer = t; }), (n.prototype.match_answer = function (t) { return this.options .map(function (t, n) { return [t, n]; }) .filter(function (n) { var e = n[0]; return t.some(function (t) { return new RegExp(e.body).test(t); }); }) .map(function (t) { return t[0], t[1]; }); }), n ); })(); !(function (t) { (t[(t.Radio = 0)] = 'Radio'), (t[(t.Checkbox = 1)] = 'Checkbox'), (t[(t.Judge = 3)] = 'Judge'), (t[(t.InBlank = 2)] = 'InBlank'); })(t || (t = {})), (function (t) { (t[(t.NOTFOUND = 0)] = 'NOTFOUND'), (t[(t.NOTMATCH = 1)] = 'NOTMATCH'), (t[(t.MATCHED = 2)] = 'MATCHED'); })(n || (n = {})); var o, i = ((o = function (t, n) { return ( (o = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (t, n) { t.__proto__ = n; }) || function (t, n) { for (var e in n) Object.prototype.hasOwnProperty.call(n, e) && (t[e] = n[e]); }), o(t, n) ); }), function (t, n) { if ('function' != typeof n && null !== n) throw new TypeError('Class extends value ' + String(n) + ' is not a constructor or null'); function e() { this.constructor = t; } o(t, n), (t.prototype = null === n ? Object.create(n) : ((e.prototype = n.prototype), new e())); }), r = (function () { function n() {} return ( (n.prototype.parse = function () { return $('.queBox') .map(function (n, e) { return { type: t.Radio, question: $(e).find('.ti-q-c').text(), options: $(e) .find('.ti-alist .ti-a') .map(function (t, n) { var e = $(n), o = e.find('.ti-a-i').text().trim(), i = e.find('.ti-a-c').text().trim(); return { prefix: o.slice(0, o.indexOf('.')), body: i }; }) .toArray(), }; }) .toArray() .map(function (t, n) { return new a(n, { question: t.question, options: t.options, type: t.type }); }); }), n ); })(), a = (function (t) { function n(n, e) { var o = t.call(this, e.question, e.options) || this; return (o.position = n), o; } return ( i(n, t), (n.prototype.select = function () { var t, n = this; 'number' == typeof this.position && (null === (t = this.answer) || void 0 === t || t.map(function (t) { $('.queBox .ti-alist:eq('.concat(n.position, ') .ti-a .ti-a-i [type=radio]:eq(').concat(t, ')')).click(); })); }), n ); })(e); function c(t) { return ( (n = this), (e = void 0), (i = function () { return (function (t, n) { var e, o, i, r, a = { label: 0, sent: function () { if (1 & i[0]) throw i[1]; return i[1]; }, trys: [], ops: [], }; return ( (r = { next: c(0), throw: c(1), return: c(2) }), 'function' == typeof Symbol && (r[Symbol.iterator] = function () { return this; }), r ); function c(r) { return function (c) { return (function (r) { if (e) throw new TypeError('Generator is already executing.'); for (; a; ) try { if ( ((e = 1), o && (i = 2 & r[0] ? o.return : r[0] ? o.throw || ((i = o.return) && i.call(o), 0) : o.next) && !(i = i.call(o, r[1])).done) ) return i; switch (((o = 0), i && (r = [2 & r[0], i.value]), r[0])) { case 0: case 1: i = r; break; case 4: return a.label++, { value: r[1], done: !1 }; case 5: a.label++, (o = r[1]), (r = [0]); continue; case 7: (r = a.ops.pop()), a.trys.pop(); continue; default: if (!((i = (i = a.trys).length > 0 && i[i.length - 1]) || (6 !== r[0] && 2 !== r[0]))) { a = 0; continue; } if (3 === r[0] && (!i || (r[1] > i[0] && r[1] < i[3]))) { a.label = r[1]; break; } if (6 === r[0] && a.label < i[1]) { (a.label = i[1]), (i = r); break; } if (i && a.label < i[2]) { (a.label = i[2]), a.ops.push(r); break; } i[2] && a.ops.pop(), a.trys.pop(); continue; } r = n.call(t, a); } catch (t) { (r = [6, t]), (o = 0); } finally { e = i = 0; } if (5 & r[0]) throw r[1]; return { value: r[0] ? r[1] : void 0, done: !0 }; })([r, c]); }; } })(this, function (n) { return [ 2, new Promise(function (n, e) { GM_xmlhttpRequest({ method: 'POST', url: 'http://cx.icodef.com/wyn-nb', headers: { 'Content-Type': 'application/x-www-form-urlencoded', Authorization: '' }, data: 'question='.concat(encodeURIComponent(t.question)), onload: function (t) { n($.parseJSON(t.responseText) || {}); }, onerror: function (t) { e(t); }, }); }), ]; }); }), new ((o = void 0) || (o = Promise))(function (t, r) { function a(t) { try { s(i.next(t)); } catch (t) { r(t); } } function c(t) { try { s(i.throw(t)); } catch (t) { r(t); } } function s(n) { var e; n.done ? t(n.value) : ((e = n.value), e instanceof o ? e : new o(function (t) { t(e); })).then(a, c); } s((i = i.apply(n, e || [])).next()); }) ); var n, e, o, i; } var s = (function () { function t(t) { this.quetions = t; } return ( (t.from = function (n) { return new t(n.parse()); }), t ); })(), u = (function () { function t() { (this.container = $( '
' )), (this.controller = this.container.find('.controller')), (this.listarea = this.container.find('.list table.listarea')), this.init(); } return ( (t.prototype.init = function () { this.windowController(); }), (t.prototype.appendItem = function (t, e) { var o, i = (((o = {})[n.NOTFOUND] = 'rgba(255, 0, 0, 0.3)'), (o[n.NOTMATCH] = 'rgba(0, 255, 0, 0.3)'), (o[n.MATCHED] = 'rgba(0, 0, 255, 0.3)'), o), r = $( '