Last active
June 26, 2021 21:47
-
-
Save FrnandMG/8c81daa5b8bc052b3126 to your computer and use it in GitHub Desktop.
YouTube Stop Autoplay (play one video at a time)
This file contains hidden or 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
// ==UserScript== | |
// @name Youtube Flash stop autoplay | |
// @namespace http://localhost | |
// @description Prevents autoplay. | |
// @include http://www.youtube.com/* | |
// @include https://www.youtube.com/* | |
// @exclude http://www.youtube.com/embed/* | |
// @exclude https://www.youtube.com/embed/* | |
// @match http://www.youtube.com/* | |
// @match https://www.youtube.com/* | |
// @match http://s.ytimg.com/yts/jsbin/html5player* | |
// @match https://s.ytimg.com/yts/jsbin/html5player* | |
// @match http://*.googlevideo.com/videoplayback* | |
// @match https://*.googlevideo.com/videoplayback* | |
// @match http://*.youtube.com/videoplayback* | |
// @match https://*.youtube.com/videoplayback* | |
// @version 1.0 | |
// ==/UserScript== | |
function noAutoplay() { | |
if(document.embeds.length!=0) | |
document.body.removeEventListener("DOMNodeInserted",noAutoplay,false); | |
for(i in document.embeds) { | |
var source = document.getElementById(document.embeds[i].getAttribute("id")).parentNode; | |
var attr = source.innerHTML; | |
attr = attr.replace(/(ad_module|ad._module|autoplay|ad_[a-z_]+)=[^&]+?/gi,""); | |
attr = attr.replace(/(flashvars=\"[^\"]+)/g,"$1&autoplay=0"); | |
attr = attr.replace(/(&){2,}/gi,"&"); | |
source.innerHTML = attr; | |
} | |
}; | |
if(document.embeds.length==0) { | |
document.body.addEventListener("DOMNodeInserted",noAutoplay,false); | |
} else { | |
noAutoplay(); | |
} | |
return; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment