Greasy Fork

Greasy Fork is available in English.

课程视频助手

课程视频防止掉线并设置每分钟更新视频观看时间

当前为 2020-03-09 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         课程视频助手
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  课程视频防止掉线并设置每分钟更新视频观看时间
// @author       零度
// @match        *://course.ucas.ac.cn/portal/site/*/tool/*/video/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    var doc = document;
    var url = doc.URL;
    var html_source = doc.documentElement.outerHTML;
    if(url.indexOf('list')>=0){
        var video_id_list = html_source.match(/(?<=gotoPlay\(\')[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/g);
        GM_setValue('VideoList', video_id_list);
    }
    else if(url.indexOf('play')>=0){
        portal.updateVideoView_url = html_source.match(/(?<=\$\.post\(\").*w(?=\",)/)[0];
        portal.updateVideoView_id = html_source.match(/(?<=id\:\s\")[0-9]*/)[0];
        portal.forever_keep_alive = function forever_keep_alive(){
            clearTimeout(sessionTimeOut);
            keep_session_alive();
            $.post(portal.updateVideoView_url, { id: portal.updateVideoView_id },
		        function(data, state){
		            console.log('更新视频观看时间:'+state);
		 	        return("确定要关闭页面吗?");
	            }
            );
            portal.forever_keep_alive_timer = setTimeout('portal.forever_keep_alive()', 60000);
        }
        portal.forever_keep_alive();
        portal.video_list = GM_getValue('VideoList', '');
        if(portal.video_list!=''){
            portal.cur_video_id = url.match(/(?<=id\=)[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/)[0];
            var cur_video_index = portal.video_list.indexOf(portal.cur_video_id);
            if(cur_video_index>0){
                portal.next_video_id = portal.video_list[cur_video_index-1];
                portal.next_video_url = url.replace(/(?<=id\=)[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}/, portal.next_video_id);
                portal.goto_next_video = function goto_next_video(){
                    window.location = portal.next_video_url
                }
            }
            else{
                portal.next_video_id = null;
                portal.next_video_url = null;
                portal.goto_next_video = function goto_next_video(){
                    alert('暂无下一个视频!')
                }
            }
            player.on("ended", function(){
		        console.log("播放结束");
	            $("#videoState").val("0");
                console.log("10秒后进入下一个视频");
                portal.goto_next_video_timer = setTimeout('portal.goto_next_video()', 10000);
	        });
        }
        else{
            alert('未获取到视频列表,请返回视频列表后再点击进入视频播放界面!')
        }
    }
    //following code is copied from chrome extension 'Enable Copy'
var body = doc.body;
var html = doc.documentElement;
function allowUserSelect(element) {
	element.setAttribute('style', '-webkit-user-select: auto !important');
	element.setAttribute('style', 'user-select: auto !important');
	return element;
}

function clearHandlers() {
	html.onselectstart = html.oncopy = html.oncut = html.onpaste = html.onkeydown = html.oncontextmenu = html.onmousemove = body.oncopy = body.oncut = body.onpaste = body.onkeydown = body.oncontextmenu = body.onmousedown = body.onmousemove = body.onselectstart = body.ondragstart = doc.onselectstart = doc.oncopy = doc.oncut = doc.onpaste = doc.onkeydown = doc.oncontextmenu = doc.onmousedown = doc.onmouseup = window.onkeyup = window.onkeydown = null;
	allowUserSelect(html);
	allowUserSelect(body);
}
clearHandlers();

var jQuery = window.jQuery;

var $Fn = window.$Fn;
if ($Fn) {
	try {
		$Fn.freeElement(doc);
		$Fn.freeElement(body);
	} catch (e) {}
}

var jindo = window.jindo;
if (jindo) {
	jindo.$A = null;
}

var domain_pattern = /^https?:\/\/([^\/]+)/;
var result = domain_pattern.exec(url);
if (result) {
	try {
		var domain = result[1];
		if (jQuery) {
			var $doc = jQuery(doc);
			var $body = jQuery(body);
			if ($doc.off) {
				$doc.off();
				$body.off();
				jQuery(window).off();
			} else {
				$doc.unbind();
				$body.unbind();
				jQuery(window).unbind();
			}
		}
	} catch (e) {
		console.log(e);
	}
}
})();