// ==UserScript== // @name 超星慕课小工具 // @namespace https://github.com/CodFrm/cxmooc-tools // @version 2.5.0 // @description 一个超星慕课刷课工具,火狐,谷歌,油猴支持.全自动任务,视频倍速秒过,作业考试题库,验证码自动打码(੧ᐛ੭挂科模式,启动) // @author CodFrm // @run-at document-start // @match *://*/mycourse/studentstudy?* // @match *://*/ztnodedetailcontroller/visitnodedetail?* // @match *://*/antispiderShowVerify.ac* // @match *://*/html/processVerify.ac?* // @match *://*/exam/test/reVersionPaperMarkContentNew?* // @match *://*/exam/test/reVersionTestStartNew?* // @match *://*/work/selectWorkQuestionYiPiYue?* // @match *://*/work/doHomeWorkNew?* // @match *://*/ananas/modules/*/index.html?* // @match *://*/exam/test?* // @match *://*/course/*.html?* // @grant GM_xmlhttpRequest // @grant GM_notification // @grant unsafeWindow // @license MIT // ==/UserScript== let config = { answer_ignore: true, //忽略题目,勾选此处将不会答题 auto: true, //全自动挂机,无需手动操作,即可自动观看视频等 interval: 1, //时间间隔,当任务点完成后,会等待1分钟然后跳转到下一个任务点 rand_answer: false, //随机答案,没有答案的题目将自动的生成一个答案 video_multiple: 1, //视频播放倍速,视频播放的倍数,建议不要改动,为1即可,这是危险的功能 video_mute: true, //视频静音,视频自动静音播放 video_cdn: "公网1", //锁定视频播放源,为空为记录最后一次选中的源(公网1,公网2等) super_mode: true, //解锁flash弹幕视频等,详情请看文档 topic_interval: 5,//题目答题间隔,单位为秒 vtoken: "", }; Object.keys(config).forEach(k => { localStorage[k] = config[k]; }); /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./src/tampermonkey/cxmooc-pack.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "./src/config.ts": /*!***********************!*\ !*** ./src/config.ts ***! \***********************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemConfig = void 0; var SystemConfig = /** @class */ (function () { function SystemConfig() { } SystemConfig.version = 2.5; SystemConfig.url = "https://cx.icodef.com/"; SystemConfig.hotVersion = "2.5.0"; //TODO:优化规则,可以通过ci自动生成匹配规则到tampermonkey和manifest文件中 SystemConfig.match = { "cx": [ "*://*/mycourse/studentstudy?*", "*://*/work/doHomeWorkNew?*", "*://*/work/selectWorkQuestionYiPiYue?*", "*://*/exam/test/reVersionTestStartNew?*", "*://*/ztnodedetailcontroller/visitnodedetail?*", "*://*/antispiderShowVerify.ac*", "*://*/html/processVerify.ac?*", "*://*/exam/test/reVersionPaperMarkContentNew?*", "*://*/ananas/modules/*/index.html?*", "*://*/exam/test?*", "*://*/course/*.html?*" ], "zhs": [ "*://examh5.zhihuishu.com/stuExamWeb.html*", "*://onlineexamh5new.zhihuishu.com/stuExamWeb.html*", "*://studyh5.zhihuishu.com/videoStudy.html*", ], "mooc163": [ "*://www.icourse163.org/learn/*", "*://www.icourse163.org/spoc/learn/*" ] }; SystemConfig.config = { cx: { name: "超星", items: [{ title: "随机答案", description: "如果题库没有正确的答案会随机选择", type: "checkbox", key: "rand_answer", value: false, }, { title: "自动挂机", description: "进入一个页面就会自动开始挂机,完成一个任务之后会自动进行下一个", type: "checkbox", key: "auto", value: true, }, { title: "视频静音", description: "播放视频时,自动开启静音", type: "checkbox", key: "video_mute", value: true, }, { title: "忽略题目", description: "自动挂机时,忽略掉题目不做,直接跳过", type: "checkbox", key: "answer_ignore", value: false, }, { title: "超级模式", description: "超星平台下,超级模式会自动将flash播放器换成h5播放器", type: "checkbox", key: "super_mode", value: true, }, { title: "播放源", description: "锁定视频播放源,为空为记录最后一次选中的源(公网1,公网2等)", type: "text", key: "video_cdn", value: "默认" }, { title: "播放倍速", description: "视频播放的倍数,1为正常速度(最高16倍,该功能有一定危险)", type: "text", key: "video_multiple", prompt: "这是一个很危险的功能,建议不要进行调整,如果你想调整播放速度请在下方填写yes(智慧树平台播放速度和视频进度无关,最高只能1.5倍速)", unit: "倍", value: "1", }, { title: "跳转间隔", description: "视频(题目,任务点)完成后n分钟再继续下一个任务,可以有小数点,例如:0.5=30秒", type: "text", key: "interval", unit: "分", value: "1", }, { title: "做题间隔", description: "每一道题之间填写答案的时间间隔", type: "text", key: "topic_interval", unit: "秒", value: "5", }], }, zhs: { name: "智慧树", items: [{ title: "随机答案", description: "如果题库没有正确的答案会随机选择", type: "checkbox", key: "rand_answer", value: false, }, { title: "自动挂机", description: "进入一个页面就会自动开始挂机,完成一个任务之后会自动进行下一个", type: "checkbox", key: "auto", value: true, }, { title: "视频静音", description: "播放视频时,自动开启静音", type: "checkbox", key: "video_mute", value: true, }, { title: "超级模式", description: "智慧树平台下,超级模式会让任务完成的倍速成真", type: "checkbox", key: "super_mode", value: true, }, { title: "播放倍速", description: "视频播放的倍数,1为正常速度(最高16倍,该功能有一定危险)", type: "text", key: "video_multiple", prompt: "这是一个很危险的功能,建议不要进行调整,如果你想调整播放速度请在下方填写yes(智慧树平台播放速度和视频进度无关,最高只能1.5倍速)", unit: "倍", value: "1", }, { title: "跳转间隔", description: "视频完成后n分钟再继续播放下一个,可以有小数点,例如:0.5=30秒", type: "text", key: "interval", unit: "分", value: "1", }, { title: "做题间隔", description: "每一道题之间填写答案的时间间隔", type: "text", key: "topic_interval", unit: "秒", value: "5", }], }, mooc163: { name: "中国大学MOOC", items: [{ title: "随机答案", description: "如果题库没有正确的答案会随机选择", type: "checkbox", key: "rand_answer", value: false, }, { title: "自动挂机", description: "进入一个页面就会自动开始挂机,完成一个任务之后会自动进行下一个", type: "checkbox", key: "auto", value: true, }, { title: "视频静音", description: "播放视频时,自动开启静音", type: "checkbox", key: "video_mute", value: true, }, { title: "忽略题目", description: "自动挂机时,忽略掉题目不做,直接跳过", type: "checkbox", key: "answer_ignore", value: false, }, { title: "播放倍速", description: "视频播放的倍数,1为正常速度(最高16倍,该功能有一定危险)", type: "text", key: "video_multiple", prompt: "这是一个很危险的功能,建议不要进行调整,如果你想调整播放速度请在下方填写yes(智慧树平台播放速度和视频进度无关,最高只能1.5倍速)", unit: "倍", value: "1", }, { title: "跳转间隔", description: "视频完成后n分钟再继续播放下一个,可以有小数点,例如:0.5=30秒", type: "text", key: "interval", unit: "分", value: "1", }, { title: "做题间隔", description: "每一道题之间填写答案的时间间隔", type: "text", key: "topic_interval", unit: "秒", value: "5", }], }, }; return SystemConfig; }()); exports.SystemConfig = SystemConfig; /***/ }), /***/ "./src/internal/app/question.ts": /*!**************************************!*\ !*** ./src/internal/app/question.ts ***! \**************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ToolsQuestionBankFacade = exports.ToolsQuestionBank = exports.SwitchTopicType = exports.QuestionStatusString = exports.TopicStatusString = exports.PushAnswer = void 0; var utils_1 = __webpack_require__(/*! ../utils/utils */ "./src/internal/utils/utils.ts"); var config_1 = __webpack_require__(/*! @App/config */ "./src/config.ts"); var application_1 = __webpack_require__(/*! ../application */ "./src/internal/application.ts"); var PushAnswer = /** @class */ (function () { function PushAnswer() { } PushAnswer.prototype.Equal = function (content1, content2) { return content1 == content2; }; return PushAnswer; }()); exports.PushAnswer = PushAnswer; var topicStatusMap = new Map(); topicStatusMap.set("ok", "搜索成功").set("random", "随机答案").set("no_support_random", "不支持的随机答案类型").set("no_answer", "题库中没有搜索到答案").set("no_match", "题库中没有符合的答案"); var questionStatusMap = new Map(); questionStatusMap.set("success", "搜索成功").set("network", "题库网络错误").set("incomplete", "题库不全").set("processing", "搜索中..."); function TopicStatusString(status) { return topicStatusMap.get(status) || "未知错误"; } exports.TopicStatusString = TopicStatusString; function QuestionStatusString(status) { return questionStatusMap.get(status) || "未知错误"; } exports.QuestionStatusString = QuestionStatusString; function SwitchTopicType(title) { switch (title) { case "单选题": { return 1; } case "多选题": { return 2; } case "判断题": { return 3; } case "填空题": { return 4; } default: { return null; } } } exports.SwitchTopicType = SwitchTopicType; // 小工具题库 var ToolsQuestionBank = /** @class */ (function () { function ToolsQuestionBank(platform, info) { this.platform = platform; this.info = info; } ToolsQuestionBank.prototype.SetInfo = function (info) { this.info = info; }; ToolsQuestionBank.prototype.GetInfo = function () { return encodeURIComponent(JSON.stringify(this.info)); }; ToolsQuestionBank.prototype.Answer = function (topic, resolve) { var _this = this; application_1.Application.App.log.Debug("答案查询", topic); var num = 20; var answer = new Array(); var retStatus = "success"; var next = function (index) { var body = "info=" + _this.GetInfo() + "&"; var t = index; for (; t < index + num && t < topic.length; t++) { var val = topic[t]; body += "topic[" + (t - index) + "]=" + encodeURIComponent((val.topic)) + "&type[" + (t - index) + "]=" + val.type + "&"; } utils_1.HttpUtils.HttpPost(config_1.SystemConfig.url + "v2/answer?platform=" + _this.platform, body, { headers: { "Authorization": application_1.Application.App.config.vtoken, "X-Version": config_1.SystemConfig.version.toString(), }, json: true, success: function (result) { return __awaiter(_this, void 0, void 0, function () { var status, tmpResult, i, val; return __generator(this, function (_a) { switch (_a.label) { case 0: status = "success"; tmpResult = new Array(); for (i = 0; i < result.length; i++) { if (result[i].result == undefined || result[i].result.length <= 0) { tmpResult.push({ index: index + result[i].index, topic: result[i].topic, type: -1, status: "no_answer", answers: null, correct: null, Equal: this.Equal, }); status = "incomplete"; continue; } val = result[i].result[0]; tmpResult.push({ index: index + result[i].index, topic: val.topic, type: val.type, correct: val.correct, status: "ok", Equal: this.Equal, }); } answer = answer.concat(tmpResult); if (status != "success") { retStatus = status; } return [4 /*yield*/, resolve({ status: "processing", answer: tmpResult })]; case 1: _a.sent(); if (t < topic.length) { next(t); } else { return [2 /*return*/, resolve({ status: retStatus, answer: answer })]; } return [2 /*return*/]; } }); }); }, error: function () { return resolve({ status: "network", answer: answer }); } }); }; next(0); }; ToolsQuestionBank.prototype.Push = function (answer) { var _this = this; return new Promise(function (resolve) { application_1.Application.App.log.Debug("采集提交", answer); utils_1.HttpUtils.HttpPost(config_1.SystemConfig.url + "answer?platform=" + _this.platform, "info=" + _this.GetInfo() + "&data=" + encodeURIComponent(JSON.stringify(answer)), { headers: { "Authorization": application_1.Application.App.config.vtoken, "X-Version": config_1.SystemConfig.version.toString(), }, json: true, success: function (result) { application_1.Application.App.log.Info("答案自动记录成功,成功获得" + result.add_token_num + "个打码数,剩余数量:" + result.token_num); resolve("success"); }, error: function () { resolve("network"); } }); }); }; ToolsQuestionBank.prototype.Equal = function (content1, content2) { return utils_1.removeHTML(content1) == utils_1.removeHTML(content2); }; ToolsQuestionBank.prototype.CheckCourse = function (info) { var _this = this; return new Promise(function (resolve) { info = info || [_this.info]; utils_1.HttpUtils.HttpPost(config_1.SystemConfig.url + "v2/check?platform=" + _this.platform, "info=" + encodeURIComponent(JSON.stringify(info)), { headers: { "Authorization": application_1.Application.App.config.vtoken, "X-Version": config_1.SystemConfig.version.toString(), }, success: function () { resolve(0); }, error: function () { resolve(-1); } }); resolve(); }); }; return ToolsQuestionBank; }()); exports.ToolsQuestionBank = ToolsQuestionBank; var ToolsQuestionBankFacade = /** @class */ (function () { function ToolsQuestionBankFacade(platform, info) { if (typeof platform == "string") { this.bank = new ToolsQuestionBank(platform, info); } else { this.bank = platform; } this.question = new Array(); } ToolsQuestionBankFacade.prototype.ClearQuestion = function () { this.question = new Array(); }; ToolsQuestionBankFacade.prototype.AddQuestion = function (q) { this.question.push(q); }; ToolsQuestionBankFacade.prototype.Answer = function (callback) { var _this = this; var topic = new Array(); this.question.forEach(function (val) { var type = val.GetType(); if (type == -1) { return; } topic.push({ topic: (val.GetTopic()), type: type, }); }); var status = "success"; this.bank.Answer(topic, function (ret) { return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { var t, i, answer, question, tmpStatus; return __generator(this, function (_a) { switch (_a.label) { case 0: if (ret.status != "processing") { application_1.Application.App.log.Debug("题库返回", ret); if (ret.status != "success" || status == "success") { callback(ret.status); return [2 /*return*/, resolve()]; } callback(status); return [2 /*return*/, resolve()]; } t = application_1.Application.App.config.topic_interval * 1000; i = 0; _a.label = 1; case 1: if (!(i < ret.answer.length)) return [3 /*break*/, 11]; answer = ret.answer[i]; question = this.question[answer.index]; tmpStatus = answer.status; if (!(answer.status == "no_answer")) return [3 /*break*/, 3]; status = this.randAnswer(status, tmpStatus, question); return [4 /*yield*/, utils_1.Sleep(t)]; case 2: _a.sent(); return [3 /*break*/, 10]; case 3: if (!(answer.type != question.GetType())) return [3 /*break*/, 4]; tmpStatus = "no_match"; return [3 /*break*/, 6]; case 4: return [4 /*yield*/, question.Fill(answer)]; case 5: tmpStatus = _a.sent(); _a.label = 6; case 6: if (!(tmpStatus == "no_match")) return [3 /*break*/, 8]; status = this.randAnswer(status, tmpStatus, question); return [4 /*yield*/, utils_1.Sleep(t)]; case 7: _a.sent(); return [3 /*break*/, 10]; case 8: question.SetStatus(tmpStatus); if (!(i < ret.answer.length - 1)) return [3 /*break*/, 10]; return [4 /*yield*/, utils_1.Sleep(t)]; case 9: _a.sent(); _a.label = 10; case 10: i++; return [3 /*break*/, 1]; case 11: return [2 /*return*/, resolve()]; } }); }); }); }); }; ToolsQuestionBankFacade.prototype.randAnswer = function (status, tmpStatus, question) { if (application_1.Application.App.config.rand_answer) { tmpStatus = question.Random(); } else { status = "incomplete"; } if (tmpStatus == "no_support_random") { status = "incomplete"; } question.SetStatus(tmpStatus); return status; }; ToolsQuestionBankFacade.prototype.Push = function (callback) { var answer = new Array(); this.question.forEach(function (val) { var correct = val.Correct(); if (correct == null || correct.correct == null || correct.type == -1) { return; } answer.push(correct); }); this.bank.Push(answer).then(function (ret) { application_1.Application.App.log.Debug("题库返回", ret); return callback(ret); }); }; ToolsQuestionBankFacade.prototype.dealOption = function (options) { for (var i = 0; i < options.length; i++) { if (typeof options[i].content == "string") { options[i].content = (options[i].content); } } return options; }; ToolsQuestionBankFacade.prototype.CheckCourse = function () { return this.bank.CheckCourse(); }; return ToolsQuestionBankFacade; }()); exports.ToolsQuestionBankFacade = ToolsQuestionBankFacade; /***/ }), /***/ "./src/internal/app/task.ts": /*!**********************************!*\ !*** ./src/internal/app/task.ts ***! \**********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Task = void 0; var event_1 = __webpack_require__(/*! @App/internal/utils/event */ "./src/internal/utils/event.ts"); var Task = /** @class */ (function (_super) { __extends(Task, _super); function Task() { return _super !== null && _super.apply(this, arguments) || this; } // 初始化任务 Task.prototype.Init = function () { return new Promise(function (resolve) { return resolve(); }); }; // 提交任务,例如topic的类型,可以在本接口内进行提交操作 Task.prototype.Submit = function () { return new Promise(function (resolve) { return resolve(); }); }; // 停止任务 Task.prototype.Stop = function () { return new Promise(function (resolve) { return resolve(); }); }; // 任务的上下文(对于某些iframe的可能会用到) Task.prototype.Context = function () { return window; }; return Task; }(event_1.EventListener)); exports.Task = Task; /***/ }), /***/ "./src/internal/app/topic.ts": /*!***********************************!*\ !*** ./src/internal/app/topic.ts ***! \***********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Topic = void 0; var application_1 = __webpack_require__(/*! ../application */ "./src/internal/application.ts"); var config_1 = __webpack_require__(/*! @App/config */ "./src/config.ts"); // 题目任务点 var Topic = /** @class */ (function () { function Topic(content, answer) { this.answer = answer; this.context = content; } Topic.prototype.SetQueryQuestions = function (queryQuestions) { this.queryQuestions = queryQuestions; }; Topic.prototype.addQuestion = function () { var _this = this; var questions = this.queryQuestions.QueryQuestions(); this.answer.ClearQuestion(); questions.forEach(function (val) { _this.answer.AddQuestion(val); }); }; Topic.prototype.QueryAnswer = function () { var _this = this; return new Promise(function (resolve) { if (_this.lock) { return resolve("processing"); } _this.lock = true; application_1.Application.App.log.Info("题目搜索中..."); _this.addQuestion(); _this.answer.Answer(function (status) { _this.lock = false; resolve(status); if (status == "network") { return application_1.Application.App.log.Error("题库无法访问,请查看:" + config_1.SystemConfig.url); } else if (status == "incomplete") { return application_1.Application.App.log.Warn("题库答案不全,请手动填写操作"); } }); }); }; Topic.prototype.CollectAnswer = function () { var _this = this; return new Promise(function (resolve) { application_1.Application.App.log.Debug("收集题目答案", _this.context); _this.addQuestion(); _this.answer.Push(function (status) { application_1.Application.App.log.Debug("采集答案返回", status); resolve(); }); }); }; return Topic; }()); exports.Topic = Topic; /***/ }), /***/ "./src/internal/app/vcode.ts": /*!***********************************!*\ !*** ./src/internal/app/vcode.ts ***! \***********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VCode = void 0; var utils_1 = __webpack_require__(/*! @App/internal/utils/utils */ "./src/internal/utils/utils.ts"); var config_1 = __webpack_require__(/*! @App/config */ "./src/config.ts"); var application_1 = __webpack_require__(/*! ../application */ "./src/internal/application.ts"); var VCode = /** @class */ (function () { function VCode(listen) { this.listen = listen; } VCode.prototype.Init = function () { var _this = this; this.listen.Listen(function (fill) { application_1.Application.App.log.Info("准备进行打码"); _this.getVcode(fill); }); }; VCode.prototype.getVcode = function (fill) { var img = fill.GetImage(); var base64 = ""; if (typeof img == "string") { base64 = img; } else { base64 = utils_1.getImageBase64(img, 'jpeg'); } utils_1.HttpUtils.HttpPost(config_1.SystemConfig.url + 'vcode', 'img=' + encodeURIComponent(base64.substr('data:image/jpeg;base64,'.length)), { headers: { "Authorization": application_1.Application.App.config.vtoken, "X-Version": config_1.SystemConfig.version.toString(), }, json: false, success: function (ret) { var json = JSON.parse(ret); application_1.Application.App.log.Debug(json); if (json.code == -2) { fill.Fill("error", json.msg, ""); } else if (json.code == -1) { fill.Fill("error", "打码服务器发生错误", ""); } else if (json.msg) { fill.Fill("ok", "打码成功", json.msg); } else { fill.Fill("error", "未知错误", ""); } }, error: function () { fill.Fill("network", "网络请求失败", ""); } }); }; return VCode; }()); exports.VCode = VCode; /***/ }), /***/ "./src/internal/application.ts": /*!*************************************!*\ !*** ./src/internal/application.ts ***! \*************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Application = exports.AppName = exports.Content = exports.Frontend = exports.Backend = void 0; var message_1 = __webpack_require__(/*! ./utils/message */ "./src/internal/utils/message.ts"); var utils_1 = __webpack_require__(/*! ./utils/utils */ "./src/internal/utils/utils.ts"); var config_1 = __webpack_require__(/*! @App/config */ "./src/config.ts"); exports.Backend = "backend"; exports.Frontend = "frontend"; exports.Content = "content"; exports.AppName = "cxmooc-tools"; var Application = /** @class */ (function () { function Application(runEnv, launcher, component) { Application.app = this; Application.runEnv = runEnv; this.runEnvSwitch(runEnv); this.launcher = launcher; this.component = component; } Object.defineProperty(Application, "App", { get: function () { return Application.app; }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "debug", { get: function () { return "development" == "development"; }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "prod", { get: function () { return "development" == "production"; }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "config", { get: function () { return this.component.get("config"); }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "log", { get: function () { return this.component.get("logger"); }, enumerable: false, configurable: true }); Application.prototype.run = function () { this.launcher.start(); }; Object.defineProperty(Application.prototype, "IsFrontend", { get: function () { return Application.IsFrontend; }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "IsBackend", { get: function () { return Application.IsBackend; }, enumerable: false, configurable: true }); Object.defineProperty(Application.prototype, "IsContent", { get: function () { return Application.IsContent; }, enumerable: false, configurable: true }); Application.prototype.runEnvSwitch = function (env) { switch (env) { case exports.Frontend: Application.IsFrontend = true; break; case exports.Backend: Application.IsBackend = true; break; case exports.Content: Application.IsContent = true; break; } ; }; Object.defineProperty(Application.prototype, "Client", { get: function () { if (Application.IsFrontend) { return message_1.NewChromeClientMessage(exports.AppName); } return message_1.NewExtensionClientMessage(exports.AppName); }, enumerable: false, configurable: true }); Application.CheckUpdate = function (callback) { if (Application.IsContent) { chrome.storage.local.get(["version", "enforce", "hotversion", "url"], function (item) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, callback((config_1.SystemConfig.version < item.version), item)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); return; } utils_1.HttpUtils.HttpGet(config_1.SystemConfig.url + "update?ver=" + config_1.SystemConfig.version, { json: true, success: function (json) { return __awaiter(this, void 0, void 0, function () { var data; return __generator(this, function (_a) { switch (_a.label) { case 0: data = { version: json.version, url: json.url, enforce: json.enforce, hotversion: json.hotversion, injection: json.injection, }; chrome.storage && chrome.storage.local.set(data); return [4 /*yield*/, callback((config_1.SystemConfig.version < data.version), data)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }, error: function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, callback(false, undefined)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); } }); }; return Application; }()); exports.Application = Application; /***/ }), /***/ "./src/internal/utils/config.ts": /*!**************************************!*\ !*** ./src/internal/utils/config.ts ***! \**************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.NewFrontendGetConfig = exports.NewBackendConfig = exports.ChromeConfigItems = void 0; var utils_1 = __webpack_require__(/*! ./utils */ "./src/internal/utils/utils.ts"); var application_1 = __webpack_require__(/*! ../application */ "./src/internal/application.ts"); var config_1 = __webpack_require__(/*! @App/config */ "./src/config.ts"); // 缓存默认值 var configDefaultValue = new Map(); configDefaultValue.set("vtoken", ""); for (var key in config_1.SystemConfig.config) { for (var i = 0; i < config_1.SystemConfig.config[key].items.length; i++) { configDefaultValue.set(key + "_" + config_1.SystemConfig.config[key].items[i].key, config_1.SystemConfig.config[key].items[i].value); } } var ChromeConfigItems = /** @class */ (function () { function ChromeConfigItems(config) { var _this = this; this.Namespace = ""; this.config = config; var list = []; configDefaultValue.forEach(function (val, key) { list.push(key); }); this.config.Watch(list, function (key, val) { _this.localCache[key] = val; }); this.localCache = localStorage; } // 设置配置的命名空间,储存格式为 namepace_configkey ChromeConfigItems.prototype.SetNamespace = function (namespace) { this.Namespace = namespace + "_"; }; ChromeConfigItems.prototype.ConfigList = function () { return this.config.ConfigList(); }; ChromeConfigItems.prototype.SetNamespaceConfig = function (namespace, key, val) { return this.config.SetConfig(namespace + "_" + key, val); }; ChromeConfigItems.prototype.GetNamespaceConfig = function (namespace, key, defaultVal) { return this.config.GetConfig(namespace + "_" + key, defaultVal); }; ChromeConfigItems.prototype.GetConfig = function (key, defaultVal) { var val = this.config.GetConfig(this.Namespace + key); if (val == undefined) { return this.config.GetConfig(key, defaultVal); } return val || defaultVal; }; ChromeConfigItems.prototype.Watch = function (key, callback) { this.config.Watch(key, callback); }; Object.defineProperty(ChromeConfigItems.prototype, "super_mode", { get: function () { return utils_1.toBool(this.GetConfig("super_mode", "true")); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "vtoken", { get: function () { return this.GetConfig("vtoken", ""); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "rand_answer", { get: function () { return utils_1.toBool(this.GetConfig("rand_answer", "false")); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "auto", { get: function () { return utils_1.toBool(this.GetConfig("auto", "true")); }, set: function (val) { this.SetConfig("auto", utils_1.boolToString(val)); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "video_mute", { get: function () { return utils_1.toBool(this.GetConfig("video_mute", "true")); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "answer_ignore", { get: function () { return utils_1.toBool(this.GetConfig("answer_ignore", "false")); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "video_cdn", { get: function () { var val = this.GetConfig("video_cdn"); if (val == "默认") { return ""; } return val; }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "video_multiple", { get: function () { return parseFloat(this.GetConfig("video_multiple")); }, enumerable: false, configurable: true }); Object.defineProperty(ChromeConfigItems.prototype, "interval", { get: function () { var interval = parseFloat(this.GetConfig("interval", "0.1")); interval = interval * 100; return Math.floor(utils_1.randNumber(interval - interval / 2, interval + interval / 2)) / 100; }, enumerable: false, configurable: true }); ChromeConfigItems.prototype.SetConfig = function (key, val) { return this.config.SetConfig(this.Namespace + key, val); }; Object.defineProperty(ChromeConfigItems.prototype, "topic_interval", { get: function () { return parseInt(this.GetConfig("topic_interval", "5")); }, set: function (val) { this.SetConfig("topic_interval", val); }, enumerable: false, configurable: true }); return ChromeConfigItems; }()); exports.ChromeConfigItems = ChromeConfigItems; // 后台环境中使用 function NewBackendConfig() { var _this = this; return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { var ret; return __generator(this, function (_a) { switch (_a.label) { case 0: ret = new backendConfig(); return [4 /*yield*/, ret.updateCache()]; case 1: _a.sent(); resolve(ret); return [2 /*return*/]; } }); }); }); } exports.NewBackendConfig = NewBackendConfig; var configWatch = /** @class */ (function () { function configWatch() { this.watchCallback = new Map(); } configWatch.prototype.WatchEvent = function (key, val) { var list = this.watchCallback.get(key); if (list != undefined) { list.forEach(function (v) { v(key, val); }); } list = this.watchCallback.get("*"); if (list != undefined) { list.forEach(function (v) { v(key, val); }); } }; configWatch.prototype.Watch = function (key, callback) { var _this = this; if (typeof key == "string") { this.setWatchMap(key, callback); return; } key.forEach(function (val, index) { _this.setWatchMap(val, callback); }); }; configWatch.prototype.setWatchMap = function (key, callback) { var list = this.watchCallback.get(key); if (list == undefined) { list = new Array(); } list.push(callback); this.watchCallback.set(key, list); }; return configWatch; }()); var backendConfig = /** @class */ (function () { function backendConfig() { var _this = this; this.watch = new configWatch(); chrome.runtime.onMessage.addListener(function (request) { if (request.type && request.type == "cxconfig") { _this.cache[request.key] = request.value; _this.watch.WatchEvent(request.key, request.value); _this.updateConfigStorage(); } }); } // 更新配置转为json,存入 backendConfig.prototype.updateConfigStorage = function () { var txt = JSON.stringify(this.cache); chrome.storage.sync.set({ "config_storage": txt }); }; // 更新缓存 backendConfig.prototype.updateCache = function () { var _this = this; return new Promise(function (resolve) { chrome.storage.sync.get("config_storage", function (items) { if (items["config_storage"]) { _this.cache = JSON.parse(items["config_storage"]); } else { _this.cache = {}; } configDefaultValue.forEach(function (val, key) { if (_this.cache[key] === undefined) { _this.cache[key] = val; } }); _this.updateConfigStorage(); resolve(); }); }); }; backendConfig.prototype.GetConfig = function (key, defaultVal) { if (this.cache == undefined) { application_1.Application.App.log.Fatal("缓存失败!!!"); return ""; } return this.cache[key] || defaultVal; }; backendConfig.prototype.Watch = function (key, callback) { return this.watch.Watch(key, callback); }; backendConfig.prototype.SetConfig = function (key, val) { var _this = this; return new Promise(function (resolve) { var info = {}; info[key] = val; //通知前端和后端 _this.cache[key] = val; chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.tabs.sendMessage(tabs[0].id, { type: "cxconfig", key: key, value: val }); }); chrome.runtime.sendMessage({ type: "cxconfig", key: key, value: val }); _this.updateConfigStorage(); resolve(); }); }; backendConfig.prototype.ConfigList = function () { var _this = this; return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: if (this.cache) { return [2 /*return*/, resolve(this.cache)]; } return [4 /*yield*/, this.updateCache()]; case 1: _a.sent(); resolve(this.cache); return [2 /*return*/]; } }); }); }); }; return backendConfig; }()); // 前端环境使用 function NewFrontendGetConfig() { return new frontendGetConfig(); } exports.NewFrontendGetConfig = NewFrontendGetConfig; var frontendGetConfig = /** @class */ (function () { function frontendGetConfig() { var _this = this; this.watch = new configWatch(); this.cache = window.configData; window.addEventListener('message', function (event) { if (event.data.type && event.data.type == "cxconfig") { application_1.Application.App.log.Info("配置更新:" + event.data.key + "=" + event.data.value); _this.cache[event.data.key] = event.data.value; _this.watch.WatchEvent(event.data.key, event.data.value); } }); } frontendGetConfig.prototype.GetConfig = function (key, defaultVal) { if (window.GM_getValue) { return window.GM_getValue(key, defaultVal); } return this.cache[key] || defaultVal; }; frontendGetConfig.prototype.Watch = function (key, callback) { return this.watch.Watch(key, callback); }; frontendGetConfig.prototype.SetConfig = function (key, val) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { this.cache[key] = val; if (window.GM_setValue) { return [2 /*return*/, window.GM_setValue(key, val)]; } return [2 /*return*/, application_1.Application.App.Client.Send({ type: "GM_setValue", details: { key: key, val: val }, })]; }); }); }; frontendGetConfig.prototype.ConfigList = function () { return this.cache; }; return frontendGetConfig; }()); /***/ }), /***/ "./src/internal/utils/event.ts": /*!*************************************!*\ !*** ./src/internal/utils/event.ts ***! \*************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventListener = void 0; var EventListener = /** @class */ (function () { function EventListener() { this.event = {}; } EventListener.prototype.addEventListener = function (event, callback) { if (!this.event[event]) { this.event[event] = new Array(); } this.event[event].push({ callback: callback, param: { once: false }, }); }; EventListener.prototype.addEventListenerOnce = function (event, callback) { if (!this.event[event]) { this.event[event] = new Array(); } this.event[event].push({ callback: callback, param: { once: true }, }); }; EventListener.prototype.callEvent = function (event) { var _this = this; var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (!this.event[event]) { return; } var del = new Array(); this.event[event].forEach(function (v, index) { v.callback.apply(_this, args); if (v.param.once) { del.push(index); } }); del.forEach(function (v, index) { _this.event[event].splice(v - index, 1); }); }; return EventListener; }()); exports.EventListener = EventListener; /***/ }), /***/ "./src/internal/utils/hook.ts": /*!************************************!*\ !*** ./src/internal/utils/hook.ts ***! \************************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Hook = void 0; var application_1 = __webpack_require__(/*! @App/internal/application */ "./src/internal/application.ts"); var Hook = /** @class */ (function () { function Hook(func, context) { this.context = context || window; this.func = func; } Hook.prototype.Middleware = function (call) { var name; if (typeof this.func == "string") { name = this.func; } else {