青书学堂挂课

青书学堂挂课,自动播放脚本。

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         青书学堂挂课
// @namespace    http://tampermonkey.net/
// @version      0.61
// @description  青书学堂挂课,自动播放脚本。
// @author       ha
// @match        https://qingshuxuetang.com/*
// @match        https://*.qingshuxuetang.com/*
// @match        https://www.qingshuxuetang.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=qingshuxuetang.com
// @grant        unsafeWindow
// @connect      degree.qingshuxuetang.com
// @connect      www.qingshuxuetang.com
// @run-at       document-end
// @license GPL
// ==/UserScript==
console.log('当前执行站点', unsafeWindow.location.href, unsafeWindow.parent)
if (unsafeWindow.self !== unsafeWindow.top) {
    return;
}

(function () {
    'use strict';
    var i
    var href = location.href

    if (href.indexOf('nodeId') > -1) {
        setTimeout(function () {
            var video = document.querySelector(".vjs-tech");
            if (video) {
                console.log('找到视频组件,开始静音并自动播放...', video)
                video.muted = true
                video.playbackRate = 1.5
                video.play()
            } else {
                console.log('未找到视频组件');
                return;
            }
            
            var params = new UrlSearch()
            var paramsNodeId = params.nodeId.trim();;
            var allLinks = document.querySelectorAll('[id^="courseware-"]');
            var ids = Array.from(allLinks).map(link => link.id.replace('courseware-', ''));
            var currentIndex = ids.indexOf(paramsNodeId);
            var nextKey = null;
            if (currentIndex !== -1 && currentIndex + 1 < ids.length) {
                nextKey = ids[currentIndex + 1];
            }
            if (nextKey) {               
                const nextUrl = `https://${window.location.host}${window.location.pathname}?teachPlanId=${params.teachPlanId}&periodId=${params.periodId}&courseId=${params.courseId}&nodeId=${nextKey}`
                console.log(params, 'currentId:', params.courseId, 'nextKey:', nextKey, 'nextUrl:', nextUrl)
                video.addEventListener("ended", function () {
                    location.replace(nextUrl);
                })
            }else{
                console.log('未找到下一节课程ID');
            }
        }, 5000)        
        getvideoprogress();
    }
})();

function UrlSearch() {
    var name, value;
    var str = location.href; 
    var num = str.indexOf("?")
    str = str.substr(num + 1); 

    var arr = str.split("&");
    for (var i = 0; i < arr.length; i++) {
        num = arr[i].indexOf("=");
        if (num > 0) {
            name = arr[i].substring(0, num);
            value = arr[i].substr(num + 1);
            this[name] = value;
        }
    }
}

function getvideoprogress() {
    setInterval(function () {
        var vid = document.querySelector(".vjs-tech");
        if (vid) {
            var currentTime = vid.currentTime; 
            var duration = vid.duration;
            if (duration > 0) { 
                var progressPercent = (currentTime / duration * 100).toFixed(1);
                console.log('当前进度:', currentTime.toFixed(1), '秒', '(', progressPercent + '%', ')');
            }
        }
    }, 10000);
}