Skip to content

Commit

Permalink
Wrap JSON.parse into userScriptStartAdBlock function
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeSmaha committed Dec 3, 2023
1 parent 9821083 commit 57c5dc5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dist/adblockMain.js

Large diffs are not rendered by default.

64 changes: 33 additions & 31 deletions src/adblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@
/* global fetch:writable */
import { configRead } from './config';

export function userScriptStartAdBlock() {}
export function userScriptStartAdBlock() {

/**
* This is a minimal reimplementation of the following uBlock Origin rule:
* https://github.com/uBlockOrigin/uAssets/blob/3497eebd440f4871830b9b45af0afc406c6eb593/filters/filters.txt#L116
*
* This in turn calls the following snippet:
* https://github.com/gorhill/uBlock/blob/bfdc81e9e400f7b78b2abc97576c3d7bf3a11a0b/assets/resources/scriptlets.js#L365-L470
*
* Seems like for now dropping just the adPlacements is enough for YouTube TV
*/
const origParse = JSON.parse;
JSON.parse = function () {
const r = origParse.apply(this, arguments);
if (r.adPlacements && configRead('enableAdBlock')) {
console.log('Adblock Removed !');
r.adPlacements = [];
}
/**
* This is a minimal reimplementation of the following uBlock Origin rule:
* https://github.com/uBlockOrigin/uAssets/blob/3497eebd440f4871830b9b45af0afc406c6eb593/filters/filters.txt#L116
*
* This in turn calls the following snippet:
* https://github.com/gorhill/uBlock/blob/bfdc81e9e400f7b78b2abc97576c3d7bf3a11a0b/assets/resources/scriptlets.js#L365-L470
*
* Seems like for now dropping just the adPlacements is enough for YouTube TV
*/
const origParse = JSON.parse;
JSON.parse = function () {
const r = origParse.apply(this, arguments);
if (r.adPlacements && configRead('enableAdBlock')) {
console.log('Adblock Removed !');
r.adPlacements = [];
}

// Drop "masthead" ad from home screen
if (
r?.contents?.tvBrowseRenderer?.content?.tvSurfaceContentRenderer?.content
?.sectionListRenderer?.contents &&
configRead('enableAdBlock')
) {
console.log('Adblock Removed (2) !');
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents =
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents.filter(
(elm) => !elm.tvMastheadRenderer
);
}
// Drop "masthead" ad from home screen
if (
r?.contents?.tvBrowseRenderer?.content?.tvSurfaceContentRenderer?.content
?.sectionListRenderer?.contents &&
configRead('enableAdBlock')
) {
console.log('Adblock Removed (2) !');
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents =
r.contents.tvBrowseRenderer.content.tvSurfaceContentRenderer.content.sectionListRenderer.contents.filter(
(elm) => !elm.tvMastheadRenderer
);
}

return r;
};
return r;
};

}

0 comments on commit 57c5dc5

Please sign in to comment.