From f624a4faf5c11b4f11962036f4d184d0a9a994be Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Fri, 20 Dec 2019 17:31:02 +0100 Subject: [PATCH] Improve youtube layout (#2509) --- app/src/main/assets/userAgentOverride.json | 2 -- .../webcompat_youtube/background.js | 31 +------------------ .../web_extensions/webcompat_youtube/main.js | 3 +- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/app/src/main/assets/userAgentOverride.json b/app/src/main/assets/userAgentOverride.json index 044ac11ea..e41ccbbc0 100644 --- a/app/src/main/assets/userAgentOverride.json +++ b/app/src/main/assets/userAgentOverride.json @@ -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" } diff --git a/app/src/main/assets/web_extensions/webcompat_youtube/background.js b/app/src/main/assets/web_extensions/webcompat_youtube/background.js index 97d7c80e9..233331a6e 100644 --- a/app/src/main/assets/web_extensions/webcompat_youtube/background.js +++ b/app/src/main/assets/web_extensions/webcompat_youtube/background.js @@ -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. @@ -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 }, diff --git a/app/src/main/assets/web_extensions/webcompat_youtube/main.js b/app/src/main/assets/web_extensions/webcompat_youtube/main.js index af919237e..151a7b7de 100644 --- a/app/src/main/assets/web_extensions/webcompat_youtube/main.js +++ b/app/src/main/assets/web_extensions/webcompat_youtube/main.js @@ -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 = { @@ -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.