慕课网(Imooc.com)自动播放

Imooc.com 去除微信公众号二维码;可设置的是否自动播放下一个视频;可设置的是否全屏播放

目前為 2019-08-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         慕课网(Imooc.com)自动播放
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Imooc.com 去除微信公众号二维码;可设置的是否自动播放下一个视频;可设置的是否全屏播放
// @author       smilewind
// @match        https://www.imooc.com/video/*
// @match        https://coding.imooc.com/class/*
// @require      https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    //在个人设置中添加配置选项
    var playSetting = `
             <div class="card-history" style="margin-top:10px;" ><span class="history-item"><i class="imv2-homework" style="display:inline-block;margin-left: -10%;margin-right:2%;"></i> <span class="text-ellipsis"  style="font-weight: 700;">播放设置</span>
                 <ol>
                     <li style="margin-top:10px;">
                        <input class="tamAutoFullScr" type="checkbox" name="autoplay" style="top:3px;">
                        <span class="text-ellipsis" style="margin-left: 5%;">全屏播放</span>
                     </li>
                     <li style="margin-top:3px;">
                        <input class="tamAutoPlay" type="checkbox" name="autoplay" style="top:3px;">
                        <span class="text-ellipsis" style="margin-left: 5%;">自动下一集</span>
                     </li>
                  </o>
              </span></div>`;

    //初始化状态
    var storage = window.localStorage,
     autoPlay = storage.getItem('autoPlay')=='true' ? true : false,
     autoFull = storage.getItem('autoFull')=='true' ?true : false;
    //console.log('自动播放:'+autoPlay+',自动全屏:'+autoFull);
    //关闭未关注微信公众号的弹窗二维码
    window.onload = function(){
        $('#BindingPublicNumber').css('display','none');
        $('.publicnumber-block').css('display','none');
        //添加配置项
        $('.user-center-box').append(playSetting);
        $('.tamAutoPlay').attr('checked',autoPlay);
        $('.tamAutoFullScr').attr('checked',autoFull);
    }

    //checkbox是否选中
    $(document).on('click','.tamAutoPlay',function(){
         var isCheck = $(this).get(0).checked;
         window.localStorage.setItem("autoPlay",isCheck);
         location=location;
    })
    $(document).on('click','.tamAutoFullScr',function(){
         var isFull = $(this).get(0).checked;
         window.localStorage.setItem("autoFull",isFull);
         location=location;
    })

   //自动播放下一集
   var isPlay = '';
   if(autoPlay){
       setInterval(function(){
           isPlay = $('.J_next-box').css('display');
           if(isPlay == 'block'){
               $('.J-next-btn').click();
           }
       },1000)
    }

    //自动全屏
    var isFull = '',isMiddle = '',isClick=false;
    if(autoFull){
        setInterval(function(){
            if(!isClick){
                isFull = $('#chapterId').css('visibility');
                isMiddle = $('.J_next-box').css('display');
                if(isFull == 'hidden' && isMiddle=='none'){
                    $('.vjs-fullscreen-control').click();
                    isClick = true;
                }
             }
       },1000)
     }
})();