// ==UserScript== // @name 优学院看视频(新) // @namespace https://greasyfork.org/zh-CN/scripts/382033 // @version 2020.09.15 // @description 可用来看优学院视频而不用手动点击 // @author Brush-JIM // @match https://ua.ulearning.cn/learnCourse/learnCourse.html?* // @grant unsafeWindow // @grant GM_getValue // @grant GM_setValue // @grant GM.getValue // @grant GM.setValue // @grant GM_deleteValue // @grant GM.deleteValue // @grant GM_xmlhttpRequest // @grant GM.xmlhttpRequest // @run-at document-start // @require https://code.jquery.com/jquery-3.3.1.min.js // @icon https://www.ulearning.cn/ulearning/favicon.ico // @supportURL https://greasyfork.org/zh-CN/scripts/382033 // @require https://greasyfork.org/scripts/394494-优学院答题/code/优学院答题.js // @downloadURL https://update.greasyfork.icu/scripts/382033/%E4%BC%98%E5%AD%A6%E9%99%A2%E7%9C%8B%E8%A7%86%E9%A2%91%EF%BC%88%E6%96%B0%EF%BC%89.user.js // @updateURL https://update.greasyfork.icu/scripts/382033/%E4%BC%98%E5%AD%A6%E9%99%A2%E7%9C%8B%E8%A7%86%E9%A2%91%EF%BC%88%E6%96%B0%EF%BC%89.meta.js // ==/UserScript== (function() { 'use strict'; var ctrl_state=false; var learning_state=false; unsafeWindow.localStorage.removeItem('failureRecord'); try{unsafeWindow.document.__defineGetter__('hidden',function(){return false})}catch(e){Object.defineProperty(unsafeWindow.document,'hidden',{get:function(){return false}})}; try{unsafeWindow.document.__defineGetter__('visibilityState',function(){return 'visible'})}catch(e){Object.defineProperty(unsafeWindow.document,'visibilityState',{get:function(){return 'visible'}})}; function gm_get(name,defaultValue){if(typeof GM_getValue==='function'){return new Promise((resolve,reject)=>{resolve(GM_getValue(name,defaultValue))})}else{return GM.getValue(name,defaultValue)}}; function gm_set(name,defaultValue){if(typeof GM_setValue==='function'){GM_setValue(name,defaultValue)}else{GM.setValue(name,defaultValue)}}; function gm_xml(obj){if(typeof GM_xmlhttpRequest==='fcuntion'){GM_xmlhttpRequest(obj)}else{GM.xmlhttpRequest(obj)}}; function save_set(){gm_set('speed',window.speed);gm_set('muted',window.muted);gm_set('auto_exit',window.auto_exit);gm_set('auto_answer',window.auto_answer);}; function get_ele_set(){window.speed=$('input[id="speed"]')[0].value;window.muted=$('input[id="video_muted"]')[0].checked;window.auto_exit=$('input[id="exit"]')[0].checked;window.auto_answer=$('input[id="auto_answer"]')[0].checked}; function set_ele(){$('input[id="speed"]')[0].value=window.speed;$('input[id="video_muted"]')[0].checked=window.muted;$('input[id="exit"]')[0].checked=window.auto_exit;$('input[id="auto_answer"]')[0].checked=window.auto_answer;} gm_get('speed').then((speed)=>{ gm_get('muted').then((muted)=>{ gm_get('auto_exit').then((auto_exit)=>{ gm_get( 'auto_answer' ).then((auto_answer)=>{ if(speed==undefined){speed=1} if(muted==undefined){muted=false} if(auto_exit==undefined){auto_exit=true} if(auto_answer==undefined){auto_answer=false} window.speed=speed;window.muted=muted;window.auto_exit=auto_exit;window.auto_answer=auto_answer;save_set(); $(unsafeWindow.document).ready(function(){ add_ele(); unsafeWindow.document.body.addEventListener('DOMSubtreeModified',function(){unsafeWindow.$(unsafeWindow).off('beforeunload')} , false); }); }) }) }) }) function learning(){ if(learning_state==false){ learning_state=true; document.querySelector('button[id="startstop"]').innerHTML = '停止学习'; var learning_class=function(){ if(document.getElementsByClassName('modal-backdrop fade in')[0]!=null){ var cl_fade=false; if(document.querySelector("[data-bind='text: $root.i18nMsgText().gotIt']")!=null){document.querySelector("[data-bind='text: $root.i18nMsgText().gotIt']").click();cl_fade=true} if(document.querySelector("[data-bind='text: $root.i18nMsgText().confirmLeave']")!=null){ document.querySelector("[data-bind='text: $root.i18nMsgText().confirmLeave']").click();cl_fade=true } if(document.querySelector("[data-bind='text: i18nMessageText().nextChapter']")!=null){ document.querySelector("[data-bind='text: i18nMessageText().nextChapter']").click();cl_fade=true } if(cl_fade==false){ alert('未知情况,请反馈问题。'); document.querySelector('button[id="startstop"]').innerHTML = '开始学习'; return false } else{ if(learning_state==true){ setTimeout(learning_class,2000) } } } else{ var data = new Array(); var all_finsh=false; for (let i = 0;i < $('mediaelementwrapper video:first-child').length;i++) { data[i] = new Array(); data[i]['video'] = $('mediaelementwrapper video:first-child')[i]; data[i]['video'].onwaiting=(event)=>{data[i]['onwaiting']=true} data[i]['state']=false; data[i]['ele_tips']=false; data[i]['onwaiting']=false; data[i]['seek'] = 0; } function watch_video(){ if(all_finsh==true){ if(learning_state==true){ setTimeout( function () { unsafeWindow.koLearnCourseViewModel.goNextPage(); for (var k = 0; k < document.querySelectorAll("[data-bind='text: $root.nextPageName()']").length; ++k) { if (document.querySelectorAll("[data-bind='text: $root.nextPageName()']")[k].innerHTML == "没有了") { if (window.auto_exit == true) { unsafeWindow.koLearnCourseViewModel.goBack(); } else { document.querySelector('button[id="startstop"]').innerHTML = '学习完成(该按钮已不可点击)'; document.querySelector('button[id="startstop"]').disabled = true; } return; } } setTimeout(learning_class,2000) },2000) } } else { var counts=0; for(let count=0;count<$('.video-bottom span:first-child').length;count++){ let data_bind = $('.video-bottom span:first-child')[count].getAttribute('data-bind'); if (data_bind == 'text: $root.i18nMessageText().finished') { data[counts]['ele_tips']=true if(data[counts]['onwaiting']==false){ if(data[counts]['video'].paused==true){ data[counts]['state']=true } }else{ data[counts]['onwaiting']=false } counts++; } else if (data_bind == 'text: $root.i18nMessageText().viewed' || data_bind == 'text: $root.i18nMessageText().unviewed'){ counts++; } } var all=true for(let j=0;j