Disable SPF Youtube

Disables red bar aka SPF on youtube. This userscript is needed to work properly other userscripts on youtube site. This script must be first to be executed, example before Youtube+ or other good userscripts.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @author mkdante381
// @name Disable SPF Youtube
// @namespace https://greasyfork.org/users/9905
// @description Disables red bar aka SPF on youtube. This userscript is needed to work properly other userscripts on youtube site. This script must be first to be executed, example before Youtube+ or other good userscripts.
// @homepageURL https://greasyfork.org/scripts/16935
// @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAXCAIAAADlZ9q2AAAACXBIWXMAAAB2AAAAdgFOeyYIAAAFwElEQVRIx3VVbWwcVxU99703Hzsza8efiT/ixbEraENaN4mRqkiVoqJKpCUkoBb4QZVCBWqlRkJC4i8IxB+EBEJqUSuFoKqtFEhAVWljUoT4iEOMa0gMpHFaJ3ZNEju7tned3Z15M+9dfqzTxI57f765755z7z1nHjEzAADm+jV94T9cqdhqFVqzTjhOOIk5MzApjIUUMJaZwRbMzraB6NAzWBNsy2VbLIqODtHU3DiiBkDp2W8s/+KIAMgFpIAQYGZjkAEGDQq5Pbtzj30+3H/Q2b4DAGyWjJ2N/zWRXpwy71/Ul6bSizN8C6r9hZ81P3t4FWD5h99b+sH3VaEgfB9EzAxrhec527c799xDra1qS5ds36zPTdRHR/X4WHZ5ji0AEEAeKAgpDMjzyXWhFACuVtPpuc3HXg+f+AqZ8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zPRGxEA2aplrlJIE1ztBQ/jvfDfcfkN09jbRsYb4+crL2zh+S039Lzl1gIAO2XZpSqqeHLdiY9QY2BmnKWrPWyDKKgtyBA+EXv+Te92kolbz7rp6cnD/4mP7gki3VAJCCCDwKAsoF7r0DAHDhA/JcYmNmOptEmBebNq3ZVZY5AwPO7p1yS5dqa6cwH58ZjU+N6PPnV7WrFHk+haEIAjjOuvGa5SUQ+q5cVxCi45XXr+/b7wiiKA8iGMNay5aWdG62NnKKM/CtgdKtX7o79KB3//1ya8HMzerxsexG6U5yXK1ms/Nbfveb229y9bVXFp5+yujVEk5Xi+ztcwYHZf+A84l+WSjI7m73k/eS4wKwpWL1+K/rf/5j7dhxZpAjIAWYYSwb5gwAOo68nH/6mdsADWhOEghBjguiDRdePX4snTzP1pLnUc4n5YAZrit8n3I5uB55nmxrd3c8QLce4P8DB/PgzhUEOfoAAAAASUVORK5CYII=
// @domain      youtube.com
// @domain      www.youtube.com
// @domain      gdata.youtube.com
// @domain      apis.google.com
// @domain      plus.googleapis.com
// @domain      googleapis.com
// @domain      s.ytimg.com
// @match       *://*.youtube.com/*
// @match       *://*.googlevideo.com/*
// @match       *://s.ytimg.com/yts/jsbin/*
// @match       *://*.ytimg.com/yts/jsbin/*
// @include     http://www.youtube.com/watch*
// @include     https://www.youtube.com/watch*
// @include     *://www.youtube.com/*
// @include     *youtube.com/*
// @include     *://*googlevideo.com/*
// @include     *googlevideo.com/*
// @include     http*://*.googlevideo.com/*
// @include     http*://*---*.googlevideo.com/*
// @include     http*://*s.ytimg*
// @include     http*://*s.img*
// @include     http*://s.ytimg*
// @include     http*://s.img*
// @include     *.ytimg.com*
// @version     1.0.3.2
// @grant       unsafeWindow
// @run-at      document-start
// ==/UserScript==
// Ensure unsafeWindow object is available both in firefox and chrome
//

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.

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);
}

/** TIME FOR SOME ACTION! **/

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