Skip to content

Instantly share code, notes, and snippets.

@silvasur
Last active November 4, 2021 10:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silvasur/8ef9fdb73965130608b0aa9724335b63 to your computer and use it in GitHub Desktop.
Save silvasur/8ef9fdb73965130608b0aa9724335b63 to your computer and use it in GitHub Desktop.
Greasemonkey script to deactivate autoplay and remove suggestions from the YouTube video page
// ==UserScript==
// @name YouTube minus autoplay and suggestions
// @description Removes suggestions in sidebar and end of video. Also disables autoplay.
// @version 1
// @grant none
// @include https://www.youtube.com/watch*
// ==/UserScript==
(function() {
var styles = `
#related { display: none !important; }
.ytp-suggestion-set { display: none !important; }
`
document.head.appendChild((function(){
var s = document.createElement("style");
s.innerText = styles;
return s;
})());
function disable_autoplay() {
console.log("disable_autoplay");
var autoplay_toggle = document.querySelector("#toggle");
console.log(autoplay_toggle);
if (!autoplay_toggle) {
console.log("disable_autoplay(): Autoplay button not yet present. Will try again in 1s");
window.setTimeout(disable_autoplay, 1000);
return;
}
if (autoplay_toggle.attributes.getNamedItem("checked"))
autoplay_toggle.dispatchEvent(new Event("click"));
}
function onready() {
console.log("onready");
disable_autoplay();
}
function checkonready() {
if (document.readyState == "complete") {
onready();
onready = function () {};
}
}
checkonready();
document.addEventListener("readystatechange", checkonready);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment