Skip to content

Commit 7f7a353

Browse files
Created basic webOS app with basic ad-blocking
1 parent 5e09daf commit 7f7a353

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
11
# youtube-webos
22
Youtube App without ADs
3+
4+
## Pre-requisites
5+
* Install webOS SDK - https://webostv.developer.lge.com/sdk/installation/
6+
* Setup webOS app testing to load apps in developer mode - https://webostv.developer.lge.com/develop/app-test
7+
8+
## Building
9+
* Clone the repository
10+
```
11+
git clone https://github.com/FriedChickenButt/youtube-webos.git
12+
```
13+
* Enter the folder and build the App, this will generate a `*.ipk` file.
14+
```
15+
cd youtube-webos && ares-package .
16+
```
17+
18+
## Installation
19+
```
20+
ares-install -d <alias of your TV> <.ipk file>
21+
```
22+
23+
## Launching
24+
* The app will be available in the TV's app list or launch it using ares-cli.
25+
```
26+
ares-launch -d <alias of your TV> com.youtube.noads
27+
```

appinfo.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "com.youtube.noads",
3+
"version": "0.0.1",
4+
"vendor": "My Company",
5+
"type": "web",
6+
"main": "index.html",
7+
"title": "Youtube Without ADs",
8+
"icon": "icon.png",
9+
"largeIcon": "largeIcon.png"
10+
}

icon.png

8.37 KB
Loading

index.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<style type="text/css">
6+
body {
7+
width: 100%;
8+
height: 100%;
9+
background-color: #202020;
10+
}
11+
12+
div {
13+
position: absolute;
14+
height: 100%;
15+
width: 100%;
16+
display: table;
17+
}
18+
19+
h1 {
20+
display: table-cell;
21+
vertical-align: middle;
22+
text-align: center;
23+
color: #FFFFFF;
24+
}
25+
</style>
26+
<!-- <script src="webOSTVjs-1.2.0/webOSTV.js" charset="utf-8"></script>
27+
<script src="webOSTVjs-1.2.0/webOSTV-dev.js" charset="utf-8"></script> -->
28+
<script type="text/javascript">
29+
window.location = "https://youtube.com/tv";
30+
</script>
31+
</head>
32+
33+
</html>

largeIcon.png

14 KB
Loading

webOSUserScripts/userScript.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const YOUTUBE_REGEX = /^https?:\/\/(\w*.)?youtube.com/i;
2+
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_)/;
3+
const YOUTUBE_ANNOTATIONS_REGEX = /^https?:\/\/(\w*.)?youtube\.com\/annotations_invideo\?/;
4+
5+
console.log("%cYT ADBlocker is loading...", "color: green;");
6+
7+
// Set these accoring to your preference
8+
const settings = {
9+
disable_ads: true,
10+
disable_annotations: false,
11+
};
12+
13+
const isRequestBlocked = (requestType, url) => {
14+
15+
console.log(`[${requestType}] URL : ${url}`);
16+
17+
if (settings.disable_ads && YOUTUBE_AD_REGEX.test(url)) {
18+
console.log("%cBLOCK AD", "color: red;", url);
19+
return true;
20+
}
21+
22+
if (settings.disable_annotations && YOUTUBE_ANNOTATIONS_REGEX.test(url)) {
23+
console.log("%cBLOCK ANNOTATION", "color: red;", url);
24+
return true;
25+
}
26+
27+
return false;
28+
29+
};
30+
31+
/**
32+
* Reference - https://gist.github.com/sergeimuller/a609a9df7d30e2625a177123797471e2
33+
*
34+
* Wrapper over XHR.
35+
*/
36+
const origOpen = XMLHttpRequest.prototype.open;
37+
XMLHttpRequest.prototype.open = function (...args) {
38+
const requestType = "XHR";
39+
const url = args[1];
40+
41+
if (isRequestBlocked(requestType, url)) {
42+
throw "Blocked";
43+
}
44+
45+
origOpen.apply(this, args);
46+
};
47+
48+
/**
49+
* Wrapper over Fetch.
50+
*/
51+
const origFetch = fetch;
52+
fetch = (...args) => {
53+
const requestType = "FETCH";
54+
const url = args[0];
55+
56+
if (isRequestBlocked(requestType, url)) {
57+
return;
58+
}
59+
return origFetch(...args);
60+
61+
};

0 commit comments

Comments
 (0)