Video Player Toothbrush

牙刷科技! 点击网页左上角让所有视频播放器网页全屏!

Verzia zo dňa 04.07.2014. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name        Video Player Toothbrush
// @namespace   http://www.icycat.com
// @description 牙刷科技! 点击网页左上角让所有视频播放器网页全屏!
// @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/*
// @version     1.1
// @grant       none
// @run-at      document-start
// ==/UserScript==

var player = null,
	parent, type, i, status = false,
	width, height, position, margin, padding, divArray, backStyle = new Array(),
	first = false;

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

function init() {
	var t = setTimeout(function() {
		checkPlayer();
	}, 1000);
}

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];
				type = 'embed';
				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];
							type = 'object';
							console.log('找到object播放器');
							break objectloop;
						}
					}
				}
			}
		} 
	}
	if (player) {
		console.log('找到播放器' + player);
		//setWmode();
		createButton();
	} else {
		console.log('未找到object播放器');
		return;
	}
}

/*function setWmode() {
	switch (type) {
		case 'embed':
			player.wmode == 'opaque';
			break;
		case 'object':

			break;
	}
}*/

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

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

}

function fullWin() {
	if (!first) {
		first = true;
		var full = player;
		do {
			if (full.getAttribute) {
				full.setAttribute('full_stack', true);
			}
		} while (full = full.parentNode);
		console.log('设置属性完成');
		divArray = document.getElementsByTagName('div');
		console.log('获取所有div');
	}
	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';
			}
		}
	}
	console.log('隐藏完成');
	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';
}

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 = '';
	console.log('恢复完成');
}