Greasy Fork

Greasy Fork is available in English.

视频站h5

视频站启用html5播放器

当前为 2017-06-19 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name             视频站h5
// @description      视频站启用html5播放器
// @version          0.3.2
// @homepage         http://bbs.kafan.cn/thread-2093014-1-1.html
// @include          *://*.qq.com/*
// @exclude          *://lpl.qq.com/es/lpl/*
// @include          *://v.youku.com/v_show/id_*
// @include          *://video.tudou.com/v/*
// @include          *://*.le.com/*.html*
// @include          *://*.lesports.com/*.html*
// @include          *://tv.sohu.com/*.shtml*
// @include          *://m*.tv.sohu.com/*.shtml*
// @include          https://www.panda.tv/*
// @exclude          https://www.panda.tv/
// @grant            unsafeWindow
// @run-at           document-start
// @namespace  http://greasyfork.icu/users/7036-xinggsf
// ==/UserScript==
'use strict';

Object.defineProperty(navigator, 'plugins', {
	get: function() {
		return { length: 0 };
	}
});
String.prototype.r1 = function(r) {
	return r.test(this) && RegExp.$1;
};
//由jQuery.cookie.js改写 http://blog.wpjam.com/m/jquery-cookies/
function cookie(name, value, options) {
	let s;
	if (typeof value === 'undefined') { //read cookie
		s = document.cookie;
		s = s && s.r1(new RegExp(name +'=([^;]+)'));
		return s && decodeURIComponent(s) || null;
	}
	options = options || {};//options: expires,path,domain,secure
	if (value == null) {
		value = '';
		options.expires = -1;//delete cookie
	}
	s = name + '=' + encodeURIComponent(value);
	if (options.expires && (typeof options.expires === 'number' || options.expires.toUTCString)) {
		let date;
		if (typeof options.expires === 'number') {
			date = new Date();
			date.setTime(date.getTime() + (options.expires * 24 * 36e5));
		} else {
			date = options.expires;
		}
		s += '; expires=' + date.toUTCString();
	}
	delete options.expires;
	for (let i in options)
		s += '; ' + i + '=' + options[i];
	//console.log(s);
	document.cookie = s;
}

let siteFn, v, totalTime,
	path = location.pathname;
const stepLen = 5, //快进快退5秒
skipLen = 27, //shift + 快进快退
u = location.hostname,
mDomain = u.split('.').reverse()[1],//主域名

$ = id => document.getElementById(id),
q = css => document.querySelector(css),
$C = (name, attr) => {
	const el = document.createElement(name);
	//用var i修正TM的for-in循环BUG
	if (attr) for (var i in attr) el.setAttribute(i, attr[i]);
	return el;
},
fakeUA = ua => Object.defineProperty(navigator, 'userAgent', {
	value: ua,
	writable: false,
	configurable: false,
	enumerable: true
}),
getAllDuration = css => {
	const a = q(css).innerHTML.split(':');
	//console.log(q(css), a);
	let n = a.pop() *1, multiplier = 1;
	for (let k of a.reverse()) {
		multiplier *= 60;
		n += k * multiplier;
	}
	return n || 2e4;
},
hotKey = function (e) {
	//console.log('hotKey', v.seeking, v.seekable);
	// 可播放
	//if (!v.seekable) return;
	//if (v.readyState !== 4) return;
	let seekPoint = ~~v.currentTime;
	switch (e.keyCode) {
	case 32: //space
		if (v.paused) v.play();
		else v.pause();
		e.preventDefault();
		//e.stopPropagation();
		break;
	case 37: //left
		seekPoint -= e.shiftKey ? skipLen : stepLen;
		if (seekPoint < 0) seekPoint = 0;
		v.currentTime = seekPoint;
		break;
	case 39: //right
		seekPoint += e.shiftKey ? skipLen : stepLen;
		v.currentTime = seekPoint;
	}
},
onCanplay = function (e) {
	//v.removeEventListener('oncanplay', onCanplay);
	//v.oncanplay = null;//注释掉,应对列表点播而不刷新页面
	console.log('脚本[启用html5播放器],事件oncanplay');
	const r = path !== location.pathname;//点播了另一个视频
	if (totalTime && !r) return;//分段视频返回
	if (!totalTime) document.addEventListener('keydown', hotKey, !1);
	totalTime = 0;
	siteFn && siteFn();
	totalTime = totalTime || Math.round(v.duration);
	//跳过片头
	if (totalTime > 666 && !['youku'].includes(mDomain))
		setTimeout( () => {
			v.currentTime = 66;
		}, 9);
	if (r) path = location.pathname;
},
init = () => {
	let mo = new MutationObserver(records => {
		v = q('video');
		if (v) {
			//console.log(mo, v.oncanplay);
			v.oncanplay = onCanplay;
			mo.disconnect();
			mo = undefined;
		}
	});
	document.addEventListener('DOMContentLoaded', e => mo.observe(document.body, {
		childList : true,
		subtree : true
	}), !1);
},
//终于可以完全屏蔽alicdn.com和mmstat.com二个统计/广告域名了,只为24字节的字符串就访问一大堆乱七八糟的东西
checkYK_cna = domain => {
	!cookie('cna') && cookie('cna', 'dZm+Ecpc9zwCAdpA3yZ5tuBx', {
		expires: 3e3,//day
		path: '/',
		'domain': domain
	});
};

switch (mDomain) {
case 'qq':
	fakeUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:48.0) Gecko/20100101 Firefox/48.0');
	break;
case 'youku':
    sessionStorage.P_l_h5 = 1;
	checkYK_cna('.youku.com');
	init();
	break;
case 'le':
case 'lesports':
	fakeUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 Version/7.0.3 Safari/7046A194A');
	init();
	break;
case 'sohu':
	//if (window.chrome)
		fakeUA('Mozilla/5.0 (Linux; U; Android 4.0.4; GT-I9300 Build/IMM76D) AppleWebKit/534.30 Version/4.0 Mobile Safari/534.30');
	// q('meta[name=mobile-agent]').remove();
	siteFn = () => {
		totalTime = getAllDuration('span.x-duration-txt');
	};
/* 	unsafeWindow.setTimeout( () => {
		if (isUseH5Player) {
			isUseH5Player = () => true;
			console.log(_videoInfo.videoLength);
		}
	}, 99); */
	init();
	break;
case 'tudou':
	//fakeUA('Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) Chrome/55.0.10 Mobile');
	siteFn = () => {
		//获取播放时长
		//totalTime = getAllDuration('span.td-h5__player__console__time-total');
		totalTime = ~~q('meta[name=duration]').getAttribute('content');
		const cur = ~~v.duration +1;
		//console.log(cur, totalTime);
		if (cur < totalTime) {
			//分段视频,保持播放器原状
			q('#td-h5+div').remove();
		}
		else {
			document.body.innerHTML = `<video width="100%" height="100%" autoplay controls src="${v.src}"/>`;
			setTimeout(() => {
				v = q('video');
				if (totalTime > 666) v.currentTime = 66;
			}, 9);
		}
	};
	init();
	checkYK_cna('.tudou.com');
	break;
case 'panda':
    localStorage.setItem('panda.tv/user/player', {useH5player: true});
}