智慧树挂机脚本

2020-05-14更新:适用于录播课,设置静音和1.5倍速,自动跳过已经看过的视频,随机答题并自动关闭弹题窗口

您需要先安裝使用者腳本管理器擴展,如 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      0.3
// @description  2020-05-14更新:适用于录播课,设置静音和1.5倍速,自动跳过已经看过的视频,随机答题并自动关闭弹题窗口
// @author       jungtravor
// @match        *://*.zhihuishu.com/videoStudy.html*
// @icon         http://assets.zhihuishu.com/icon/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
	'use strict';
	const $ = window.jQuery;
	var zhs_halt = false;

	function keeping() {
		if ( zhs_halt ) return;

		// 读取视频时长计算标识
		var video_finished = $(".current_play b").hasClass("time_icofinish");

		// 暂停后自动播放
		if ( $("video")[0].paused && !video_finished ) {
			$("#playButton").click();
		}

		// 自动切换下一个视频
		if ( video_finished ) {
			// 点击 next 按钮
			// $("#nextBtn").click();
			// 由于智慧树网页设计问题,在一定情况下点击 next 按钮后无法跳转到视频页面,故采用模拟点击方法
			var current_video = $(".video.current_play");
			var videos = $(".video");
			var click = false;
			$(".video").each(function(){
				if( click ){
					$(this).click();
					click = false;
				}
				if($(this).hasClass("current_play")) click = true;
			})
		}

		// 静音
		if ( $("video")[0].volume ) {
			$(".volumeIcon")[0].click();
		}

		// 自动切换到1.5倍
		if ( $("video")[0].playbackRate != 1.5 ) {
			$(".speedTab15")[0].click();
		}

		// 弹题自动选择第一个选项
		if ( $(".dialog-test").length ) {
			var test = $(".dialog-test");
			var test_option = test.find(".topic-item").length - 1;
			test_option = parseInt( Math.random() * test_option );
			test.find(".topic-item")[test_option].click();
			test.find(".dialog-footer").find(".btn")[0].click();
		}

	}

	$(window).ready(function(){
		setInterval(keeping, 1000);
	})

})();