SHARE
TWEET

Show only not watched videos

LuizZeroxis Dec 9th, 2017 (edited) 423 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.     var elements = document.getElementsByClassName("pl-video yt-uix-tile");
  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("resume-playback-progress-bar");
  22.         if (children.length>0) {
  23.             //delete it!
  24.             elements[i].remove();
  25.         }
  26.     }
  27.    
  28.     if(document.querySelector('.load-more-button') != null){
  29.         //scroll down
  30.         window.scrollTo(0,document.body.scrollHeight);
  31.         //click the load more button
  32.         document.querySelector('.load-more-button').click();
  33.         //redo it again
  34.         setTimeout(function(){deleteMore()}, 500);
  35.     } else {
  36.         //in case there's no more load more button (looped through all videos)
  37.         //change all links to remove the annoying playlist links
  38.         var links = document.getElementsByTagName("A");
  39.         for(i=links.length-1;i>=0;i--) {
  40.             url = links[i].getAttribute('href');
  41.             if (url!=null) {
  42.                 url = updateQueryStringParameter(url,'list','');
  43.                 links[i].setAttribute('href',url);
  44.             }
  45.         }
  46.        
  47.         console.log("... IS DONE! *metal riffs*"); 
  48.     }
  49. }
  50.  
  51. 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