├── README.md └── UoocAutoLearn.user.js /README.md: -------------------------------------------------------------------------------- 1 | # UoocAutoLearn 2 | 优课在线自动学习脚本 3 | 4 | 基本功能完成,细节待完善。 5 | 6 | http://www.uooconline.com/ 优课在线 视频课程后台学习 7 | 8 | 打开学校对应的后台登录后,开课中列表即可看到在线挂机。 9 | 10 | 挂机状态可通过浏览器 开发者工具(F12)查看进度。 11 | 12 | 油猴脚本,新手走这里安装。 13 | https://greasyfork.org/zh-CN/scripts/40463 14 | -------------------------------------------------------------------------------- /UoocAutoLearn.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name 优课在线辅助脚本 3 | // @namespace http://www.qs5.org/?UoocAutoLearn 4 | // @version 1.2.181225a 5 | // @description 实现自动挂机看视频,作业自动做题/共享答案功能 6 | // @author ImDong 7 | // @match *://*.uooconline.com/* 8 | // @match *://www1.baidu.com/s?uooc=1&* 9 | // @grant none 10 | // ==/UserScript== 11 | 12 | (function (window, $) { 13 | 14 | // 创建对象 15 | var UoocAutoLearn = window.UoocAutoLearn || { 16 | apiUrl: 'https://www.qs5.org/tools/szu_tools/index.php' 17 | }; 18 | 19 | // 获取课程列表 20 | UoocAutoLearn.getCatalogList = function () { 21 | $.ajax({ 22 | type: "GET", 23 | url: '/home/learn/getCatalogList', 24 | data: { 25 | cid: this.cid 26 | }, 27 | success: function (response) { 28 | UoocAutoLearn.loopCatalog(response.data); 29 | } 30 | }); 31 | }; 32 | 33 | // 遍历课程 34 | UoocAutoLearn.loopCatalog = function (data) { 35 | var isFinished = true; 36 | for (let index = 0; index < data.length; index++) { 37 | const item = data[index]; 38 | if (item.finished == 0) { 39 | isFinished = false; 40 | if (typeof item.children != 'undefined') { 41 | UoocAutoLearn.loopCatalog(item.children); 42 | } else { 43 | // 播放这个课程 44 | console.log('新的课程', item.number, item.name); 45 | 46 | UoocAutoLearn.catalog_id = item.id; 47 | UoocAutoLearn.chapter_id = item.pid; 48 | UoocAutoLearn.video_pos = 0; 49 | 50 | // 开始下一课程 51 | UoocAutoLearn.getUnitLearn(); 52 | } 53 | break; 54 | } 55 | } 56 | if (isFinished) { 57 | console.log('恭喜,本课已全看完。'); 58 | } 59 | }; 60 | 61 | // 获取课程进度 62 | UoocAutoLearn.getCourseLearn = function () { 63 | $.ajax({ 64 | type: "GET", 65 | url: '/home/learn/getCourseLearn', 66 | data: { 67 | cid: this.cid 68 | }, 69 | success: function (response) { 70 | if (response.code != 1) { 71 | console.log('Error', response); 72 | return; 73 | } 74 | UoocAutoLearn.chapter_id = response.data.chapter_id; 75 | UoocAutoLearn.section_id = response.data.section_id; 76 | UoocAutoLearn.resource_id = response.data.resource_id; 77 | UoocAutoLearn.catalog_id = response.data.catalog_id; 78 | UoocAutoLearn.subsection_id = response.data.subsection_id; 79 | UoocAutoLearn.parent_name = response.data.parent_name; 80 | 81 | // 如果没有看过 82 | if (UoocAutoLearn.chapter_id <= 0) { 83 | UoocAutoLearn.getCatalogList(); 84 | return; 85 | } 86 | 87 | console.log( 88 | '课程信息', UoocAutoLearn.parent_name, 89 | '章节', UoocAutoLearn.chapter_id, 90 | '部分', UoocAutoLearn.section_id, 91 | '资源', UoocAutoLearn.resource_id 92 | ); 93 | 94 | // 获取课程观看时间 95 | UoocAutoLearn.getUnitLearn(); 96 | } 97 | }); 98 | }; 99 | 100 | // 获取当前课程观看时间 101 | UoocAutoLearn.getUnitLearn = function () { 102 | $.ajax({ 103 | type: "GET", 104 | url: '/home/learn/getUnitLearn', 105 | data: { 106 | cid: this.cid, 107 | chapter_id: this.chapter_id, 108 | section_id: this.section_id, 109 | catalog_id: this.catalog_id 110 | }, 111 | success: function (response) { 112 | // 遍历每一个视频 113 | var isFinished = true; 114 | for (let index = 0; index < response.data.length; index++) { 115 | const item = response.data[index]; 116 | if (item.finished == 0) { 117 | UoocAutoLearn.video_pos = parseFloat(item.video_pos); 118 | UoocAutoLearn.videoSource = item.video_play_list[0].source; 119 | UoocAutoLearn.title = item.title; 120 | UoocAutoLearn.resource_id = item.id; 121 | isFinished = false; 122 | 123 | console.log('当前任务', UoocAutoLearn.parent_name, UoocAutoLearn.title); 124 | 125 | // 获取视频时长 126 | UoocAutoLearn.getVideoLength(); 127 | 128 | break; 129 | } 130 | } 131 | // 如果都看完了 132 | if (isFinished) { 133 | // 获取下一节课 134 | UoocAutoLearn.getCatalogList(); 135 | } 136 | } 137 | }); 138 | }; 139 | 140 | // 获取视频长度 141 | UoocAutoLearn.getVideoLength = function () { 142 | // var video = document.createElement('video'); 143 | // 加载完成后调用 144 | // video.onloadeddata = function () { 145 | UoocAutoLearn.video_length = 0; 146 | 147 | // console.log('总时长', UoocAutoLearn.video_length, '秒, 已看至', UoocAutoLearn.video_pos, '秒'); 148 | 149 | // 开始刷新时间 150 | UoocAutoLearn.markVideoLearn(); 151 | // }; 152 | // video.src = UoocAutoLearn.videoSource; 153 | return; 154 | }; 155 | 156 | // 刷新时间 157 | UoocAutoLearn.markVideoLearn = function () { 158 | this.video_pos = this.video_pos + 10; 159 | if (this.video_pos > this.video_length && this.video_length > 0) this.video_pos = this.video_length; 160 | 161 | $.ajax({ 162 | type: "POST", 163 | url: '/home/learn/markVideoLearn', 164 | data: { 165 | chapter_id: this.chapter_id, 166 | cid: this.cid, 167 | // hidemsg_: true, 168 | network: 3, 169 | resource_id: this.resource_id, 170 | section_id: this.section_id, 171 | source: 1, 172 | subsection_id: this.subsection_id, 173 | video_length: this.video_length == 0 ? 100 : this.video_length, 174 | video_pos: this.video_pos 175 | }, 176 | success: function (response) { 177 | console.log('已看至', UoocAutoLearn.video_pos, '秒, 总', UoocAutoLearn.video_length == 0 ? '未知' : UoocAutoLearn.video_length, '秒'); 178 | if (response.data.finished == 1 || (UoocAutoLearn.video_length > 0 && UoocAutoLearn.video_pos >= UoocAutoLearn.video_length)) { 179 | console.log('本课已经结束'); 180 | // 获取下一节课 181 | UoocAutoLearn.getCatalogList(); 182 | return; 183 | } 184 | setTimeout(() => { 185 | UoocAutoLearn.markVideoLearn(); 186 | }, 10 * 1000); 187 | } 188 | }); 189 | }; 190 | 191 | // 获取课程列表 192 | UoocAutoLearn.homeworkList = function () { 193 | console.log('homeworkList'); 194 | 195 | $.ajax({ 196 | type: "GET", 197 | url: '/home/task/homeworkList', 198 | data: { 199 | cid: this.cid, 200 | page: 1, 201 | pagesize: 20 202 | }, 203 | success: function (response) { 204 | for (let index = 0; index < response.data.data.length; index++) { 205 | const element = response.data.data[index]; 206 | // 判断是否批改 207 | if (element.status_code == "20") { 208 | // 提交答案到服务器 209 | UoocAutoLearn.examView(UoocAutoLearn.cid, element.id) 210 | } 211 | } 212 | } 213 | }); 214 | } 215 | 216 | // 获取作业答案并提交 217 | UoocAutoLearn.examView = function (cid, tid) { 218 | console.log('examView', cid, tid); 219 | $.ajax({ 220 | type: "GET", 221 | url: '/exam/view', 222 | data: { 223 | cid: cid, 224 | tid: tid 225 | }, 226 | success: function (response) { 227 | // 判断是否提交试卷 228 | if (response.code == 1) { 229 | // 提交试卷到服务器 230 | UoocAutoLearn.sendExam2Server(cid, tid, response.data); 231 | } 232 | } 233 | }); 234 | } 235 | 236 | // 提交试卷到服务器 237 | UoocAutoLearn.sendExam2Server = function (cid, tid, data) { 238 | console.log('sendExam2Server', cid, tid); 239 | $.ajax({ 240 | type: "POST", 241 | url: UoocAutoLearn.apiUrl, 242 | data: { 243 | cmd: 'save_exam_answer', 244 | cid: cid, 245 | tid: tid, 246 | data: JSON.stringify(data) 247 | }, 248 | success: function (response) { 249 | console.log('sendExam2Server', cid, tid, response); 250 | } 251 | }); 252 | } 253 | 254 | // 从服务器获取答案 255 | UoocAutoLearn.getExamAnswer = function () { 256 | console.log('getExamAnswer', this.tid); 257 | $.ajax({ 258 | type: "GET", 259 | url: UoocAutoLearn.apiUrl, 260 | dataType: "JSONP", 261 | data: { 262 | cmd: 'get_exam_answer', 263 | tid: this.tid 264 | }, 265 | success: function (response) { 266 | console.log(response); 267 | if (response.code == 1) { 268 | window._response = response; 269 | UoocAutoLearn.answerData = response.data; 270 | UoocAutoLearn.loopSetAnchor(); 271 | } 272 | } 273 | }); 274 | } 275 | 276 | // 依次遍历题目修改答案 277 | UoocAutoLearn.loopSetAnchor = function () { 278 | console.log("loopSetAnchor"); 279 | for (let i = 0; i < UoocAutoLearn.answerData.length; i++) { 280 | const item = UoocAutoLearn.answerData[i]; 281 | 282 | // 获取题目对象 283 | var anchor = $('#anchor' + item.id).parent('.queContainer'); 284 | 285 | window._item = item; 286 | window._anchor = anchor; 287 | 288 | // 获取题目内容 289 | var anchor_ti = anchor.find('.ti-q-c').text(), 290 | answer_ti = $("
").html(item.question).text(); 291 | 292 | // 题目相同再遍历答案 293 | if (anchor_ti == answer_ti) { 294 | // 设置题目绿色背景 295 | // anchor.find('.ti-q-c').css({ backgroundColor: '#99FF99' }); 296 | 297 | // 获取答案 298 | var ti_alist = anchor.find('.ti-alist label'); 299 | for (let k = 0; k < ti_alist.length; k++) { 300 | const a_item = ti_alist[k]; 301 | // 获取作业答案并提交 302 | var ti_k = $(a_item).find('input').val(), 303 | ti_v = $(a_item).find('.ti-a-c').text(), 304 | an_v = $('
').html(item.options[ti_k]).text(); 305 | 306 | // 对比答案是否一致 一致则勾选 307 | if (ti_v == an_v) { 308 | // 设置题目绿色 309 | // $(a_item).find('.ti-a-c').css({ backgroundColor: '#99FF99' }) 310 | 311 | // 题目是否是正确答案 312 | if (item.answer.indexOf(ti_k) >= 0) { 313 | $(a_item).find('input').click(); 314 | } 315 | } else { 316 | // 答案不一致 标红 317 | $(a_item).find('.ti-a-c').css({ backgroundColor: 'burlywood' }); 318 | // 显示数据库原题 319 | $(a_item).find('.ti-a-c').append(an_v); 320 | } 321 | } 322 | } 323 | // 题目不一致 设置红色 324 | else { 325 | // var ti_a_list = $('