From e6d7c03dccb585426ef6f1a18ae3b4882df690d2 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Sun, 30 May 2021 23:35:32 +0200 Subject: [PATCH 1/3] appinfo: fix back button behaviour Seems like YouTube dynamically changes back button behaviour based on User-Agent. Changing user-agent is possible (as done by official app) only after setting "trustLevel" to "netcast". This however also moves "launchParams" from window.PalmSystem directly into window object, thus the second minor change. --- appinfo.json | 4 ++++ index.js | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/appinfo.json b/appinfo.json index 278b28f6..d63573b3 100644 --- a/appinfo.json +++ b/appinfo.json @@ -11,6 +11,10 @@ "accessibility": { "supportsAudioGuidance": true }, + "vendorExtension": { + "userAgent": "$browserName$/$browserVersion$ ($platformName$-$platformVersion$), _TV_$chipSetName$/$firmwareVersion$ (LG, $modelName$, $networkMode$)" + }, + "trustLevel": "netcast", "privilegedJail": true, "supportQuickStart": true, "dialAppName": "YouTube", diff --git a/index.js b/index.js index bfd30b17..85b3a5a9 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,9 @@ function concatenateUrlAndGetParams(ytUrl, path) { } function main() { - const launchParameters = window.PalmSystem.launchParams; + const launchParameters = window.PalmSystem + ? window.PalmSystem.launchParams + : window.launchParams; const youtubeLaunchUrlPath = extractLaunchUrlParams(launchParameters); window.location = concatenateUrlAndGetParams(YOUTUBE_TV_URL, youtubeLaunchUrlPath); From ee2e1077a1fcc9cfb2a5af0d4fda53a8404872bd Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Sun, 30 May 2021 23:36:05 +0200 Subject: [PATCH 2/3] userscript: fix syntax unsupported on webOS 3.x --- webOSUserScripts/userScript.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/webOSUserScripts/userScript.js b/webOSUserScripts/userScript.js index 14fabdf9..ed7ba6c9 100644 --- a/webOSUserScripts/userScript.js +++ b/webOSUserScripts/userScript.js @@ -11,8 +11,7 @@ const settings = { }; function isRequestBlocked(requestType, url) { - - console.log(`[${requestType}] URL : ${url}`); + console.log("[" + requestType + "] URL : " + url); if (settings.disable_ads && YOUTUBE_AD_REGEX.test(url)) { console.log("%cBLOCK AD", "color: red;", url); @@ -25,37 +24,36 @@ function isRequestBlocked(requestType, url) { } return false; - -}; +} /** * Reference - https://gist.github.com/sergeimuller/a609a9df7d30e2625a177123797471e2 - * + * * Wrapper over XHR. */ const origOpen = XMLHttpRequest.prototype.open; -XMLHttpRequest.prototype.open = function (...args) { +XMLHttpRequest.prototype.open = function () { const requestType = "XHR"; - const url = args[1]; + const url = arguments[1]; if (isRequestBlocked(requestType, url)) { throw "Blocked"; } - origOpen.apply(this, args); + origOpen.apply(this, arguments); }; /** * Wrapper over Fetch. */ -const origFetch = fetch; -fetch = function (...args) { +const origFetch = window.fetch; +fetch = function () { const requestType = "FETCH"; - const url = args[0]; + const url = arguments[0]; if (isRequestBlocked(requestType, url)) { return; } - return origFetch(...args); + return origFetch.apply(this, arguments); }; From c6f4180516d9d43d092ca6db4355b33ef529346a Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Sun, 30 May 2021 23:38:55 +0200 Subject: [PATCH 3/3] userscript: add newer ad filtering based on uBlock Origin rules --- webOSUserScripts/userScript.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webOSUserScripts/userScript.js b/webOSUserScripts/userScript.js index ed7ba6c9..f715a2e1 100644 --- a/webOSUserScripts/userScript.js +++ b/webOSUserScripts/userScript.js @@ -55,5 +55,22 @@ fetch = function () { return; } return origFetch.apply(this, arguments); +}; +/** + * 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) { + r.adPlacements = []; + } + return r; };