Skip to content

Commit

Permalink
Merge pull request #8 from Informatic/various-fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
FriedChickenButt authored Jun 5, 2021
2 parents 7fd3871 + c6f4180 commit 3ec13ef
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
4 changes: 4 additions & 0 deletions appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 27 additions & 12 deletions webOSUserScripts/userScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,37 +24,53 @@ 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);
};

/**
* 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;
};

0 comments on commit 3ec13ef

Please sign in to comment.