Skip to content

Commit

Permalink
remove ad tiles from horizontal shelf
Browse files Browse the repository at this point in the history
  • Loading branch information
alyyousuf7 committed Oct 25, 2023
1 parent 4540449 commit b1f1de5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.ipk
node_modules
dist
.DS_Store
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions src/adblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,36 @@ import { configRead } from './config';
const origParse = JSON.parse;
JSON.parse = function () {
const r = origParse.apply(this, arguments);
if (r.adPlacements && configRead('enableAdBlock')) {
if (!configRead('enableAdBlock')) {
return r;
}

if (r.adPlacements) {
r.adPlacements = [];
}

// Drop "masthead" ad from home screen
if (
const sectionListRenderer =
r?.contents?.tvBrowseRenderer?.content?.tvSurfaceContentRenderer?.content
?.sectionListRenderer?.contents &&
configRead('enableAdBlock')
) {
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents =
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents.filter(
(elm) => !elm.tvMastheadRenderer
?.sectionListRenderer;
if (sectionListRenderer?.contents) {
// Drop the full width ad card, usually appears at the top of the page
sectionListRenderer.contents = sectionListRenderer.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
);
});
}

return r;
Expand Down
2 changes: 1 addition & 1 deletion src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,5 @@ export function showNotification(text, time = 3000) {
}

setTimeout(() => {
showNotification('Press [GREEN] to open YTAF configuration screen');
showNotification('Press 🟩 to open YTAF configuration screen');
}, 2000);

0 comments on commit b1f1de5

Please sign in to comment.