YouTube - Remove watched videos button

Adds a button to remove all watched videos from the subscription page

当前为 2022-04-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube - Remove watched videos button
  3. // @description Adds a button to remove all watched videos from the subscription page
  4. // @author MetalTxus
  5. // @version 1.0.2
  6.  
  7. // @icon https://www.youtube.com/favicon.ico
  8. // @include https://www.youtube.com*
  9. // @namespace https://github.com/jesuscc1993/user-js
  10. // @require https://code.jquery.com/jquery-3.2.1.min.js
  11. // ==/UserScript==
  12.  
  13. /* globals jQuery */
  14.  
  15. (() => {
  16. 'use strict';
  17.  
  18. const shouldRender = () => {
  19. return location.href.includes('/subscriptions') || location.href.includes('/videos');
  20. }
  21.  
  22. const removeWatchedVideos = () => {
  23. jQuery('[id="progress"]').parents('ytd-grid-video-renderer').remove();
  24. }
  25.  
  26. const buttonElement = jQuery(`
  27. <tp-yt-paper-button class="style-scope ytd-subscribe-button-renderer" style="margin-top: 24px;">
  28. Remove Watched
  29. </tp-yt-paper-button>
  30. `);
  31.  
  32. const handleButtonPresence = () => {
  33. if (shouldRender()) {
  34. const containerElement = jQuery('ytd-shelf-renderer, ytd-browse:first ytd-two-column-browse-results-renderer #primary #header-container').first();
  35. if (containerElement.length && !containerElement.find(buttonElement).length) {
  36. buttonElement.click(removeWatchedVideos);
  37. containerElement.prepend(buttonElement);
  38. }
  39. } else {
  40. buttonElement.remove();
  41. }
  42. };
  43.  
  44. setInterval(handleButtonPresence, 150);
  45.  
  46. })();