// ==UserScript== // @name 优学院自动静音播放、自动做练习题、自动翻页、修改播放速率(改) // @namespace [url=mailto:moriartylimitter@outlook.com]moriartylimitter@outlook.com[/url] // @version 1.6.6 // @description 自动静音播放每页视频、自动作答、修改播放速率! // @author EliotZhang、Brush-JIM // @match *://*.ulearning.cn/learnCourse/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/jqueryui/1.12.1/jquery-ui.js // @run-at document-start // @grant unsafeWindow // @downloadURL none // ==/UserScript== (function () { 'use strict'; /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * 优学院自动静音播放、自动做练习题、自动翻页、修改播放速率脚本v1.6.3由BrushJIM @ 2020/09/13 最后更新 * 特别感谢Brush-JIM (Mail:Brush-JIM@protonmail.com) 提供的脚本改进支持! * 使用修改播放速率功能请谨慎!!!产生的不良后果恕某概不承担!!! * 请保持网课播放页面在浏览器中活动,避免长时间后台挂机(平台有挂机检测功能),以减少不必要的损失 * 自动作答功能由于精力有限目前只支持单/多项选择、判断题、部分填空问答题,如果出现问题请尝试禁用这个功能! * 如果脚本无效请优先尝试刷新页面,若是无效请查看脚本最后的解决方案,如果还是不行请反馈给本人,本人将会尽快修复 * 如果是因为网络问题,本人也无能为力 * 如果在使用中还有什么问题请通过邮箱联系EliotZhang:moriartylimitter@outlook.com * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ var N = 1.50; var EnableAutoPlay = true; var EnableAutoMute = true; var EnableAutoChangeRate = true; var EnableAutoFillAnswer = true; var EnableAutoShowAnswer = true; var EnableAutoAnswerChoices = true; var EnableAutoAnswerJudges = true; var EnableAutoAnswerFills = true; function Video(slept = false) { if (!EnableAutoPlay) { return; } if (autoAnswering) { setTimeout(function () { Video(true); }, '1000'); return; } if (!slept) { setTimeout(function () { Video(true); }, '3000'); return; } var videos = $('mediaelementwrapper video:first-child'); var videos_status = $('.video-bottom span:first-child'); if (videos.length === 0) { GotoNextPage(); return; } var v_s = []; if (videos.length === videos_status.length) { $(videos).each(function (index, value) { let state = $(videos_status[index]).attr('data-bind'); if (state === 'text: $root.i18nMessageText().finished') { v_s.push({ 'ele': value, 'status': true, 'seek': 0 }); } else if (state === 'text: $root.i18nMessageText().viewed' || state === 'text: $root.i18nMessageText().unviewed') { v_s.push({ 'ele': value, 'status': false, 'seek': 0 }); } else { v_s.push({ 'ele': value, 'status': null, 'seek': 0 }); } }) } else { GotoNextPage(); return; } $(v_s).each(function (index, value) { value['ele'].addEventListener("ended", function () { v_s[index]['status'] = true; }, true); }) VideoCtrl(v_s); } function VideoCtrl(v_s){ if (v_s.length !== $('mediaelementwrapper video:first-child').length){ Video(); return; } for(let z = 0; z < v_s.length; z++){ if(v_s[z].ele !== $('mediaelementwrapper video:first-child')[z]){ Video(); return; } let edit_video = undefined; if(v_s[z].status === false){ edit_video = (z !== 0 && v_s[z - 1].status === false)? v_s[z - 1]: v_s[z]; if(edit_video.ele.paused === true || v_s[z].seek === edit_video.ele.currentTime){ edit_video.ele.currentTime = edit_video.ele.currentTime - 3; edit_video.ele.play(); } edit_video.seek = edit_video.ele.currentTime; if(EnableAutoMute && edit_video.ele.muted === false){ edit_video.ele.muted = true; } if(EnableAutoChangeRate && edit_video.ele.playbackRate != N){ edit_video.ele.playbackRate = N; } setTimeout(VideoCtrl, 500, v_s); return; } } GotoNextPage(); } function GotoNextPage() { if (autoAnswering || !EnableAutoPlay || checkingModal) return; var nextPageBtn = $('.mobile-next-page-btn'); if (nextPageBtn.length === 0) return; nextPageBtn.each((k, n) => { n.click(); }); setTimeout(Video, "1000"); } function CheckModal(slept = false) { if (autoAnswering) return; if (!slept) { setTimeout(function () { CheckModal(true); }, '2000'); return; } if (EnableAutoPlay) { CheckModal(); } checkingModal = true; var qw = $('.question-wrapper'); if (qw.length > 0 && EnableAutoFillAnswer) { ShowAndFillAnswer(); checkingModal = false; return; } var statModal = $('#statModal'); if (statModal.length > 0) { var ch = statModal[0]; ch.getElementsByTagName('button'); if (ch.length >= 2) ch[1].click(); } var err = $('.mobile-video-error'); if (err && err.css('display') != 'none') $('.try-again').click(); var alertModal = document.getElementById("alertModal"); if (alertModal === undefined) { checkingModal = false; return; } if (alertModal.className.match(/\sin/)) { var op = $('.modal-operation').children(); if (op.length >= 2) op[EnableAutoFillAnswer ? 0 : 1].click(); else { var continueBtn = $('.btn-submit'); if (continueBtn.length > 0) { continueBtn.each((k, v) => { if ($(v).text() != '提交') $(v).click(); }); } } if (EnableAutoFillAnswer) ShowAndFillAnswer(); } checkingModal = false; } function RemoveDuplicatedItem(arr) { for (var i = 0; i < arr.length - 1; i++) { for (var j = i + 1; j < arr.length; j++) { if (arr[i] == arr[j]) { arr.splice(j, 1); j--; } } } return arr; } function Escape2Html(str) { var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' }; return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; }); } function DelHtmlTag(str) { return str.replace(/(<[^>]+>|\\n|\\r)/g, " "); } function FillAnswers() { if (!autoAnswering || !EnableAutoAnswerFills) return; var ansarr = []; var idList = []; var re = []; var txtAreas = $('textarea, .blank-input'); $(txtAreas).each((k, v) => { var reg = /question\d+/; var fa = $(v).parent(); while (!reg.test($(fa).attr('id'))) { fa = $(fa).parent(); } var id = $(fa).attr('id').replace('question', ''); idList.push(id); }); idList = RemoveDuplicatedItem(idList); $(idList).each((k, id) => { $.ajax({ url: 'https://api.ulearning.cn/questionAnswer/' + id, type: "GET", contentType: "application/json", dataType: 'json', async: false, data: { parentId: pageid, }, success: function (result, status, xhr) { re.push(result.correctAnswerList); } }); }); $(re).each((k1, v1) => { if (v1.length == 1) { ansarr.push(DelHtmlTag(Escape2Html(v1[0]))); } else { $(v1).each(function (k2, v2) { ansarr.push(DelHtmlTag(Escape2Html(v2))); }); } }); $(txtAreas).each((k, v) => { $(v).val(ansarr.shift()); }); } function ShowAndFillAnswer() { if (autoAnswering | !EnableAutoFillAnswer) return; autoAnswering = true; var sqList = []; var qw = $('.question-wrapper'); var pages = $('.page-item'); var an = []; qw.each(function (k, v) { var id = $(v).attr('id'); sqList.push(id.replace('question', '')); }); var flag = false; pages.each(function (k, v) { if (flag) return; var sp = $(v).find('.page-name'); if (sp.length > 0 && sp[0].className.search('active') >= 0) { var pd = $(v).attr('id'); pd = pd.slice(pd.search(/\d/g)); pageid = pd; flag = true; } }); if (!flag) { autoAnswering = false; GotoNextPage(); return; } if (sqList.length <= 0) { autoAnswering = false; return; } $(sqList).each(function (k, id) { var flag = false; while (!flag) $.ajax({ url: 'https://api.ulearning.cn/questionAnswer/' + id, type: "GET", contentType: "application/json", dataType: 'json', async: false, data: { parentId: pageid, }, success: function (result, status, xhr) { an.push(result.correctAnswerList); flag = true; } }); }); // if (EnableAutoShowAnswer) { var t = qw.find('.question-title-html'); t.each(function (k, v) { var ans = an.shift(); $(v).after('答案:' + ans + ''); an.push(ans); }); } // var checkBox = qw.find('.checkbox'); var choiceBox = qw.find('.choice-btn'); var checkList = []; var choiceList = []; let lasOffsetP = ''; checkBox.each((k, cb) => { if (lasOffsetP == $(cb).offsetParent().attr('id')) { checkList[checkList.length - 1].push(cb); } else { var l = []; l.push(cb); checkList.push(l); lasOffsetP = $(cb).offsetParent().attr('id'); } }); lasOffsetP = ''; choiceBox.each((k, cb) => { if (lasOffsetP == $(cb).offsetParent().attr('id')) { choiceList[choiceList.length - 1].push(cb); } else { var l = []; l.push(cb); choiceList.push(l); lasOffsetP = $(cb).offsetParent().attr('id'); } }); an.forEach(a => { if (a == null || a == undefined || a.length <= 0) { return; } if (a[0].match(/[A-Z]/) && a[0].length == 1 && EnableAutoAnswerChoices) { var cb = checkList.shift(); a.forEach(aa => { var cccb = $(cb[aa.charCodeAt() - 65]); if (cccb[0] === undefined || (cccb[0] != undefined && cccb[0].className.search('selected') < 0)) cccb.click(); }); } else if (a[0].match(/(([tT][rR][uU][eE])|([fF][aA][lL][sS][eE]))/) && EnableAutoAnswerJudges) { var ccb = choiceList.shift(); a.forEach(aa => { if (aa.match(/([tT][rR][uU][eE])/)) ccb[0].click(); else ccb[1].click(); }); } return; }); if (EnableAutoAnswerFills) { FillAnswers(); $.globalEval("$('textarea, .blank-input').trigger('change')"); } if (EnableAutoPlay) { $('textarea, .blank-input').trigger('change'); $('.btn-submit').click(); var A_tmp = $('video'); var A = []; for (let d = 0; d < A_tmp.length; d++) { if (A_tmp[d].src != "") { A.push(A_tmp[d]); } } if (A.length === 0) { autoAnswering = false; GotoNextPage(); return; } } autoAnswering = false; } function LoadStyle(url) { var link = document.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = url; var head = document.getElementsByTagName('head')[0]; head.appendChild(link); } function DrawOptionPanel() { LoadStyle('https://eliotzhang.club/CSS/ulearning.css'); var root = document.getElementsByTagName('body')[0]; var panel = document.createElement('div'); root.appendChild(panel); panel.setAttribute('class', 'OptionPanel'); panel.innerHTML = "
由于优学院视频问题,可能会出现无法正常播放,此时脚本会后退3秒重新播放,可能要重复多次!
若关闭自动翻页功能导致自动作答系列功能失效请点击保存设置并刷新脚本按钮!
若关闭自动翻页功能答完题后请手动提交!!