Skip to content

Instantly share code, notes, and snippets.

@JorelAli
Last active April 11, 2019 01:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JorelAli/e3097626f98c7dd2580ee1b1872ebfeb to your computer and use it in GitHub Desktop.
Save JorelAli/e3097626f98c7dd2580ee1b1872ebfeb to your computer and use it in GitHub Desktop.
A bookmarklet to help retrieve information on deleted videos in a YouTube playlist
javascript: /* Video salvager bookmarklet */
/*
Usage: Run this bookmarklet when viewing a list of a playlist.
The link should be something like https://www.youtube.com/playlist?list=[BUNCH_OF_LETTERS_AND_NUMBERS]
Why use this: There have been too many times that I've lost the title of an important
YouTube video from a playlist of mine and have no idea what the video title was called.
Unfortunately, this no longer works for certain playlists (for example, Watch Later) as
YouTube will automatically remove them from the playlist if a video within it was deleted.
*/
/* Find elements which have video information */
var vidElements = document.getElementsByClassName('yt-simple-endpoint style-scope ytd-playlist-video-renderer');
/* Generate dialog */
var vidDialog = document.createElement('div'); /*Styling*/
vidDialog.id = 'vidDialog';
vidDialog.style.position = 'fixed';
vidDialog.style.left = '30px';
vidDialog.style.top = '30px';
vidDialog.style.borderStyle = 'solid';
vidDialog.style.borderWidth = '2px';
vidDialog.style.padding = '5px';
vidDialog.style.backgroundColor = 'beige';
vidDialog.style.zIndex = 3141592653; /*Dimensions*/
vidDialog.style.width = '300px';
vidDialog.style.height = '200px';
/* List of Google URLs for missing videos */
var elementArr = [];
for(var i = 0; i < vidElements.length; i++) {
/* Find deleted video elements */
if(vidElements[i].children[1].children[0].children[1].title == '[Deleted video]') {
/* Find URL for said deleted video */
var hr = vidElements[i].children[0].children[0].href;
/* Salvage video ID code */
var re = /v=[A-Za-z0-9_-]+/g;
var idCode = hr.match(re)[0].substring(2);
/* Add to array*/
elementArr.push(idCode);
}
}
/* Function to close the dialog */
function closevidDialog() {
document.getElementById('vidDialog').remove();
}
/* Content for dialog*/
var innerHTMLContent = `
<style>
#vidDialog {all: initial; font-family: Helvetica; overflow: auto;}
#vidDialog div {position:absolute; top:2px; right:2px; color: blue;}
#vidDialog a {color: blue;}`;
/* Red if more than 1 deleted video */
if(elementArr.length == 0) {
innerHTMLContent = innerHTMLContent.concat('#vidDialog abbr {color: green;}')
} else {
innerHTMLContent = innerHTMLContent.concat('#vidDialog abbr {color: red;}')
}
innerHTMLContent = innerHTMLContent.concat(`</style>
<div><a onclick=closevidDialog()>[Close]</a></div>
<p>There are <abbr>` + elementArr.length + `</abbr> missing videos</p>`);
/* Include links if there are deleted videos */
if(elementArr.length != 0) {
innerHTMLContent = innerHTMLContent.concat(`
<p><i>Here are the missing video IDs. Click the video ID to search for it on Google</i></p>
<ul>`);
for(var i = 0; i < elementArr.length; i++) {
innerHTMLContent = innerHTMLContent.concat('<li><a onclick=window.open(`http://www.google.com/search?q=' + elementArr[i] + '`,`_blank`)>' + elementArr[i] + '</a></li>');
}
innerHTMLContent = innerHTMLContent.concat(`</ul>`);
}
/*Add to document*/
vidDialog.innerHTML = innerHTMLContent;
document.documentElement.appendChild(vidDialog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment