Greasy Fork

Greasy Fork is available in English.

好医生自动学习

自动播放下一个视频并设置默认倍速为1倍

当前为 2024-07-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         好医生自动学习
// @namespace    https://cmechina.net/
// @version      1.5
// @description  自动播放下一个视频并设置默认倍速为1倍
// @author       韦同学
// @match        *.cmechina.net/cme/study2.jsp?course_id=202401007786&courseware_id=*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const handleVideo = () => {
        const videoElement = document.querySelector("video");
        if (videoElement) {
            videoElement.muted = true;
            videoElement.playbackRate = 1; // 设置默认倍速为1倍
            videoElement.play().catch(error => {
                console.error('视频播放失败:', error);
            });
            videoElement.addEventListener('ended', playNextVideo);
        } else {
            console.log('没有找到视频元素');
            setTimeout(handleVideo, 2000); // 重试
        }
    };

    const playNextVideo = () => {
        const lis = document.querySelectorAll("ul.s_r_ml > li");
        const activeElement = document.querySelector("li.active");

        if (!activeElement) {
            console.log('没有找到当前播放的视频元素');
            return;
        }

        let index = Array.from(lis).findIndex(li => li === activeElement);

        if (index + 1 < lis.length) {
            index += 1;
            setTimeout(() => {
                lis[index].querySelector("a").click();
            }, 5000); // 延迟5秒再点击下一个视频
        } else {
            console.log('已经是最后一个课程');
        }
    };

    window.addEventListener('load', () => {
        setTimeout(handleVideo, 3000); // 等待3秒确保页面加载完成
    });

})();