Last active
November 28, 2022 18:29
-
-
Save yasirkula/efbb784ad49c304794f0be66560d8f47 to your computer and use it in GitHub Desktop.
Restore fullscreen button on embedded YouTube videos (Chrome Extension)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkDocument = function( doc ) | |
{ | |
var frames = doc.getElementsByTagName( "iframe" ); | |
for( var i = 0, l = frames.length; i < l; i++ ) | |
checkIframe( frames[i] ); | |
}; | |
var checkIframe = function(iframe) | |
{ | |
if( iframe.src.indexOf( "https://www.youtube" ) == 0 ) | |
{ | |
iframe.src = iframe.src.replace( "?fs=0", "" ).replace( "&fs=0", "" ).replace( "?controls=0", "?controls=1" ).replace( "&controls=0", "&controls=1" ); | |
iframe.setAttribute( "allowfullscreen", "0" ); | |
if( iframe.hasAttribute( "donotallowfullscreen" ) ) | |
iframe.removeAttribute( "donotallowfullscreen" ); | |
} | |
else if( iframe.hasAttribute( "data-src" ) && iframe.getAttribute( "data-src" ).indexOf( "https://www.youtube" ) == 0 ) | |
{ | |
iframe.setAttribute( "data-src", iframe.getAttribute( "data-src" ).replace( "?fs=0", "" ).replace( "&fs=0", "" ).replace( "?controls=0", "?controls=1" ).replace( "&controls=0", "&controls=1" ) ); | |
iframe.setAttribute( "allowfullscreen", "0" ); | |
if( iframe.hasAttribute( "donotallowfullscreen" ) ) | |
iframe.removeAttribute( "donotallowfullscreen" ); | |
} | |
else if( iframe.src.indexOf( "https://twitter.com" ) == 0 ) | |
{ | |
// Support for YouTube embedded videos on Twitter | |
if( iframe.src.indexOf( "cardname=player" ) > 0 ) | |
iframe.addEventListener( "load", iframeLoaded ); | |
} | |
}; | |
var iframeLoaded = function( e ) | |
{ | |
e.target.removeEventListener( "load", iframeLoaded ); | |
checkDocument( e.target.contentDocument || e.target.contentWindow.document ); | |
}; | |
var observerCallback = function( mutationsList, observer ) | |
{ | |
for( var mutation of mutationsList ) | |
{ | |
if( mutation.type == 'childList' ) | |
{ | |
var addedNodes = mutation.addedNodes; | |
for( var i = 0; i < addedNodes.length; i++ ) | |
{ | |
if( addedNodes[i].nodeName == "IFRAME" ) | |
checkIframe( addedNodes[i] ); | |
} | |
} | |
} | |
}; | |
checkDocument( document ); | |
var observer = new MutationObserver( observerCallback ); | |
observer.observe( document.body, { childList: true, subtree: true } ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "YouTube Fullscreen Button", | |
"version": "1.0", | |
"description": "Bring back the fullscreen button to embedded YouTube videos", | |
"content_scripts": [{ | |
"js": ["content.js"], | |
"matches": ["https://*/*", "http://*/*"] | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Speaking of those who stumble here in search of a solution, here's one that actually works: https://greasyfork.org/en/scripts/829-restore-youtube-embed-defaults