forked from MozillaReality/FirefoxReality
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use WebExtension for youtube redirects instead of the GV API (Mozilla…
- Loading branch information
1 parent
138cd34
commit 4c0a47f
Showing
5 changed files
with
40 additions
and
61 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
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
33 changes: 33 additions & 0 deletions
33
app/src/main/assets/web_extensions/webcompat_youtube/background.js
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 @@ | ||
const targetUrls = [ | ||
"https://*.youtube.com/*", | ||
"https://*.youtube-nocookie.com/*" | ||
]; | ||
|
||
/** | ||
* 1. Disable YouTube's Polymer layout (which makes YouTube very slow in non-Chrome browsers) | ||
* via a query-string parameter in the URL. | ||
* 2. Rewrite YouTube URLs from `m.youtube.com` -> `youtube.com` (to avoid serving YouTube's | ||
* video pages intended for mobile phones, as linked from Google search results). | ||
*/ | ||
function redirectUrl(req) { | ||
let redirect = false; | ||
const url = new URL(req.url); | ||
if (url.host.startsWith("m.")) { | ||
url.host = url.host.replace("m.", "www."); | ||
redirect = true; | ||
} | ||
if (!url.searchParams.get("disable_polymer")) { | ||
url.searchParams.set("disable_polymer", "1"); | ||
redirect = true; | ||
} | ||
if (!redirect) { | ||
return null; | ||
} | ||
return { redirectUrl: url.toString() }; | ||
} | ||
|
||
browser.webRequest.onBeforeRequest.addListener( | ||
redirectUrl, | ||
{ urls: targetUrls, types: ["main_frame"]}, | ||
["blocking"] | ||
); |
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
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