diff --git a/CHANGELOG.md b/CHANGELOG.md index a035344..31e27ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,13 @@ * Reworked logging * Started using mutation observers to watch for changes in player size as well. -### v4.2.4 +### v4.2.4 / 4.2.4.x (current) -* Improvements to player detection. More details in the [blog post](https://stuff.tamius.net/sacred-texts/2019/08/31/ultrawidify-and-the-improper-cropping/). - -### v4.2.3 / 4.2.3.1 (current) +* Improvements to player detection. More details in the [blog post](https://stuff.tamius.net/sacred-texts/2019/08/31/ultrawidify-and-the-improper-cropping/). +* **[4.2.4.1]** Fixed default video settings for reddit +* **[4.2.4.1]** Manually specified query selectors will also be checked for compliance with player detection rules. +### v4.2.3 / 4.2.3.x * Fixed twitchy behaviour on Twitch, Facebook and Twatter. Here's a [blog post](https://stuff.tamius.net/sacred-texts/2019/08/24/ultrawidify-the-twitchy-twitch-problem/) that covers the issue in more detail. * Cropping now uses user styles (as opposed to modifying element's style attribute) * Fixed the issue where one-pixel letterbox would result in constant aspect ratio corrections. diff --git a/src/ext/lib/video-data/PlayerData.js b/src/ext/lib/video-data/PlayerData.js index 2e07a83..b3cc7bb 100644 --- a/src/ext/lib/video-data/PlayerData.js +++ b/src/ext/lib/video-data/PlayerData.js @@ -169,6 +169,9 @@ class PlayerData { const host = window.location.host; let element = this.video.parentNode; const videoWidth = this.video.offsetWidth, videoHeight = this.video.offsetHeight; + const elementQ = []; + let scorePenalty = 0; + let score; if(! element ){ this.logger.log('info', 'debug', "[PlayerDetect::_pd_getPlayer] element is not valid, doing nothing.", element) @@ -196,18 +199,41 @@ class PlayerData { } } else if (this.settings.active.sites[host].DOM.player.querySelectors) { const allSelectors = document.querySelectorAll(this.settings.active.sites[host].DOM.player.querySelectors); - while (element && !this.collectionHas(allSelectors, element)) { + + // actually we'll also score this branch in a similar way we score the regular, auto branch + while (element !== undefined) { + + // Let's see how this works + if (this.collectionHas(allSelectors, element)) { + score = 100; // every matching element gets a baseline 100 points + + // elements that match the size get a hefty bonus + if ( (element.offsetWidth >= videoWidth && this.equalish(element.offsetHeight, videoHeight, 2)) + || (element.offsetHeight >= videoHeight && this.equalish(element.offsetWidth, videoHeight, 2))) { + score += 75; + } + + // elements farther away from the video get a penalty + score -= (scorePenalty++) * 20; + + // push the element on the queue/stack: + elementQ.push({ + score: score, + element: element, + }); + } + element = element.parentNode; } - if (element) { - return element; + if (elementQ.length) { + // return element with biggest score + // if video player has not been found, proceed to automatic detection + return elementQ.sort( (a,b) => b.score - a.score)[0].element; } } } - const elementQ = []; - let scorePenalty = 0; - let score; + while (element != undefined){ // odstranimo Ĩudne elemente, ti bi pokvarili zadeve