Remove Ads Slots in YouTube Main Page

to remove ads slots in YouTube main page

当前为 2024-01-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Remove Ads Slots in YouTube Main Page
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.5
  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://update.greasyfork.org/scripts/465819/1304833/API%20for%20CustomElements%20in%20YouTube.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. customYtElements.whenRegistered('ytd-rich-grid-renderer', (proto) => {
  34. proto.dataChanged = ((dataChanged) => {
  35. return function () {
  36. removeAdsSlot(this);
  37. return dataChanged.apply(this, arguments);
  38. }
  39. })(proto.dataChanged)
  40. });
  41.  
  42. })();