学堂在线刷课脚本

学堂在线刷课脚本,自动静音和二倍速,只有刷课的功能。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         学堂在线刷课脚本
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  学堂在线刷课脚本,自动静音和二倍速,只有刷课的功能。
// @author       Saafo
// @license      LGPL-3.0-only
// @match        https://next.xuetangx.com/learn/*
// @grant        none
// ==/UserScript==



function sleep (time) {
    return new Promise((resolve) => setTimeout(resolve, time));
}
(async function() {
    'use strict';
    await sleep(1000);
    var courses = document.getElementsByClassName("noScore");
    var currentCourse = "";
    var j = 0;
    for(j = 0;j< courses.length;j++){
        if(courses[j].parentElement.getAttribute("class") == "title active"){
            currentCourse = courses[j];
            break;
        }
    }
    await sleep(2000);
    var isVideo = false;

    for(let i = 0;i< 50000;i++){
        if(document.getElementsByClassName("xt_video_player_common_icon").length != 0){
            document.getElementsByClassName("xt_video_player_common_icon")[0].click();//静音
            document.getElementsByClassName("xt_video_player_common_list")[0].children[0].click();//二倍速
            isVideo = true;
            break;
        }
    }
    if(!isVideo){
        courses[j+1].click();//跳到下一个视频
        await sleep(500);
        window.location.reload();
    }

    if(currentCourse != ""){
        //开始等待
        var timeBlock = document.getElementsByClassName("xt_video_player_current_time_display")[0].textContent;
        var currentTimeRaw = timeBlock.split(' / ')[0];
        var timeLengthRaw = timeBlock.split(' / ')[1];
        var currentTime = (+currentTimeRaw.split(':')[0])*3600 + (+currentTimeRaw.split(':')[1])*60 + (+currentTimeRaw.split(':')[2]);
        var timeLength = (+timeLengthRaw.split(':')[0])*3600 + (+timeLengthRaw.split(':')[1])*60 + (+timeLengthRaw.split(':')[2]);
        await sleep((timeLength - currentTime)*500);
        courses[j+1].click();//跳到下一个视频
        console.log('开始刷课');
        await sleep(500);
        window.location.reload();
    }else{
        alert("出错,脚本已经停止运行。")
    }
    // Your code here...
})();