From 4c359675b64793241e1a474397a77f6c4466437e Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 30 Dec 2020 15:14:03 +0100 Subject: [PATCH 01/24] Build edge version of the addon separately from Chrome --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a46fe5a..22ca37d 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Tamius Han ", "scripts": { "build": "npm run pre-build; cross-env NODE_ENV=production BROWSER=firefox CHANNEL=stable webpack --hide-modules", - "build-all": "mkdir -p ./build/old; npm run pre-build; rm ./dist-zip/uw-amo-source.zip; mv -f ./dist-zip/*.zip ./build/old; npm run build; node scripts/build-zip.js ff; npm run build-chrome; node scripts/build-zip.js chrome; ./scripts/prepare-amo-source.sh", + "build-all": "mkdir -p ./build/old; npm run pre-build; rm ./dist-zip/uw-amo-source.zip; mv -f ./dist-zip/*.zip ./build/old; npm run build; node scripts/build-zip.js ff; npm run build-chrome; node scripts/build-zip.js chrome; npm run build-edge; node scripts/build-zip.js edge; ./scripts/prepare-amo-source.sh", "build-chrome": "cross-env NODE_ENV=production BROWSER=chrome CHANNEL=stable webpack --hide-modules", "build-chrome:dev": "cross-env NODE_ENV=development BROWSER=chrome webpack --hide-modules", "build-edge": "cross-env NODE_ENV=production BROWSER=edge CHANNEL=stable webpack --hide-modules", From f4ff7e7ed614a954c32711093a31a760e3374809 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 30 Dec 2020 15:35:08 +0100 Subject: [PATCH 02/24] Distinction between chrome build and edge build, and "doesn't matter which of the two" build. --- src/ext/conf/BrowserDetect.js | 1 + src/ext/lib/comms/CommsClient.js | 2 +- src/ext/uw-bg.js | 12 ++++++------ src/options/GeneralSettings.vue | 2 +- src/popup/App.vue | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ext/conf/BrowserDetect.js b/src/ext/conf/BrowserDetect.js index d2d58e5..0fa5ad4 100644 --- a/src/ext/conf/BrowserDetect.js +++ b/src/ext/conf/BrowserDetect.js @@ -7,6 +7,7 @@ if (process.env.CHANNEL !== 'stable') { const BrowserDetect = { firefox: process.env.BROWSER === 'firefox', + anyChromium: process.env.BROWSER !== 'firefox', chrome: process.env.BROWSER === 'chrome', edge: process.env.BROWSER === 'edge', processEnvBrowser: process.env.BROWSER, diff --git a/src/ext/lib/comms/CommsClient.js b/src/ext/lib/comms/CommsClient.js index 8f6ef89..e6e0c30 100644 --- a/src/ext/lib/comms/CommsClient.js +++ b/src/ext/lib/comms/CommsClient.js @@ -11,7 +11,7 @@ class CommsClient { if (BrowserDetect.firefox) { this.port = browser.runtime.connect({name: name}); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { this.port = chrome.runtime.connect({name: name}); } diff --git a/src/ext/uw-bg.js b/src/ext/uw-bg.js index 89c6351..df74b25 100644 --- a/src/ext/uw-bg.js +++ b/src/ext/uw-bg.js @@ -69,7 +69,7 @@ class UWServer { if(BrowserDetect.firefox) { browser.tabs.onActivated.addListener((m) => {this.onTabSwitched(m)}); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { chrome.tabs.onActivated.addListener((m) => {this.onTabSwitched(m)}); } } @@ -84,7 +84,7 @@ class UWServer { try { if (BrowserDetect.firefox || BrowserDetect.edge) { browser.tabs.insertCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { chrome.tabs.insertCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); } } catch (e) { @@ -95,7 +95,7 @@ class UWServer { try { if (BrowserDetect.firefox || BrowserDetect.edge) { browser.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { // this doesn't work currently, but hopefully chrome will get this feature in the future chrome.tabs.removeCSS(sender.tab.id, {code: css, cssOrigin: 'user', frameId: sender.frameId}); } @@ -141,7 +141,7 @@ class UWServer { let tab; if (BrowserDetect.firefox) { tab = await browser.tabs.get(this.currentTabId); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { tab = await this._promisifyTabsGet(chrome, this.currentTabId); } @@ -223,7 +223,7 @@ class UWServer { file: '/ext/uw-ui.js', allFrames: true, }); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { await new Promise( resolve => chrome.tabs.executeScript({ file: '/ext/uw-ui.js', @@ -269,7 +269,7 @@ class UWServer { async getCurrentTab() { if (BrowserDetect.firefox) { return (await browser.tabs.query({active: true, currentWindow: true}))[0]; - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { return new Promise((resolve, reject) => chrome.tabs.query({active: true, currentWindow: true}, (x) => resolve(x[0]))); } } diff --git a/src/options/GeneralSettings.vue b/src/options/GeneralSettings.vue index 3aa2242..ce42e2f 100644 --- a/src/options/GeneralSettings.vue +++ b/src/options/GeneralSettings.vue @@ -216,7 +216,7 @@ export default { // reminder — webextension-polyfill doesn't seem to work in vue! await browser.permissions.request({permissions: ['downloads']}); browser.downloads.download({saveAs: true, filename: 'ultrawidify-settings.json', url: fileUrl}); - } else if (BrowserDetect.chrome) { + } else if (BrowserDetect.anyChromium) { const ths = this; chrome.permissions.request( diff --git a/src/popup/App.vue b/src/popup/App.vue index 5a67bbd..2192d5b 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -261,7 +261,7 @@ export default { cmd: 'unmark-player', forwardToAll: true, }); - if (BrowserDetect.chrome) { + if (BrowserDetect.anyChromium) { chrome.extension.getBackgroundPage().sendUnmarkPlayer({ cmd: 'unmark-player', forwardToAll: true, From 7cb378029cf88068a2a5296c739b73741d031897 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Wed, 30 Dec 2020 15:35:54 +0100 Subject: [PATCH 03/24] Some cosmetic changes in BrowserDetect --- src/csui/PlayerUiComponent.vue | 2 +- src/ext/conf/BrowserDetect.js | 17 ++++++++++++++--- src/ext/lib/video-data/PlayerData.js | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/csui/PlayerUiComponent.vue b/src/csui/PlayerUiComponent.vue index 0d4e56c..9e8eb02 100644 --- a/src/csui/PlayerUiComponent.vue +++ b/src/csui/PlayerUiComponent.vue @@ -138,7 +138,7 @@ export default { }, methods: { getUrl(url) { - return BrowserDetect.firefox ? browser.runtime.getURL(url) : chrome.runtime.getURL(url); + return BrowserDetect.getURL(url); }, async hidePopupForever() { const settings = new Settings(); diff --git a/src/ext/conf/BrowserDetect.js b/src/ext/conf/BrowserDetect.js index 0fa5ad4..a552e7d 100644 --- a/src/ext/conf/BrowserDetect.js +++ b/src/ext/conf/BrowserDetect.js @@ -4,6 +4,17 @@ if (process.env.CHANNEL !== 'stable') { console.info('Loaded BrowserDetect'); } +function detectEdgeUA() { + return /Edg\/(\.?[0-9]*)*$/.test(window.navigator.userAgent); +} + +function getBrowserObj() { + return process.env.BROWSER === 'firefox' ? browser : chrome; +} + +function getURL(url) { + return process.env.BROWSER === 'firefox' ? browser.runtime.getURL(url) : chrome.runtime.getURL(url); +} const BrowserDetect = { firefox: process.env.BROWSER === 'firefox', @@ -12,9 +23,9 @@ const BrowserDetect = { edge: process.env.BROWSER === 'edge', processEnvBrowser: process.env.BROWSER, processEnvChannel: process.env.CHANNEL, - isEdgeUA: () => /Edg\/(\.?[0-9]*)*$/.test(window.navigator.userAgent), - getBrowserObj: () => { return process.env.BROWSER === 'firefox' ? browser : chrome; }, - getURL: (url) => { console.log('getting file:', url); console.log(process.env.BROWSER === 'firefox' ? browser.runtime.getURL(url) : chrome.runtime.getURL(url)); return process.env.BROWSER === 'firefox' ? browser.runtime.getURL(url) : chrome.runtime.getURL(url); }, + isEdgeUA: detectEdgeUA(), + browserObj: getBrowserObj(), + getURL: (url) => getURL(url), } if (process.env.CHANNEL !== 'stable') { diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index 21caaa9..d721146 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -485,7 +485,7 @@ class PlayerData { * NOTE: this method needs to be deleted once Edge gets its shit together. */ showEdgeNotification() { - if (BrowserDetect.isEdgeUA() && !this.settings.active.mutedNotifications?.browserSpecific?.edge?.brokenDrm?.[window.hostname]) { + if (BrowserDetect.isEdgeUA && !this.settings.active.mutedNotifications?.browserSpecific?.edge?.brokenDrm?.[window.hostname]) { this.ui = new PlayerUi(this.element, this.settings); } } From 7e403e34063d0a85ae237b7c56c52de94beb183a Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 16:12:20 +0100 Subject: [PATCH 04/24] Edge issues are fixed, so the popup goes. --- src/ext/lib/video-data/PlayerData.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index d721146..3d787ca 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -485,9 +485,9 @@ class PlayerData { * NOTE: this method needs to be deleted once Edge gets its shit together. */ showEdgeNotification() { - if (BrowserDetect.isEdgeUA && !this.settings.active.mutedNotifications?.browserSpecific?.edge?.brokenDrm?.[window.hostname]) { - this.ui = new PlayerUi(this.element, this.settings); - } + // if (BrowserDetect.isEdgeUA && !this.settings.active.mutedNotifications?.browserSpecific?.edge?.brokenDrm?.[window.hostname]) { + // this.ui = new PlayerUi(this.element, this.settings); + // } } } From 897e65567bc24dd15794081675e583ca15401e4f Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 16:12:35 +0100 Subject: [PATCH 05/24] add note in the popup --- src/popup/App.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/popup/App.vue b/src/popup/App.vue index 2192d5b..6da65b6 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -20,6 +20,10 @@ Build channel: {{BrowserDetect.processEnvChannel}} +
+ NOTE: please ensure your Windows and Edge have the latest updates, otherwise this extension + WILL NOT WORK on DRM-protected sites. +
From 167b9d4305ed75f82b44ee388fcad5830f1a3193 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 17:22:02 +0100 Subject: [PATCH 07/24] Disney+ should be fixed? Maybe? See #84 --- src/ext/conf/ExtConfPatches.js | 7 +++++++ src/ext/conf/ExtensionConf.js | 10 ++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ext/conf/ExtConfPatches.js b/src/ext/conf/ExtConfPatches.js index 242e449..c8c6064 100644 --- a/src/ext/conf/ExtConfPatches.js +++ b/src/ext/conf/ExtConfPatches.js @@ -436,6 +436,13 @@ const ExtensionConfPatch = [ userOptions.sites['streamable.com'].css = '.player {text-align: left}' }; } + }, { + forVersion: '4.5.1.3', + updateFn: (userOptions, defaultOptions) => { + try { + userOptions.sites['wwww.disneyplus.com']['css'] = ".hudson-container {\n height: 100%;\n}"; + } + } } ]; diff --git a/src/ext/conf/ExtensionConf.js b/src/ext/conf/ExtensionConf.js index d8b3412..0da109d 100644 --- a/src/ext/conf/ExtensionConf.js +++ b/src/ext/conf/ExtensionConf.js @@ -1066,7 +1066,8 @@ var ExtensionConf = { "useRelativeAncestor": false, "playerNodeCss": "" } - } + }, + css: ".hudson-container { height: 100%; }", }, "www.twitch.tv": { mode: ExtensionMode.Enabled, @@ -1145,13 +1146,6 @@ var ExtensionConf = { }, css: 'video {\n width: 100% !important;\n height: 100% !important;\n}', }, - "www.disneyplus.com": { - DOM: { - player: { - periodicallyRefreshPlayerElement: true, - } - } - }, "imgur.com": { mode: -1, autoar: -1, From 5b5f4204bbfc4f6a54bbbd5e06c7744858bd771e Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 17:22:12 +0100 Subject: [PATCH 08/24] Version bump --- src/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/manifest.json b/src/manifest.json index 75454b1..1e94bd3 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Ultrawidify", "description": "Removes black bars on ultrawide videos and offers advanced options to fix aspect ratio.", - "version": "4.5.1.2", + "version": "4.5.1.3", "applications": { "gecko": { "id": "{cf02b1a7-a01a-4e37-a609-516a283f1ed3}" From fda7b38fa16d29a0f1734d1614784d2922c9f011 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 17:25:36 +0100 Subject: [PATCH 09/24] fix --- src/ext/conf/ExtConfPatches.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ext/conf/ExtConfPatches.js b/src/ext/conf/ExtConfPatches.js index c8c6064..349a2c2 100644 --- a/src/ext/conf/ExtConfPatches.js +++ b/src/ext/conf/ExtConfPatches.js @@ -441,6 +441,8 @@ const ExtensionConfPatch = [ updateFn: (userOptions, defaultOptions) => { try { userOptions.sites['wwww.disneyplus.com']['css'] = ".hudson-container {\n height: 100%;\n}"; + } catch (e) { + // do nothing if disney+ is missing } } } From 67ad0c54b4a683a6f43bfa6890887201dca85248 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 17:43:11 +0100 Subject: [PATCH 10/24] Apply some styling to the edge warning box --- src/popup/App.vue | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/popup/App.vue b/src/popup/App.vue index 6da65b6..5e677fe 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -20,9 +20,16 @@ Build channel: {{BrowserDetect.processEnvChannel}} -
- NOTE: please ensure your Windows and Edge have the latest updates, otherwise this extension - WILL NOT WORK on DRM-protected sites. +
+
+ +
+
+ + NOTE: please ensure your Windows and Edge have the latest updates in order for this extension to work on DRM-protected sites. + If your Windows and Edge are not up to date, videos on sites like Netflix, Hulu, and Disney+ may not be aligned and cropped correctly. + +
Date: Sun, 10 Jan 2021 18:07:58 +0100 Subject: [PATCH 11/24] Fix formatting in what's new panel --- src/popup/panels/WhatsNewPanel.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/popup/panels/WhatsNewPanel.vue b/src/popup/panels/WhatsNewPanel.vue index fd9918e..f299d25 100644 --- a/src/popup/panels/WhatsNewPanel.vue +++ b/src/popup/panels/WhatsNewPanel.vue @@ -20,8 +20,14 @@
  • [4.5.1.1] Streamable fix broke old.reddit + RES on embeds from v.redd.it and streamable.com. We're now using an alternative implementation. (#128) +
  • +
  • [4.5.1.2] Fixed the issue where videos would sometimes get misaligned while using hybrid stretch. (#125) +
  • +
  • [4.5.1.3] Added a potential fix for disney plus +
  • +
  • [4.5.1.3] Microsoft Edge has fixed the bugs that prevented the extension from working properly. Popup should no longer be shown.
  • From aec87e7681a11ab682585f29e449f92a6613e7a9 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sun, 10 Jan 2021 20:46:41 +0100 Subject: [PATCH 12/24] Don't assume jenkins build number is always there, cos it's not on local builds --- webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 8cb6897..447d6d9 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -121,7 +121,7 @@ const config = { .substr(2) // YYYY -> YY .replace('-', '') // YY-MM-DD -> YYMM-DD .replace('-', '.') // YYMM-DD -> YYMM.DD - }.${process.env.BUILD_NUMBER}`; + }.${process.env.BUILD_NUMBER ?? 0}`; jsonContent.browser_action.default_title = "Ultrawidify Nightly"; // because we don't want web-ext to submit this as proper release @@ -137,7 +137,7 @@ const config = { .substr(2) // YYYY -> YY .replace('-', '') // YY-MM-DD -> YYMM-DD .replace('-', '.') // YYMM-DD -> YYMM.DD - }.${process.env.BUILD_NUMBER}`; + }.${process.env.BUILD_NUMBER ?? 0}`; jsonContent.browser_action.default_title = "Ultrawidify Testing"; // because we don't want web-ext to submit this as proper release From df2b0f56145d588c44ffd693152a2df2e3aadc63 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:18:14 +0100 Subject: [PATCH 13/24] Add toString method to aspect ratio enum --- src/common/enums/aspect-ratio.enum.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/common/enums/aspect-ratio.enum.js b/src/common/enums/aspect-ratio.enum.js index 95c92f1..46c1f7d 100644 --- a/src/common/enums/aspect-ratio.enum.js +++ b/src/common/enums/aspect-ratio.enum.js @@ -6,6 +6,19 @@ var AspectRatio = Object.freeze({ FitHeight: 3, // legacy/dynamic: fit to height Fixed: 4, // pre-determined aspect ratio Manual: 5, // ratio achieved by zooming in/zooming out + + toString: (ar) => { + switch (ar) { + case -1: return 'Initial'; + case 0: return 'Reset'; + case 1: return 'Automatic'; + case 2: return 'FitWidth'; + case 3: return 'FitHeight'; + case 4: return 'Fixed'; + case 5: return 'Manual'; + default: return '' + } + } }); export default AspectRatio; From aa1ccedad5cf43568832eb517896b1978c3b2fd0 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:19:04 +0100 Subject: [PATCH 14/24] Cosmetic changes --- src/ext/lib/ar-detect/ArDetector.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ext/lib/ar-detect/ArDetector.js b/src/ext/lib/ar-detect/ArDetector.js index 48b5fe8..b6997c6 100644 --- a/src/ext/lib/ar-detect/ArDetector.js +++ b/src/ext/lib/ar-detect/ArDetector.js @@ -474,19 +474,19 @@ class ArDetector { // poglejmo, če se je razmerje stranic spremenilo // check if aspect ratio is changed: - var lastAr = this.conf.resizer.getLastAr(); + let lastAr = this.conf.resizer.getLastAr(); if (lastAr.type === AspectRatio.Automatic && lastAr.ratio !== null && lastAr.ratio !== undefined){ // spremembo lahko zavrnemo samo, če uporabljamo avtomatski način delovanja in če smo razmerje stranic // že nastavili. // // we can only deny aspect ratio changes if we use automatic mode and if aspect ratio was set from here. - var arDiff = trueAr - lastAr.ar; + let arDiff = trueAr - lastAr.ar; if (arDiff < 0) arDiff = -arDiff; - var arDiff_percent = arDiff / trueAr; + const arDiff_percent = arDiff / trueAr; // ali je sprememba v mejah dovoljenega? Če da -> fertik // is ar variance within acceptable levels? If yes -> we done From 884db1c5e3ccfd043dfe11fda4fc48216dae153d Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:24:20 +0100 Subject: [PATCH 15/24] Do event listeners properly --- src/ext/lib/video-data/VideoData.js | 83 ++++++++++++++++------------- 1 file changed, 47 insertions(+), 36 deletions(-) diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 9e62f8f..19f6e40 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -71,21 +71,29 @@ class VideoData { this.video.classList.remove('uw-ultrawidify-base-wide-screen'); } + onLoadedData() { + this.logger.log('info', 'init', '[VideoData::ctor->video.onloadeddata] Video fired event "loaded data!"'); + this.onVideoLoaded(); + } + onLoadedMetadata() { + this.logger.log('info', 'init', '[VideoData::ctor->video.onloadedmetadata] Video fired event "loaded metadata!"'); + this.onVideoLoaded(); + } + onTimeUpdate() { + console.info('received timeupdate event!', this); + this.onVideoLoaded(); + } async setupStageOne() { this.logger.log('info', 'init', '%c[VideoData::setupStageOne] ——————————— Starting setup stage one! ———————————', 'color: #0f9'); // ensure base css is loaded before doing anything this.injectBaseCss(); // this is in case extension loads before the video - this.video.addEventListener('loadeddata', () => { - this.logger.log('info', 'init', '[VideoData::ctor->video.onloadeddata] Video fired event "loaded data!"'); - this.onVideoLoaded(); - }); + this.video.addEventListener('loadeddata', this.onLoadedData.bind(this)); + this.video.addEventListener('loadedmetadata', this.onLoadedMetadata.bind(this)); // this one is in case extension loads after the video is loaded - this.video.addEventListener('timeupdate', () => { - this.onVideoLoaded(); - }); + this.video.addEventListener('timeupdate', this.onTimeUpdate.bind(this)); this.logger.log('info', 'init', '%c[VideoData::setupStageOne] ——————————— Setup stage one complete! ———————————', 'color: #0f9'); } @@ -158,6 +166,38 @@ class VideoData { } } + destroy() { + this.logger.log('info', ['debug', 'init'], `[VideoData::destroy] received destroy command`); + + if (this.video) { + this.video.classList.remove(this.userCssClassName); + this.video.classList.remove('uw-ultrawidify-base-wide-screen'); + + this.video.removeEventListener('onloadeddata', this.onLoadedData); + this.video.removeEventListener('onloadedmetadata', this.onLoadedMetadata); + this.video.removeEventListener('ontimeupdate', this.onTimeUpdate); + } + + this.pause(); + this.destroyed = true; + try { + this.arDetector.stop(); + this.arDetector.destroy(); + } catch (e) {} + this.arDetector = undefined; + try { + this.resizer.destroy(); + } catch (e) {} + this.resizer = undefined; + try { + this.player.destroy(); + } catch (e) {} + try { + this.observer.disconnect(); + } catch (e) {} + this.player = undefined; + this.video = undefined; + } restoreCrop() { this.logger.log('info', 'debug', '[VideoData::restoreCrop] Attempting to reset aspect ratio.') @@ -378,35 +418,6 @@ class VideoData { } } - destroy() { - this.logger.log('info', ['debug', 'init'], `[VideoData::destroy] received destroy command`); - - if (this.video) { - this.video.classList.remove(this.userCssClassName); - this.video.classList.remove('uw-ultrawidify-base-wide-screen'); - } - - this.pause(); - this.destroyed = true; - try { - this.arDetector.stop(); - this.arDetector.destroy(); - } catch (e) {} - this.arDetector = undefined; - try { - this.resizer.destroy(); - } catch (e) {} - this.resizer = undefined; - try { - this.player.destroy(); - } catch (e) {} - try { - this.observer.disconnect(); - } catch (e) {} - this.player = undefined; - this.video = undefined; - } - pause(){ this.paused = true; if(this.arDetector){ From 2025547d3375d964da487ddf45b55901b4a8c62d Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:28:17 +0100 Subject: [PATCH 16/24] Un-initalize videoData on illegal video dimensions ($ When youtube changes between two videos, video dimensions briefly become 0x0. This is super duper illegal and sometimes causes the behaviour described in issue #125. Setting VideoData.videoLoaded to false fixes this. --- src/ext/lib/video-data/VideoData.js | 7 +++++++ src/ext/lib/video-transform/Resizer.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 19f6e40..f0252c9 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -33,6 +33,9 @@ class VideoData { async onVideoLoaded() { if (!this.videoLoaded) { + if (this.video.videoWidth && this.video.videoHeight) { + return; // onVideoLoaded is a lie in this case + } this.logger.log('info', 'init', '%c[VideoData::onVideoLoaded] ——————————— Initiating phase two of videoData setup ———————————', 'color: #0f9'); this.videoLoaded = true; @@ -52,6 +55,10 @@ class VideoData { } } + videoUnloaded() { + this.videoLoaded = false; + } + async injectBaseCss() { try { await this.pageInfo.injectCss(` diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index 7a5ec8f..6b056eb 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -146,7 +146,8 @@ class Resizer { } if (!this.video.videoWidth || !this.video.videoHeight) { - this.logger.log('warning', 'debug', '[Resizer::setAr] Video has no width or no height. This is not allowed. Aspect ratio will not be set.'); + this.logger.log('warning', 'debug', '[Resizer::setAr] Video has no width or no height. This is not allowed. Aspect ratio will not be set, and videoData will be uninitialized.'); + this.conf.videoUnloaded(); } this.logger.log('info', 'debug', '[Resizer::setAr] trying to set ar. New ar:', ar) From 437890a609ea073b20ad5901c7ab3a3c1880a65e Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 12 Jan 2021 23:28:27 +0100 Subject: [PATCH 17/24] Documentation & comments --- src/ext/lib/video-data/VideoData.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index f0252c9..97de308 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -51,7 +51,6 @@ class VideoData { this.restoreCrop(); this.videoDimensionsLoaded = true; - } } @@ -78,6 +77,7 @@ class VideoData { this.video.classList.remove('uw-ultrawidify-base-wide-screen'); } + //#region