Greasy Fork is available in English.

Video Player Toothbrush

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

Versione datata 05/07/2014. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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     *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*
// @version     1.3
// @grant       none
// @run-at      document-start
// ==/UserScript==

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

var i, divArray, player = null, status = false, backStyle = new Array(), playerStyle, first = true;

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

function init() {
	if (!checkPlayer()) {
		console.log('延迟2秒重新检测');
		var t = setTimeout(function() {
			checkPlayer();
		}, 2000);
	}
}

function checkPlayer() {
	var embedArray = document.getElementsByTagName('embed');
	console.log('embed数量' + embedArray.length);
	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];
				console.log('找到embed播放器');
				break;
			}
		}
	}
	if (!player) {
		console.log('未找到embed播放器');
		var objectArray = document.getElementsByTagName('object');
		if (objectArray.length > 0) {
			console.log('object数量' + objectArray.length);
			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];
							console.log('找到object播放器');
							break objectloop;
						}
					}
				}
			}
		}
	}
	if (!player) {
		console.log('未找到object播放器');
		return false;
	} else {
		console.log('创建按钮&生成快捷键');
		createButton();
		window.addEventListener("keydown", function(e) {
			// 默认快捷键为alt + 1, 全屏/恢复。altkey是按键ALT,keyCode=49是按键1,需要修改为其他快捷键的请搜索"keycode",修改为按键对应的数字。
			if (e.altKey && e.keyCode == 49) { 
				playerControl();
			}
		}, false);
		return true;
	}
}

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

function playerControl() {
	if (!status) {
		status = true;
		fullWin();
	} else {
		status = false;
		smallWin();
	}
}

function fullWin() {
	if (first) {
		first = false;
		var full = player;
		do {
			if (full.getAttribute) {
				full.setAttribute('full_stack', true);
			}
		} while (full = full.parentNode);
		divArray = document.getElementsByTagName('div');
		playerStyle = {
			width: player.style.width,
			height: player.style.height,
			position: player.style.position,
			margin: player.style.margin,
			padding: player.style.padding,
			left: player.style.left,
			zIndex: player.parentNode.style.zIndex
		};
		console.log(playerStyle);
	}
	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
				};
				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';
			} else {
				backStyle[i] = divArray[i].style.display;
				divArray[i].style.display = 'none';
			}
		}
	}
	player.style.width = '100%';
	player.style.height = '100%';
	player.style.position = 'fixed';
	player.style.margin = '0 0';
	player.style.padding = '0 0 0 1px';
	player.style.left = '0';
	player.parentNode.style.zIndex = '22222';
	console.log('网页全屏完成');
}

function smallWin() {
	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;
			} else {
				divArray[i].style.display = backStyle[i];
			}
		}
	}
	player.style.width = playerStyle.width;
	player.style.height = playerStyle.height;
	player.style.position = playerStyle.position;
	player.style.margin = playerStyle.margin;
	player.style.padding = playerStyle.padding;
	player.style.left = playerStyle.left;
	player.parentNode.style.zIndex = playerStyle.zIndex;
	console.log('恢复完成');
}