Greasy Fork

Greasy Fork is available in English.

中国大学Mooc刷学习时长

点亮所有学习任务后但是会发现学习时长不够,使用该脚本进行反复刷某一个视频即可。

当前为 2023-09-12 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        中国大学Mooc刷学习时长
// @namespace   http://tampermonkey.net/
// @version     0.0.1
// @description 点亮所有学习任务后但是会发现学习时长不够,使用该脚本进行反复刷某一个视频即可。
// @author      HengY1
// @match       *://www.icourse163.org/learn/*
// @grant       none
// @license     MIT
// @run-at      document-start
// ==/UserScript==

(function () {
    'use strict';
    // 先把debugger下掉,方便如果需要调试
    Function.prototype.__constructor_back = Function.prototype.constructor;
    Function.prototype.constructor = function () {
        if (arguments && typeof arguments[0] === 'string') {
            if ("debugger" === arguments[0]) {
                return
            }
        }
        return Function.prototype.__constructor_back.apply(this, arguments);
    }

    // 核心思路就是随便打开一个视频,然后缩小浏览器自己干自己的事情去。
    // 我们目前是会看时长,但不会看你看了哪些视频。

    // 拿到播放器进行相关控制
    // https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLMediaElement
    function checkPlayer() {
        let videoElement = document.querySelector('video');
        if (videoElement) {
            clearInterval(intervalId); // 清除定时器
            videoElement.playbackRate = 1;
            videoElement.muted = true;
            videoElement.autoplay = true;
            videoElement.addEventListener('ended', () => {
                console.log('视频已经播放完毕,重新跳转到当前页面进行刷时间');
                location.reload();
            });
            videoElement.addEventListener('pause', () => {
                const currentTime = videoElement.currentTime;
                const duration = videoElement.duration;
                if (currentTime !== duration) { // 现在莫名多了个选择题,直接不管继续播放进行
                    setTimeout(function () {
                        videoElement.play();
                    }, Math.floor(Math.random() * 400) + 800); // 模拟人在做题
                }
            });
        }
    }
    let intervalId = setInterval(checkPlayer, 500); // 没找到对应回调,暴力点
})();