From 245f4e22e4ae1c59fb60cbbfd98cdaabdc72f0af Mon Sep 17 00:00:00 2001 From: Ali Yousuf Date: Wed, 25 Oct 2023 03:47:05 -0400 Subject: [PATCH] remove ad tiles from horizontal shelf in search result --- src/adblock.js | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/adblock.js b/src/adblock.js index 6176d2c5..572cbe64 100644 --- a/src/adblock.js +++ b/src/adblock.js @@ -22,29 +22,41 @@ JSON.parse = function () { r.adPlacements = []; } - const sectionListRenderer = + // remove ads from home + const homeSectionListRenderer = r?.contents?.tvBrowseRenderer?.content?.tvSurfaceContentRenderer?.content ?.sectionListRenderer; - if (sectionListRenderer?.contents) { + if (homeSectionListRenderer?.contents) { // Drop the full width ad card, usually appears at the top of the page - sectionListRenderer.contents = sectionListRenderer.contents.filter( + homeSectionListRenderer.contents = homeSectionListRenderer.contents.filter( (elm) => !elm.tvMastheadRenderer ); // Drop ad tile from the horizontal shelf - // Target to remove: - // contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents[0].shelfRenderer.content.horizontalListRenderer.items[0].adSlotRenderer - const contentsWithShelfRenderer = sectionListRenderer.contents.filter( - (elm) => elm.shelfRenderer - ); - contentsWithShelfRenderer.forEach((content) => { - const horizontalRenderer = - content.shelfRenderer.content.horizontalListRenderer; - horizontalRenderer.items = horizontalRenderer.items.filter( - (elm) => !elm.adSlotRenderer - ); - }); + removeAdSlotRenderer(homeSectionListRenderer); + } + + // remove ad tile from search + const searchSectionListRenderer = r?.contents?.sectionListRenderer; + if (searchSectionListRenderer?.contents) { + removeAdSlotRenderer(searchSectionListRenderer); } return r; }; + +// Drop ad tile from the horizontal shelf +// Target to remove: +// sectionListRenderer.contents[0].shelfRenderer.content.horizontalListRenderer.items[0].adSlotRenderer +function removeAdSlotRenderer(sectionListRenderer) { + const contentsWithShelfRenderer = sectionListRenderer.contents.filter( + (elm) => elm.shelfRenderer + ); + contentsWithShelfRenderer.forEach((content) => { + const horizontalRenderer = + content.shelfRenderer.content.horizontalListRenderer; + horizontalRenderer.items = horizontalRenderer.items.filter( + (elm) => !elm.adSlotRenderer + ); + }); +}