Skip to content

Instantly share code, notes, and snippets.

@FrnandMG
Last active June 26, 2021 21:47
Show Gist options
  • Save FrnandMG/8c81daa5b8bc052b3126 to your computer and use it in GitHub Desktop.
Save FrnandMG/8c81daa5b8bc052b3126 to your computer and use it in GitHub Desktop.
YouTube Stop Autoplay (play one video at a time)
// ==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