Merge branch '4.2.4'

This commit is contained in:
Tamius Han 2019-09-01 01:54:41 +02:00
commit 6d77b7818d
2 changed files with 37 additions and 10 deletions

View File

@ -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/).</li>
### 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.

View File

@ -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