Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Improve youtube layout (#2509)
Browse files Browse the repository at this point in the history
  • Loading branch information
MortimerGoro authored Dec 20, 2019
1 parent 6eca0b8 commit f624a4f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 33 deletions.
2 changes: 0 additions & 2 deletions app/src/main/assets/userAgentOverride.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"744723238cc3c00582d7ff9e8ece83e6503a3926d8c07491672d5da3634be41e1d41580dd3694b663c0d0a5e64280a2b411a1346e6ed0d53d694835781cf6436": "Mozilla/5.0 (X11; Linux x86_64; rv:69) Gecko/20100101 Firefox/69.0",
"ae0755740e4354ac67025056e775ad06d8a529ae4f37244fbb02d72199e2c780311e47aa9895079b980ec4bfa676f1f39c4ab41ea995c524e52bde9a73623da2": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.21 (KHTML, like Gecko) Version/9.2 Safari/602.1.21",
"e6137b4c2f49a3917c2c90a50fb270a5eebb962f2c72344ae2e29e321bb21891e5ca4fec06cae78e14f4a8510473e934234e9ec3f60e8415f5f6da754c55b9b1": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.21 (KHTML, like Gecko) Version/9.2 Safari/602.1.21"
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
const CUSTOM_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.21 (KHTML, like Gecko) Version/9.2 Safari/602.1.21';
const CUSTOM_USER_AGENT = 'Mozilla/5.0 (Linux; Android 7.1.1; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/7.0.13.186866463 SamsungBrowser/4.0 Chrome/77.0.3865.126 Mobile VR Safari/537.36';
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() };
}

/**
* Override UA. This is required to get the equirectangular video formats from Youtube.
* Otherwise youtube uses custom 360 controls.
Expand All @@ -40,12 +17,6 @@ function overrideUA(req) {
return { requestHeaders: req.requestHeaders };
}

browser.webRequest.onBeforeRequest.addListener(
redirectUrl,
{ urls: targetUrls, types: ["main_frame"]},
["blocking"]
);

browser.webRequest.onBeforeSendHeaders.addListener(
overrideUA,
{ urls: targetUrls },
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/assets/web_extensions/webcompat_youtube/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const CUSTOM_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.21 (KHTML, like Gecko) Version/9.2 Safari/602.1.21';
const CUSTOM_USER_AGENT = 'Mozilla/5.0 (Linux; Android 7.1.1; Quest) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/7.0.13.186866463 SamsungBrowser/4.0 Chrome/77.0.3865.126 Mobile VR Safari/537.36';
const LOGTAG = '[firefoxreality:webcompat:youtube]';
const VIDEO_PROJECTION_PARAM = 'mozVideoProjection';
const YT_SELECTORS = {
Expand Down Expand Up @@ -96,6 +96,7 @@ class YoutubeExtension {
}

overrideClick(event) {
this.overrideVideoProjection();
const player = this.getPlayer();
if (!this.isWatchingPage() || !this.hasVideoProjection() || document.fullscreenElement || !player) {
return; // Only override click in the Youtube watching page for 360 videos.
Expand Down

0 comments on commit f624a4f

Please sign in to comment.