Don't restore ar if player dimensions haven't changed

This commit is contained in:
Tamius Han 2020-01-27 23:42:55 +01:00
parent 691f45fbcc
commit 1588ebd274
2 changed files with 22 additions and 3 deletions

View File

@ -215,7 +215,8 @@ class PlayerData {
getPlayer() {
const host = window.location.host;
let element = this.video.parentNode;
const videoWidth = this.video.offsetWidth, videoHeight = this.video.offsetHeight;
const videoWidth = this.video.offsetWidth;
const videoHeight = this.video.offsetHeight;
const elementQ = [];
let scorePenalty = 0;
let score;
@ -352,6 +353,20 @@ class PlayerData {
return a > b - tolerance && a < b + tolerance;
}
forceDetectPlayerElementChange() {
// save current dimensions before refreshing the player object
const oldDimensions = this.dimensions;
this.getPlayer();
// compare new player object dimensions with the old dimensions
// don't fucking trigger changes if nothing changed
if (this.dimensions.width === this.dimensions.width && this.dimensions.height === this.dimensions.height) {
return false;
} else {
return true;
}
}
forceRefreshPlayerElement() {
this.getPlayer();
}

View File

@ -154,8 +154,12 @@ class VideoData {
&& this.isWithin(vh, (ph - (translateY * 2)), 2)
&& this.isWithin(vw, (pw - (translateX * 2)), 2)) {
} else {
this.player.forceRefreshPlayerElement();
this.restoreAr();
if (this.player.forceDetectPlayerElementChange()) {
this.logger.log('info', 'debug', "Video dimensions changed. Triggering restoreAr()");
this.restoreAr();
} else {
this.logger.log('info', 'playerRescan', "Video dimensions didn't change.");
}
}
} catch(e) {