Skip to content

Commit

Permalink
Created basic webOS app with basic ad-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedChickenButt committed Apr 4, 2021
1 parent 5e09daf commit 7f7a353
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# youtube-webos
Youtube App without ADs

## Pre-requisites
* Install webOS SDK - https://webostv.developer.lge.com/sdk/installation/
* Setup webOS app testing to load apps in developer mode - https://webostv.developer.lge.com/develop/app-test

## Building
* Clone the repository
```
git clone https://github.com/FriedChickenButt/youtube-webos.git
```
* Enter the folder and build the App, this will generate a `*.ipk` file.
```
cd youtube-webos && ares-package .
```

## Installation
```
ares-install -d <alias of your TV> <.ipk file>
```

## Launching
* The app will be available in the TV's app list or launch it using ares-cli.
```
ares-launch -d <alias of your TV> com.youtube.noads
```
10 changes: 10 additions & 0 deletions appinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "com.youtube.noads",
"version": "0.0.1",
"vendor": "My Company",
"type": "web",
"main": "index.html",
"title": "Youtube Without ADs",
"icon": "icon.png",
"largeIcon": "largeIcon.png"
}
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>

<head>
<style type="text/css">
body {
width: 100%;
height: 100%;
background-color: #202020;
}

div {
position: absolute;
height: 100%;
width: 100%;
display: table;
}

h1 {
display: table-cell;
vertical-align: middle;
text-align: center;
color: #FFFFFF;
}
</style>
<!-- <script src="webOSTVjs-1.2.0/webOSTV.js" charset="utf-8"></script>
<script src="webOSTVjs-1.2.0/webOSTV-dev.js" charset="utf-8"></script> -->
<script type="text/javascript">
window.location = "https://youtube.com/tv";
</script>
</head>

</html>
Binary file added largeIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions webOSUserScripts/userScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const YOUTUBE_REGEX = /^https?:\/\/(\w*.)?youtube.com/i;
const YOUTUBE_AD_REGEX = /(doubleclick\.net)|(adservice\.google\.)|(youtube\.com\/api\/stats\/ads)|(&ad_type=)|(&adurl=)|(-pagead-id.)|(doubleclick\.com)|(\/ad_status.)|(\/api\/ads\/)|(\/googleads)|(\/pagead\/gen_)|(\/pagead\/lvz?)|(\/pubads.)|(\/pubads_)|(\/securepubads)|(=adunit&)|(googlesyndication\.com)|(innovid\.com)|(youtube\.com\/pagead\/)|(google\.com\/pagead\/)|(flashtalking\.com)|(googleadservices\.com)|(s0\.2mdn\.net\/ads)|(www\.youtube\.com\/ptracking)|(www\.youtube\.com\/pagead)|(www\.youtube\.com\/get_midroll_)/;
const YOUTUBE_ANNOTATIONS_REGEX = /^https?:\/\/(\w*.)?youtube\.com\/annotations_invideo\?/;

console.log("%cYT ADBlocker is loading...", "color: green;");

// Set these accoring to your preference
const settings = {
disable_ads: true,
disable_annotations: false,
};

const isRequestBlocked = (requestType, url) => {

console.log(`[${requestType}] URL : ${url}`);

if (settings.disable_ads && YOUTUBE_AD_REGEX.test(url)) {
console.log("%cBLOCK AD", "color: red;", url);
return true;
}

if (settings.disable_annotations && YOUTUBE_ANNOTATIONS_REGEX.test(url)) {
console.log("%cBLOCK ANNOTATION", "color: red;", url);
return true;
}

return false;

};

/**
* Reference - https://gist.github.com/sergeimuller/a609a9df7d30e2625a177123797471e2
*
* Wrapper over XHR.
*/
const origOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (...args) {
const requestType = "XHR";
const url = args[1];

if (isRequestBlocked(requestType, url)) {
throw "Blocked";
}

origOpen.apply(this, args);
};

/**
* Wrapper over Fetch.
*/
const origFetch = fetch;
fetch = (...args) => {
const requestType = "FETCH";
const url = args[0];

if (isRequestBlocked(requestType, url)) {
return;
}
return origFetch(...args);

};

0 comments on commit 7f7a353

Please sign in to comment.