YouTube - Always Theater Mode

Set the default viewing mode to Theater Mode.

目前為 2017-08-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        YouTube - Always Theater Mode
// @namespace   r-a-y/youtube/theater
// @description Set the default viewing mode to Theater Mode.
// @include     http://www.youtube.com/watch*
// @include     https://www.youtube.com/watch*
// @version     1.3.4
// @grant       none
// @run-at      document-start
// @license     GPL v3
// ==/UserScript==

// Ensure unsafeWindow object is available both in firefox and chrome
//
// Props Anon via YouTube Cinema Mode userscript
// https://greasyfork.org/en/scripts/10417-youtube-cinema-mode
function installUnsafewindowPolyfill()
{
	if (typeof unsafeWindow === 'undefined')
	{
		if (typeof XPCNativeWrapper === 'function' && typeof XPCNativeWrapper.unwrap === 'function')
			unsafeWindow = XPCNativeWrapper.unwrap(window);
		else if (window.wrappedJSObject)
			unsafeWindow = window.wrappedJSObject;
	}
}

// Disable SPF (Structured Page Fragments), which prevents properly attaching to page load events when navigation occurs
// Will also disable the red loading bar.
//
// Props Anon via YouTube Cinema Mode userscript
// https://greasyfork.org/en/scripts/10417-youtube-cinema-mode
function disableSPF()
{
	if (unsafeWindow._spf_state && unsafeWindow._spf_state.config)
	{
		unsafeWindow._spf_state.config['navigate-limit'] = 0;
		unsafeWindow._spf_state.config['navigate-part-received-callback'] = function (targetUrl) { location.href = targetUrl; }
	}

	setTimeout(disableSPF, 50);
}

// flash + html5 requires manually resizing the stage
function resizeStage() {
	var playlist,
		newPlayer = document.querySelector('button.ytp-size-button');

	// 2017 redesign.
	if ( newPlayer ) {
		newPlayer.click();

	// Older.
	} else {
		document.getElementById('page').className = "watch watch-stage-mode watch-wide";
		document.getElementById('player').className = "content-alignment watch-medium";
		document.getElementById('watch7-container').className = "watch-wide";

		// handle playlists
		playlist = document.getElementById('watch-appbar-playlist');
		if (playlist) {
			playlist.setAttribute('style', 'top:120px');
		}
	}
}

/** TIME FOR SOME ACTION! **/

// get rid of SPF
installUnsafewindowPolyfill();
disableSPF();

// resize after document is loaded
window.addEventListener ("load", function() {
	resizeStage();
});