Skip to content

Instantly share code, notes, and snippets.

@Nielk1
Created August 29, 2016 22:02
Show Gist options
  • Save Nielk1/fff3d1b66549a5ad2e1eb9c76f10ad13 to your computer and use it in GitHub Desktop.
Save Nielk1/fff3d1b66549a5ad2e1eb9c76f10ad13 to your computer and use it in GitHub Desktop.
Add a button to remove watched videos from page
// ==UserScript==
// @name Remove Watched Button
// @namespace http://nielk1.com/
// @version 1.0
// @description Add a button to remove watched videos from page
// @author You
// @match https://www.youtube.com/feed/subscriptions
// @grant none
// ==/UserScript==
// Best Used With https://chrome.google.com/webstore/detail/better-youtube-watch-hist/lleajdkalfbohpinoaekajagdefaeckd?utm_source=chrome-app-launcher-info-dialog
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main(){
jQ(document).ready(function() {
jQ('.appbar-nav-menu').append('<li><a href="#" id="script_clear_watched_videos" class="yt-uix-button spf-link yt-uix-sessionlink yt-uix-button-epic-nav-item yt-uix-button-size-default" aria-selected="false"><span class="yt-uix-button-content">Clear Watched</span></a></li>');
jQ('#script_clear_watched_videos').on('click',function(evt){
evt.preventDefault();
jQ('.yt-shelf-grid-item>.watched').each(function(idx,elem){jQ(elem).parent().remove();});
jQ('.yt-shelf-grid-item>>>.watched').each(function(idx,elem){jQ(elem).parent().parent().parent().remove();});
});
});
}
// load jQuery and execute the main function
addJQuery(main);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment