Skip to content

Instantly share code, notes, and snippets.

@Maxr1998
Last active February 28, 2023 00:51
Show Gist options
  • Save Maxr1998/f07175ad05ed5c783da9b98bceee61a6 to your computer and use it in GitHub Desktop.
Save Maxr1998/f07175ad05ed5c783da9b98bceee61a6 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Disable YouTube playlists
// @description Remove playlist part from watched videos
// @namespace https://gist.github.com/Maxr1998/f07175ad05ed5c783da9b98bceee61a6
// @downloadURL https://gist.github.com/Maxr1998/f07175ad05ed5c783da9b98bceee61a6/raw/2b47f9d7949f95b1b6e50f3be79d49ac48f95af7/disable_youtube_playlists.user.js
// @updateURL https://gist.github.com/Maxr1998/f07175ad05ed5c783da9b98bceee61a6/raw/2b47f9d7949f95b1b6e50f3be79d49ac48f95af7/disable_youtube_playlists.user.js
// @author Maxr1998
// @version 0.1.1
// @match *://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?domain=youtube.com
// @grant none
// @run-at document-start
// @license GNU GPLv3
// ==/UserScript==
function redirect() {
const listRegex = /&list=\w+&index=\d+/;
if (window.location.href.indexOf('youtube.com/watch') > -1) {
const previous = window.location.toString();
const normalized = previous.replace(listRegex, '');
if (previous !== normalized) {
window.location.replace(normalized);
}
}
}
redirect();
let oldHref = document.location.href;
window.onload = function() {
const bodyList = document.querySelector("body")
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (oldHref != document.location.href) {
oldHref = document.location.href;
console.log('location changed!');
redirect();
}
});
});
const config = {
childList: true,
subtree: true
};
observer.observe(bodyList, config);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment