SHARE
TWEET

Show only not watched videos [For new youtube design]

LuizZeroxis Dec 9th, 2017 (edited) 558 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Script for showing only watched videos on YouTube - more info in here: https://webapps.stackexchange.com/a/112602/173146
  2.  
  3. //function to edit url query strings
  4. function updateQueryStringParameter(uri, key, value) {
  5.   var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
  6.   var separator = uri.indexOf('?') !== -1 ? "&" : "?";
  7.   if (uri.match(re)) {
  8.     return uri.replace(re, '$1' + key + "=" + value + '$2');
  9.   }
  10.   else {
  11.     return uri + separator + key + "=" + value;
  12.   }
  13. }
  14.  
  15. function deleteMore() {
  16.     //search through all videos in playlist
  17.     elements = document.getElementsByTagName("ytd-playlist-video-renderer");
  18.    
  19.     for(i=elements.length-1;i>=0;i--) {
  20.         //check if there's a progress bar in the video (if it has you have watched it)
  21.         children = elements[i].getElementsByClassName("ytd-thumbnail-overlay-resume-playback-renderer");
  22.         if (children.length>0) {
  23.             //delete it!
  24.             elements[i].remove();
  25.         }
  26.     }
  27.    
  28.     //check if there's loading spinner in the bottom
  29.     if(document.getElementsByTagName('yt-next-continuation').length > 0){
  30.         //scroll down
  31.         window.scrollTo(0,document.getElementsByTagName('ytd-app')[0].scrollHeight);
  32.         //redo it again
  33.         setTimeout(function(){deleteMore()}, 500);
  34.     } else {
  35.         //in case there's no more loading (looped through all videos)
  36.         //change all links to remove the annoying playlist links
  37.         var links = document.getElementsByTagName("A");
  38.         for(i=links.length-1;i>=0;i--) {
  39.             url = links[i].getAttribute('href');
  40.             if (url!=null) {
  41.                 url = updateQueryStringParameter(url,'list','');
  42.                 links[i].setAttribute('href',url);
  43.             }
  44.         }
  45.        
  46.         console.log("... IS DONE! *metal riffs*"); 
  47.     }
  48. }
  49.  
  50. deleteMore();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top