Skip to content

Commit

Permalink
remove ad tiles from horizontal shelf in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
alyyousuf7 committed Oct 25, 2023
1 parent 0148c1e commit 245f4e2
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/adblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});
}

0 comments on commit 245f4e2

Please sign in to comment.