forked from FriedChickenButt/youtube-webos
-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created basic webOS app with basic ad-blocking
- Loading branch information
1 parent
5e09daf
commit 7f7a353
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
}; |