Greasy Fork is available in English.

YouTube - CardRemover

Remove YouTube end video cards overlay on top of videos

  1. // ==UserScript==
  2. // @name YouTube - CardRemover
  3. // @version 1.35
  4. // @description Remove YouTube end video cards overlay on top of videos
  5. // @author pengc99
  6. // @license GNU GPL v3.0
  7. // @namespace https://github.com/pengc99/tampermonkey_youtube_cardremover
  8. // @homepage https://github.com/pengc99/tampermonkey_youtube_cardremover
  9. // @include http://www.youtube.com/*
  10. // @include https://www.youtube.com/*
  11. // @include http://youtube.com/*
  12. // @include https://youtube.com/*
  13. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABmJLR0QA/wD/AP+gvaeTAAABJElEQVRIie2WTYrCQBBGn4MTVypkMTDOicSNXkMzXtIZf0BFcKFr9QSJ+7joirRJRzTpRkE/KEi+dOqliuok8NarqQMcgNhy7IH2NfDeATSJnQ6qpMDxDV0pozPvwzEoV9UcP92Jssp08mEV3wuuAb/AFDhKTIAA8Mo8SDKBJv0AK/Kndgm0CuS9uqCWgg4AH6gDXWAj/gJz5YXBQy6rWwNf2vWmBh/YBM+0pOsceE/8iU1wJL4vMBO8IV5oExyKX5dzE9x3AZ6K39W8NDyQ47FNcJJ0gxokEzyJvk2wh9qnMbBFDVID1d5Au28OfNoEg3o5LLmsTo858F0g700LPNSWGqMmPQL+Ue01VWoNXFSZvE/3PXb9J5Kp+M8ha+Qw91tPqBNQe7BEabp3fAAAAABJRU5ErkJggg==
  14. // ==/UserScript==
  15.  
  16. var cardElement = "ytp-ce-element";
  17.  
  18. /**
  19. * waitForKeyElements.js (CoeJoder Fork) - https://github.com/CoeJoder/waitForKeyElements.js
  20. *
  21. * A utility function for userscripts that detects and handles AJAXed content.
  22. *
  23. * Usage example:
  24. *
  25. * function callback(domElement) {
  26. * domElement.innerHTML = "This text inserted by waitForKeyElements().";
  27. * }
  28. *
  29. * waitForKeyElements("div.comments", callback);
  30. * // or
  31. * waitForKeyElements(selectorFunction, callback);
  32. *
  33. * @param {(string|function)} selectorOrFunction - The selector string or function.
  34. * @param {function} callback - The callback function; takes a single DOM element as parameter.
  35. * If returns true, element will be processed again on subsequent iterations.
  36. * @param {boolean} [waitOnce=true] - Whether to stop after the first elements are found.
  37. * @param {number} [interval=300] - The time (ms) to wait between iterations.
  38. * @param {number} [maxIntervals=-1] - The max number of intervals to run (negative number for unlimited).
  39. */
  40. function waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals) {
  41. if (typeof waitOnce === "undefined") {
  42. waitOnce = true;
  43. }
  44. if (typeof interval === "undefined") {
  45. interval = 300;
  46. }
  47. if (typeof maxIntervals === "undefined") {
  48. maxIntervals = -1;
  49. }
  50. var targetNodes = (typeof selectorOrFunction === "function")
  51. ? selectorOrFunction()
  52. : document.querySelectorAll(selectorOrFunction);
  53.  
  54. var targetsFound = targetNodes && targetNodes.length > 0;
  55. if (targetsFound) {
  56. targetNodes.forEach(function(targetNode) {
  57. var attrAlreadyFound = "data-userscript-alreadyFound";
  58. var alreadyFound = targetNode.getAttribute(attrAlreadyFound) || false;
  59. if (!alreadyFound) {
  60. var cancelFound = callback(targetNode);
  61. if (cancelFound) {
  62. targetsFound = false;
  63. }
  64. else {
  65. targetNode.setAttribute(attrAlreadyFound, true);
  66. }
  67. }
  68. });
  69. }
  70.  
  71. if (maxIntervals !== 0 && !(targetsFound && waitOnce)) {
  72. maxIntervals -= 1;
  73. setTimeout(function() {
  74. waitForKeyElements(selectorOrFunction, callback, waitOnce, interval, maxIntervals);
  75. }, interval);
  76. }
  77. }
  78.  
  79. function removeCards () {
  80. console.log("## Entered removeCards()");
  81. while (document.getElementsByClassName(cardElement).length != 0) {
  82. console.log("## Removing " + cardElement);
  83. document.getElementsByClassName(cardElement)[0].remove();
  84. }
  85. }
  86.  
  87. waitForKeyElements ("div." + cardElement, removeCards);