From b1f1de514c5cc0da0141eb57e30fa6a56484d180 Mon Sep 17 00:00:00 2001 From: Ali Yousuf Date: Wed, 25 Oct 2023 01:12:54 -0400 Subject: [PATCH] remove ad tiles from horizontal shelf --- .gitignore | 1 + .husky/pre-commit | 0 package-lock.json | 2 +- src/adblock.js | 34 +++++++++++++++++++++++++--------- src/ui.js | 2 +- 5 files changed, 28 insertions(+), 11 deletions(-) mode change 100644 => 100755 .husky/pre-commit diff --git a/.gitignore b/.gitignore index 6602020e..04db325f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.ipk node_modules dist +.DS_Store diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/package-lock.json b/package-lock.json index 59e17d97..9ef504b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "youtube-webos", - "version": "0.2.1", + "version": "0.3.1", "license": "GPL-3.0", "dependencies": { "@babel/runtime": "^7.16.7", diff --git a/src/adblock.js b/src/adblock.js index 6b7ecaee..6176d2c5 100644 --- a/src/adblock.js +++ b/src/adblock.js @@ -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; diff --git a/src/ui.js b/src/ui.js index 4bce127e..754a2696 100644 --- a/src/ui.js +++ b/src/ui.js @@ -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);