diff --git a/CHANGELOG.md b/CHANGELOG.md index d2198ed..57296d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ * Settings page looks ugly af right now. Maybe fix it some time later ### v4.3.0 (future release) +### v4.2.4 + +* Improvements to player detection. More details in the [blog post](https://stuff.tamius.net/sacred-texts/2019/08/31/ultrawidify-and-the-improper-cropping/). + * Added user-friendly way to export/import settings * Reworked logging diff --git a/src/ext/conf/Debug.js b/src/ext/conf/Debug.js index 1e68951..7147c78 100644 --- a/src/ext/conf/Debug.js +++ b/src/ext/conf/Debug.js @@ -14,10 +14,9 @@ var Debug = { comms: true, // showArDetectCanvas: true, // flushStoredSettings: true, - // flushStoredSettings: false, // playerDetect: true, // periodic: true, - // // videoRescan: true, + // videoRescan: true, // mousemove: true, // arDetect: { // edgeDetect: true diff --git a/src/ext/conf/ExtConfPatches.js b/src/ext/conf/ExtConfPatches.js index 83e36f1..9a1c841 100644 --- a/src/ext/conf/ExtConfPatches.js +++ b/src/ext/conf/ExtConfPatches.js @@ -10,7 +10,7 @@ const ExtensionConfPatch = { player: { manual: true, useRelativeAncestor: false, - querySelectors: '.media-preview-content, .reddit-video-player-root' + querySelectors: '.reddit-video-player-root, .media-preview-content' } }, css: '', @@ -21,7 +21,7 @@ const ExtensionConfPatch = { player: { manual: true, useRelativeAncestor: false, - querySelectors: '.media-preview-content, .reddit-video-player-root' + querySelectors: '.reddit-video-player-root, .media-preview-content' } }, css: '', diff --git a/src/ext/lib/Settings.js b/src/ext/lib/Settings.js index bcca4db..c2190f6 100644 --- a/src/ext/lib/Settings.js +++ b/src/ext/lib/Settings.js @@ -78,7 +78,9 @@ class Settings { const settings = await this.get(); // |—> on first setup, settings is undefined & settings.version is haram - const oldVersion = (settings && settings.version) || '0.0.0'; + // | since new installs ship with updates by default, no patching is + // | needed. In this case, we assume we're on the current version + const oldVersion = (settings && settings.version) || this.getExtensionVersion(); const currentVersion = this.getExtensionVersion(); if(Debug.debug) { @@ -90,43 +92,43 @@ class Settings { if (Debug.flushStoredSettings) { console.log("%c[Settings::init] Debug.flushStoredSettings is true. Using default settings", "background: #d00; color: #ffd"); Debug.flushStoredSettings = false; // don't do it again this session - this.setDefaultSettings(); this.active = this.getDefaultSettings(); + this.active.version = currentVersion; + this.set(this.active); return this.active; } } // if there's no settings saved, return default settings. if(! settings || (Object.keys(settings).length === 0 && settings.constructor === Object)) { - this.setDefaultSettings(); this.active = this.getDefaultSettings(); + this.active.version = currentVersion; + this.set(this.active); return this.active; } // if last saved settings was for version prior to 4.x, we reset settings to default // it's not like people will notice cos that version didn't preserve settings at all if (settings.version && !settings.version.startsWith('4')) { - this.setDefaultSettings(); this.active = this.getDefaultSettings(); + this.active.version = currentVersion; + this.set(this.active); return this.active; } + // in every case, we'll update the version number: + settings.version = currentVersion; + // if there's settings, set saved object as active settings this.active = settings; - // from some point to 4.2.3.1, settings version wasn't saved. Fix that. - if (!settings.version) { - this.active.version = currentVersion; - } - // check if extension has been updated. If not, return settings as they were retreived - if(oldVersion === currentVersion) { + if (oldVersion == currentVersion) { if(Debug.debug) { console.log("[Settings::init] extension was saved with current version of ultrawidify. Returning object as-is."); } - return this.active; } @@ -223,6 +225,7 @@ class Settings { } setDefaultSettings() { + this.default.version = this.getExtensionVersion(); this.set(this.default); } diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index 517cde5..2e07a83 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -168,6 +168,7 @@ class PlayerData { getPlayer(isFullScreen) { const host = window.location.host; let element = this.video.parentNode; + const videoWidth = this.video.offsetWidth, videoHeight = this.video.offsetHeight; if(! element ){ this.logger.log('info', 'debug', "[PlayerDetect::_pd_getPlayer] element is not valid, doing nothing.", element) @@ -204,18 +205,11 @@ class PlayerData { } } + const elementQ = []; + let scorePenalty = 0; + let score; - var trustCandidateAfterGrows = 2; // if candidate_width or candidate_height increases in either dimensions this many - // times, we say we found our player. (This number ignores weird elements) - // in case our