Skip to content

Commit

Permalink
Added adblock for "autoplay" ad tile on home screen
Browse files Browse the repository at this point in the history
YouTube "recently" added a tile which is automatically selected and will
autoplay an ad on launch. This removes that tile
  • Loading branch information
pvrs12 committed Aug 30, 2023
1 parent af2098e commit 004b81f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions assets/appinfo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "youtube.leanback.v4",
"version": "0.3.1",
"version": "0.3.2",
"vendor": "My Company",
"type": "web",
"main": "index.html",
Expand Down Expand Up @@ -28,4 +28,4 @@
"dialAppName": "YouTube",
"disableBackHistoryAPI": true,
"supportGIP": true
}
}
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "youtube-webos",
"version": "0.3.1",
"version": "0.3.2",
"description": "Youtube App without ADs",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -51,4 +51,4 @@
"lint-staged": {
"*": "prettier --write --ignore-unknown"
}
}
}
28 changes: 24 additions & 4 deletions src/adblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,30 @@ JSON.parse = function () {
?.sectionListRenderer?.contents &&
configRead('enableAdBlock')
) {
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents =
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents.filter(
(elm) => !elm.tvMastheadRenderer
);
// remove masthead
let sectionContents = r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents;
sectionContents = sectionContents.filter(
(elm) => !elm.tvMastheadRenderer
);

// drop "autoplay" ad tile from home screen
let replacementSections = [];
for (let i = 0; i < sectionContents.length; ++i) {
let section = sectionContents[i];
let replacementItems = [];
let items = section.shelfRenderer.content.horizontalListRenderer.items;
for (let i = 0; i < items.length; ++i) {
let item = items[i];
// remove ad slot
if ("adSlotRenderer" in item) {
continue
}
replacementItems.push(item);
}
section.shelfRenderer.content.horizontalListRenderer.items = replacementItems;
replacementSections.push(section);
}
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents = replacementSections;
}

return r;
Expand Down

0 comments on commit 004b81f

Please sign in to comment.