Greasy Fork is available in English.

Youtube Ad Remover

Removes annoying ad in Suggested Video List.

  1. // ==UserScript==
  2. // @name Youtube Ad Remover
  3. // @namespace YoutubeAdRemover
  4. // @version 0.4
  5. // @description Removes annoying ad in Suggested Video List.
  6. // @author shellster
  7. // @match https://www.youtube.com/watch*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var MutationObserver = window.MutationObserver;
  15. var myObserver = new MutationObserver (mutationHandler);
  16. var obsConfig = {
  17. childList: true, attributes: true,
  18. subtree: true, attributeFilter: ['class']
  19. };
  20.  
  21. myObserver.observe (document, obsConfig);
  22.  
  23. function mutationHandler (mutationRecords) {
  24. mutationRecords.forEach ( function (mutation) {
  25.  
  26. if (mutation.type == "childList"
  27. && typeof mutation.addedNodes == "object"
  28. && mutation.addedNodes.length
  29. )
  30. {
  31. for (var J = 0, L = mutation.addedNodes.length; J < L; ++J) {
  32. checkForAD(mutation.addedNodes[J]);
  33. }
  34. }
  35. else if (mutation.type == "attributes") {
  36. checkForAD(mutation.target);
  37. }
  38. } );
  39. }
  40.  
  41. function checkForAD(node) {
  42. //-- Only process element nodes
  43. if (node.nodeType === 1) {
  44. if(node.nodeName.toLowerCase().indexOf('promoted') != -1)
  45. {
  46. try
  47. {
  48. node.parentNode.removeChild(node);
  49. }
  50. catch(ex){}
  51. }
  52. }
  53. }
  54.  
  55. function walkTheDOM(node, func) {
  56. func(node);
  57. node = node.firstChild;
  58. while (node) {
  59. walkTheDOM(node, func);
  60. node = node.nextSibling;
  61. }
  62. }
  63.  
  64. walkTheDOM(document.body, checkForAD);
  65. })();