Greasy Fork

Greasy Fork is available in English.

Video Player Toothbrush

牙刷科技! 让所有视频播放器网页全屏!默认快捷键ALT+1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Video Player Toothbrush
// @namespace   http://www.icycat.com
// @description 牙刷科技! 让所有视频播放器网页全屏!默认快捷键ALT+1
// @include     *www.bilibili.com/video/av*
// @include     *www.iqiyi.com/*
// @include     *v.youku.com/*
// @include     *www.youtube.com/*
// @include     *v.17173.com/*
// @include     *www.tudou.com/*
// @include     *.letv.com/*
// @include     *v.pptv.com/*
// @include     *tv.sohu.com/*
// @include     *v.ku6.com/*
// @include     *vod.kankan.com/*
// @include     *v.qq.com/*
// @include     *www.56.com/*
// @include     *live.yy.com/*
// @include     *www.acfun.com/v/ac*
// @include     *donghua.dmzj.com/*
// @include     *video.sina.com.cn/*
// @version     1.7
// @grant       none
// @run-at      document-start
// ==/UserScript==

//若有需要可以自行添加域名,按照include的格式添加即可。
//自行修改快捷键,请参考下面代码中的注释。注意焦点在flash上时快捷键会失效。

var i, divArray, player = null, fullStatus = false, backStyle = new Array(), playerStyle, parent, type;

document.addEventListener('DOMContentLoaded', init, false);

function init() {
	createButton();
	window.addEventListener("keydown", function(e) {
		//默认快捷键为alt + 1, 全屏/恢复。altkey是按键ALT,keyCode=49是按键1,需要修改为其他快捷键的请搜索"keycode",修改为按键对应的数字。
		if (e.altKey && e.keyCode == 49) { 
			playerControl();
		}
	}, false);
	console.log('初始化完成');
}

function checkPlayer() {
	var embedArray = document.getElementsByTagName('embed');
	console.log('embed数量' + embedArray.length);
	checkEmbed(embedArray);
	if (!player) {
		console.log('未找到embed播放器');
		var objectArray = document.getElementsByTagName('object');
		console.log('object数量' + objectArray.length);
		checkObject(objectArray);
	}
	if (!player) {
		console.log('未找到object播放器');
		return false;
	} else {
		parent = player.parentNode;
		var full = player;
		do {
			if (full.getAttribute) {
				full.setAttribute('full_stack', true);
			}
		} while (full = full.parentNode);
		divArray = document.getElementsByTagName('div');
		fullWin();
	}
}

function createButton() {
	var button = document.createElement('span');
	button.id = 'fullStackButton';
	button.onclick = function() {
		playerControl();
	};
	document.body.appendChild(button);
	addStyle('#fullStackButton{position:fixed;width:2px;height:100%;top:0;left:0;z-index:33333;}');
}

function addStyle(css) {
	var style = document.createElement('style');
	style.type = 'text/css';
	var node = document.createTextNode(css);
	style.appendChild(node);
	document.head.appendChild(style);
}

function checkEmbed(embedArray) {
	if (embedArray.length > 0) {
		for (i = 0; i < embedArray.length; i++) {
			console.log('embed播放器检测' + i);
			if (embedArray[i].getAttribute('allowfullscreen') && embedArray[i].offsetWidth > 500) {
				player = embedArray[i];
				type = 'embed';
				console.log('找到embed播放器');
				break;
			}
		}
	}
}

function checkObject(objectArray) {
	if (objectArray.length > 0) {
		objectloop: 
		for (i = 0; i < objectArray.length; i++) {
			console.log('object播放器检测' + i);
			if (objectArray[i].offsetWidth > 500) {
				var paramArray = objectArray[i].getElementsByTagName('param');
				var j;
				for (j = 0; j < paramArray.length; j++) {
					if (paramArray[j].name.toLowerCase() == 'allowfullscreen') {
						player = objectArray[i];
						type = 'object';
						console.log('找到object播放器');
						break objectloop;
					}
				}
			}
		}
	}
}

function playerControl() {
	if (!player) {
		checkPlayer();
	} else {
		if (!fullStatus) {
			switch (type) {
				case 'embed':
					var embedArray = parent.getElementsByTagName('embed');
					checkEmbed(embedArray);
					break;
				case 'object':
					var objectArray = parent.getElementsByTagName('object');
					checkObject(objectArray);
					break;
			}
			fullWin();
		} else {
			smallWin();
		}
	}
}

function fullWin() {
	fullStatus = true;
	playerStyle = {
		width: player.style.width,
		height: player.style.height,
		margin: player.style.margin,
		padding: player.style.padding,
		left: player.style.left
	};
	for (i = 0; i < divArray.length; i++) {
		if (divArray[i].getAttribute) {
			if (divArray[i].getAttribute('full_stack')) {
				backStyle[i] = {
					width: divArray[i].style.width,
					height: divArray[i].style.height,
					position: divArray[i].style.position,
					margin: divArray[i].style.margin,
					padding: divArray[i].style.padding,
					background: divArray[i].style.background,
					top: divArray[i].style.top,
					zIndex: divArray[i].style.zIndex
				};
				divArray[i].style.width = '100%';
				divArray[i].style.height = '100%';
				divArray[i].style.position = 'fixed';
				divArray[i].style.margin = '0 0';
				divArray[i].style.padding = '0 0';
				divArray[i].style.background = '#000';
				divArray[i].style.top = '0';
				divArray[i].style.zIndex = '22222';
			} else {
				backStyle[i] = divArray[i].style.display;
				divArray[i].style.display = 'none';
			}
		}
	}
	player.style.width = '100%';
	player.style.height = '100%';
	player.style.margin = '0 0';
	player.style.padding = '0 0 0 1px';
	player.style.left = '0';
	console.log('网页全屏完成');
}

function smallWin() {
	fullStatus = false;
	for (i = 0; i < divArray.length; i++) {
		if (divArray[i].getAttribute) {
			if (divArray[i].getAttribute('full_stack')) {
				divArray[i].style.width = backStyle[i].width;
				divArray[i].style.height = backStyle[i].height;
				divArray[i].style.position = backStyle[i].position;
				divArray[i].style.margin = backStyle[i].margin;
				divArray[i].style.padding = backStyle[i].padding;
				divArray[i].style.background = backStyle[i].background;
				divArray[i].style.top = backStyle[i].top;
				divArray[i].style.zIndex = backStyle[i].zIndex;
			} else {
				divArray[i].style.display = backStyle[i];
			}
		}
	}
	player.style.width = playerStyle.width;
	player.style.height = playerStyle.height;
	player.style.margin = playerStyle.margin;
	player.style.padding = playerStyle.padding;
	player.style.left = playerStyle.left;
	console.log('恢复完成');
}