Skip to content

Instantly share code, notes, and snippets.

@lrstanley
Last active February 2, 2022 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lrstanley/789622b4c196c33d4e122bdc5d01da39 to your computer and use it in GitHub Desktop.
Save lrstanley/789622b4c196c33d4e122bdc5d01da39 to your computer and use it in GitHub Desktop.
Voilent/Tamper/Grease Monkey scripts for YouTube
// ==UserScript==
// @name YouTube Disable Watch Later Autoplay
// @namespace lrstanley
// @match https://www.youtube.com/*
// @grant none
// @version 1.0.4
// @downloadURL https://gist.githubusercontent.com/lrstanley/789622b4c196c33d4e122bdc5d01da39/raw/yt_disable_watchlater_autoplay.js
// @updateURL https://gist.githubusercontent.com/lrstanley/789622b4c196c33d4e122bdc5d01da39/raw/yt_disable_watchlater_autoplay.js
// @author Liam Stanley
// @description This script disables the auto-play functionality for "Watch later" playlists. Watch later playlists ignore the user-configured auto-play option, so there is no way to disable it by default.
// @noframes
// ==/UserScript==
(function() {
'use strict';
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function replaceLinks() {
await sleep(1000);
if (!window.location.pathname.startsWith("/playlist")) {
return
}
let video_links = document.querySelectorAll('a#video-title[href^="/watch"], a#thumbnail.yt-simple-endpoint.inline-block.ytd-thumbnail[href^="/watch"]');
for (let i = 0; i < video_links.length; i++) {
let orig_dest = video_links[i].href;
// example: https://www.youtube.com/watch?v=EXAMPLE&list=WL&index=1&t=3s
let new_dest = orig_dest.split("&list")[0];
video_links[i].data = null; // remove YouTubes data object that tries to override on outbound links.
video_links[i].href = new_dest;
}
}
document.addEventListener('yt-navigate-finish', replaceLinks);
replaceLinks();
})();
// ==UserScript==
// @name YouTube Misc. Enhancements
// @namespace lrstanley
// @match https://www.youtube.com/*
// @grant none
// @version 1.0.2
// @downloadURL https://gist.githubusercontent.com/lrstanley/789622b4c196c33d4e122bdc5d01da39/raw/yt_misc.js
// @updateURL https://gist.githubusercontent.com/lrstanley/789622b4c196c33d4e122bdc5d01da39/raw/yt_misc.js
// @author lrstanley
// @description YouTube Misc. Enhancements
// @run-at document-end
// @noframes
// ==/UserScript==
(function main() {
'use strict';
// Auto-pause video.
var vid = document.getElementsByClassName("html5-main-video")[0];
vid.addEventListener('loadeddata', function() {
vid.pause();
}, true);
// Auto-expand video details.
setTimeout(function() {
document.querySelector("tp-yt-paper-button.ytd-expander#more").click()
let prev_onscroll = window.onscroll;
window.onscroll = function () { window.scrollTo(0, 0); };
setTimeout(function() { window.onscroll = prev_onscroll }, 5000);
}, 1000);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment