Greasy Fork is available in English.

Remove Ads Slots in YouTube Main Page

to remove ads slots in YouTube main page

  1. // ==UserScript==
  2. // @name Remove Ads Slots in YouTube Main Page
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.6
  5. // @license MIT
  6. // @author CY Fung
  7. // @match https://www.youtube.com/*
  8. // @exclude /^https?://\S+\.(txt|png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  10. // @grant none
  11. // @run-at document-start
  12. // @require https://cdn.jsdelivr.net/gh/cyfung1031/userscript-supports@8fac46500c5a916e6ed21149f6c25f8d1c56a6a3/library/ytZara.js
  13. // @description to remove ads slots in YouTube main page
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. 'use strict';
  18. const wm = new WeakSet();
  19.  
  20. const removeAdsSlot = async (grid) => {
  21. const td = grid.data;
  22. if (td && !wm.has(td)) {
  23. const md = Object.assign({}, td);
  24. md.contents = md.contents.filter(content => {
  25. let isadSlotRenderer = ((((content || 0).richItemRenderer || 0).content || 0).adSlotRenderer || null) !== null;
  26. return isadSlotRenderer ? false : true;
  27. });
  28. wm.add(md);
  29. grid.data = md;
  30. }
  31. };
  32.  
  33. ytZara.ytProtoAsync("ytd-rich-grid-renderer").then((proto) => {
  34. proto.dataChanged = ((dataChanged) => {
  35. return function () {
  36. removeAdsSlot(this);
  37. return dataChanged.apply(this, arguments);
  38. }
  39. })(proto.dataChanged);
  40. });
  41.  
  42. })();