中国大学mooc_倍速播放控制

收录 89

中国大学mooc_倍速播放控制
此脚本加了视频倍速播放的控制,便于复习
视频播放后,按键盘c速度+0.1,按键盘x速度-0.1,回车全屏
左右键快进或后退
键盘上部1234键设置倍数为1、2、3、4倍
代码45行处,设置默认倍数,默认为3倍
取消了自动连续播放
播放的速度会显示在原课程名称位置处
脚本概率性失效,失效后刷新即可正常

// ==UserScript==
// @name         中国大学mooc_倍速播放控制
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  此脚本加了视频倍速播放的控制,便于复习
// @author       kakasearch
// @match        https://www.icourse163.org/learn/*
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    function FullScreen() {
    var ele = document.getElementsByTagName('video')[0]
    if (ele.requestFullscreen) {
        ele.requestFullscreen();
    } else if (ele.mozRequestFullScreen) {
        ele.mozRequestFullScreen();
    } else if (ele.webkitRequestFullScreen) {
        ele.webkitRequestFullScreen();
    }
}
    if (/content/.test(window.location.href)){
    console.log('loaded')
     document.body.onkeydown = function (event) {
 if (window.event) {
 return event;
}

     }
     let check = setInterval(function(){
     let checkbox = document.querySelector("#courseLearn-inner-box > div > div > div.j-lscontent.lscontent > div.j-unitct.unitct > div.m-learnunitUI.f-pr.learn-plan-container > div.j-unitctBar.unitctBar.f-cb > div.f-fl > input")
     if(checkbox){
         clearInterval(check)
          checkbox.checked= false
     }
     },100)
     let pass = setInterval(function(){
     let video = document.getElementsByTagName('video')

     if(video.length>0){
         clearInterval(pass)
         video[0].currentTime=0
         video[0].play()
         video[0].playbackRate =3
         video[0].onended = function(){
             let ycid = /cid=(\d+)/.exec(window.location.href)[1]
      let ncid = parseInt(ycid)+1
  window.location.href = window.location.href.replace(ycid,String(ncid))
         }
     }
     },100)

       document.body.onkeydown = function(ev){
            var e = ev || event;
            if(e.keyCode ==67){
                document.getElementsByTagName('video')[0].playbackRate += 0.1
    document.querySelector("#g-body > div.m-learnhead > div > div.f-fl.info > div > a.f-fl > h4").innerText =document.getElementsByTagName('video')[0].playbackRate.toFixed(1)
            }else if(e.keyCode ==88){
                     document.getElementsByTagName('video')[0].playbackRate -= 0.1
    document.querySelector("#g-body > div.m-learnhead > div > div.f-fl.info > div > a.f-fl > h4").innerText =document.getElementsByTagName('video')[0].playbackRate.toFixed(1)
}else if(e.keyCode ==13){
         FullScreen()
    document.querySelector("#courseLearn-inner-box > div > div > div.j-lscontent.lscontent > div.j-unitct.unitct > div.m-learnunitUI.f-pr.learn-plan-container > div.j-unitctBar.unitctBar.f-cb > div.f-fl > input").checked= false
if(document.getElementsByTagName('video')[0].ended){
    let ycid = /cid=(\d+)/.exec(window.location.href)[1]
      let ncid = parseInt(ycid)+1
  window.location.href = window.location.href.replace(ycid,String(ncid))
         }
                     }
  else if(e.keyCode ==39){
          document.getElementsByTagName('video')[0].currentTime += 5
          }
  else if (e.keyCode ==37){
          document.getElementsByTagName('video')[0].currentTime -= 5
          }
     else if (e.keyCode ==49){
          document.getElementsByTagName('video')[0].playbackRate =1
          }
           else if (e.keyCode ==50){
          document.getElementsByTagName('video')[0].playbackRate =2
          }
                    else if (e.keyCode ==51){
          document.getElementsByTagName('video')[0].playbackRate =3
          }
                     else if (e.keyCode ==52){
          document.getElementsByTagName('video')[0].playbackRate =4
          }


document.querySelector("#g-body > div.m-learnhead > div > div.f-fl.info > div > a.f-fl > h4").innerText =document.getElementsByTagName('video')[0].playbackRate.toFixed(1)

       }}




    // Your code here...
})();
none
打赏采用二维码方式。

添加新评论