Skip to content

Instantly share code, notes, and snippets.

@cadadr
Created February 27, 2020 22:16
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 cadadr/ba3eb6de942eba460fac330b8cdb24da to your computer and use it in GitHub Desktop.
Save cadadr/ba3eb6de942eba460fac330b8cdb24da to your computer and use it in GitHub Desktop.
Non-playlist links in YouTube playlists
// ==UserScript==
// @name youtube-non-playlist-links
// @version 1
// @grant none
// @namespace youtube.com/playlist
// @include https://www.youtube.com/playlist*
// @include https://youtube.com/playlist*
// ==/UserScript==
document.querySelectorAll(
'a.yt-simple-endpoint.ytd-playlist-video-renderer'
).forEach(function (vid) {
let url = new URL(vid.href);
let id = url.searchParams.get('v');
let title = vid.querySelector('span#video-title');
let text = title.textContent;
let newurl = new URL(url.origin);
newurl.pathname = url.pathname;
newurl.searchParams.set('v', id);
let sup = document.createElement('sup');
let a = document.createElement('a');
a.href = newurl.toLocaleString();
a.innerText = '[nopl]';
a.title = 'Non-playlist link, direct link to video.';
sup.appendChild(a);
title.appendChild(sup);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment