diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c15110..67d27cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,14 @@ QoL improvements for me: * logging: allow to enable logging at will and export said logs to a file -### v4.4.9 (Current) +### v4.4.10 (Current) + +* Video alignment should now work on Twitch [#109](https://github.com/tamius-han/ultrawidify/issues/109) +* Videos should now align properly on Hulu while cropped [#111](https://github.com/tamius-han/ultrawidify/issues/111) & via email +* Fixed a problem where changing certain settings would cause multiple instances of Ultrawidify to run on a page, effectively preventing some crop options to be set until reload. (possibly [#112](https://github.com/tamius-han/ultrawidify/issues/112)?) +* Fixed a problem where embedded videos would be misaligned after switching from full screen + +### v4.4.9 * Fixed the youtube alignment issue (previously fixed in v4.4.7.1-2), but this time for real (and in a bit more proper way) * Fixed the bug where extension wouldn't work when URL specified a port (e.g. www.example.com:80) diff --git a/package-lock.json b/package-lock.json index 8e02e4b..0b61c74 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ultrawidify", - "version": "4.4.9", + "version": "4.4.10", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1863,9 +1863,9 @@ "optional": true }, "bl": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-3.0.0.tgz", - "integrity": "sha512-EUAyP5UHU5hxF8BPT0LKW8gjYLhq1DQIcneOX/pL/m2Alo+OYDQAJlHq+yseMP50Os2nHXOSic6Ss3vSQeyf4A==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/bl/-/bl-3.0.1.tgz", + "integrity": "sha512-jrCW5ZhfQ/Vt07WX1Ngs+yn9BDqPL/gw28S7s9H6QK/gupnizNzJAss5akW20ISgOrbLTlXOOCTJeNUQqruAWQ==", "dev": true, "requires": { "readable-stream": "^3.0.1" diff --git a/src/common/enums/aspect-ratio.enum.js b/src/common/enums/aspect-ratio.enum.js index 9337b9e..95c92f1 100644 --- a/src/common/enums/aspect-ratio.enum.js +++ b/src/common/enums/aspect-ratio.enum.js @@ -1,10 +1,11 @@ var AspectRatio = Object.freeze({ - Initial: -1, - Reset: 0, - Automatic: 1, - FitWidth: 2, - FitHeight: 3, - Fixed: 4, + Initial: -1, // page default + Reset: 0, // reset to initial + Automatic: 1, // set by Aard + FitWidth: 2, // legacy/dynamic: fit to width + FitHeight: 3, // legacy/dynamic: fit to height + Fixed: 4, // pre-determined aspect ratio + Manual: 5, // ratio achieved by zooming in/zooming out }); export default AspectRatio; diff --git a/src/ext/lib/ActionHandler.js b/src/ext/lib/ActionHandler.js index c0d2bf0..dd34e3e 100644 --- a/src/ext/lib/ActionHandler.js +++ b/src/ext/lib/ActionHandler.js @@ -104,14 +104,36 @@ class ActionHandler { } } - document.addEventListener('keydown', (event) => ths.handleKeydown(event) ); - document.addEventListener('keyup', (event) => ths.handleKeyup(event) ); + // events should be handled in handleEvent function. We need to do things this + // way, otherwise we can't remove event listenerđ + // https://stackoverflow.com/a/19507086 + document.addEventListener('keydown', this ); + document.addEventListener('keyup', this ); this.pageInfo.setActionHandler(this); this.logger.log('info', 'debug', "[ActionHandler::init] initialization complete"); } + handleEvent(event) { + switch(event.type) { + case 'keydown': + this.handleKeydown(event); + break; + case 'keyup': + this.handleKeyup(event); + break; + case 'mousemove': + this.handleMouseMove(event); + break; + } + } + + destroy() { + document.removeEventListener('keydown', this); + document.removeEventListener('keyup', this); + } + registerHandleMouse(videoData) { this.logger.log('info', ['actionHandler', 'mousemove'], "[ActionHandler::registerHandleMouse] registering handle mouse for videodata:", videoData.id) diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index cc5239f..5527bc4 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -394,7 +394,7 @@ class PlayerData { this.getPlayer(); } - checkPlayerSizeChange(){ + checkPlayerSizeChange() { // this 'if' is just here for debugging — real code starts later. It's safe to collapse and // ignore the contents of this if (unless we need to change how logging works) if (this.logger.canLog('debug')){ diff --git a/src/ext/lib/video-data/VideoData.js b/src/ext/lib/video-data/VideoData.js index 9be729a..2fbf15f 100644 --- a/src/ext/lib/video-data/VideoData.js +++ b/src/ext/lib/video-data/VideoData.js @@ -56,6 +56,7 @@ class VideoData { this.restoreCrop(); this.videoDimensionsLoaded = true; + } } @@ -123,7 +124,7 @@ class VideoData { } restoreCrop() { - this.logger.log('info', 'debug', '[VideoData::restoreCrop] Attempting to reset/restore aspect ratio.') + this.logger.log('info', 'debug', '[VideoData::restoreCrop] Attempting to reset aspect ratio.') // if we have default crop set for this page, apply this. // otherwise, reset crop if (this.pageInfo.defaultCrop) { @@ -132,6 +133,7 @@ class VideoData { this.resizer.reset(); try { + this.stopArDetection(); this.startArDetection(); } catch (e) { this.logger.log('warn', 'debug', '[VideoData::restoreCrop] Autodetection not resumed. Reason:', e); diff --git a/src/ext/lib/video-transform/Resizer.js b/src/ext/lib/video-transform/Resizer.js index f8c5223..5402288 100644 --- a/src/ext/lib/video-transform/Resizer.js +++ b/src/ext/lib/video-transform/Resizer.js @@ -155,11 +155,11 @@ class Resizer { // reset zoom, but only on aspect ratio switch. We also know that aspect ratio gets converted to // AspectRatio.Fixed when zooming, so let's keep that in mind - if (ar.type !== AspectRatio.Fixed) { - this.zoom.reset(); - this.resetPan(); - } else if (ar.ratio !== this.lastAr.ratio) { - // we must check against this.lastAR.ratio because some calls provide same value for ar and lastAr + if ( + (ar.type !== AspectRatio.Fixed && ar.type !== AspectRatio.Manual) // anything not these two _always_ changes AR + || ar.type !== this.lastAr.type // this also means aspect ratio has changed + || ar.ratio !== this.lastAr.ratio // this also means aspect ratio has changed + ) { this.zoom.reset(); this.resetPan(); } @@ -239,29 +239,29 @@ class Resizer { this.conf.destroy(); } - // pause AR on basic stretch, unpause when using other modes - // for sine reason unpause doesn't unpause. investigate that later - try { - if (this.stretcher.mode === Stretch.Basic) { - this.conf.arDetector.pause(); - } else { - if (this.lastAr.type === AspectRatio.Automatic) { - this.conf.arDetector.unpause(); - } + // pause AR on: + // * ar.type NOT automatic + // * ar.type is auto, but stretch is set to basic basic stretch + // + // unpause when using other modes + if (ar.type !== AspectRatio.Automatic || this.stretcher.mode === Stretch.Basic) { + this.conf?.arDetector?.pause(); + } else { + if (this.lastAr.type === AspectRatio.Automatic) { + this.conf?.arDetector?.unpause(); } - } catch (e) { // resizer starts before arDetector. this will do nothing but fail if arDetector isn't setup - } // do stretch thingy if (this.stretcher.mode === Stretch.NoStretch || this.stretcher.mode === Stretch.Conditional || this.stretcher.mode === Stretch.FixedSource){ + var stretchFactors = this.scaler.calculateCrop(ar); - this.logger.log('error', 'debug', `[Resizer::setAr] failed to set AR due to problem with calculating crop. Error:`, stretchFactors && stretchFactors.error); if(! stretchFactors || stretchFactors.error){ + this.logger.log('error', 'debug', `[Resizer::setAr] failed to set AR due to problem with calculating crop. Error:`, stretchFactors?.error); if (stretchFactors?.error === 'no_video'){ this.conf.destroy(); return; @@ -303,14 +303,17 @@ class Resizer { this.zoom.applyZoom(stretchFactors); - //TODO: correct these two var translate = this.computeOffsets(stretchFactors); this.applyCss(stretchFactors, translate); - } + toFixedAr() { - this.lastAr.type = AspectRatio.Fixed; + // converting to fixed AR means we also turn off autoAR + this.setAr({ + ar: this.lastAr.ar, + type: AspectRatio.Fixed + }); } resetLastAr() { @@ -339,7 +342,9 @@ class Resizer { this.videoAlignment = VideoAlignment.Center; // because non-fixed aspect ratios reset panning: - this.toFixedAr(); + if (this.lastAr.type !== AspectRatio.Fixed) { + this.toFixedAr(); + } const player = this.conf.player.element; @@ -380,7 +385,7 @@ class Resizer { } restore() { - this.logger.log('info', 'debug', "[Resizer::restore] attempting to restore aspect ratio", {'a_lastAr': this.lastAr} ); + this.logger.log('info', 'debug', "[Resizer::restore] attempting to restore aspect ratio", {'lastAr': this.lastAr} ); // this is true until we verify that css has actually been applied if(this.lastAr.type === AspectRatio.Initial){ @@ -442,18 +447,85 @@ class Resizer { // mostly internal stuff + /** + * Returns the size of the video file _as displayed_ on the screen. + * Consider the following example: + * + * * player dimensions are 2560x1080 + * *