Use optional chaining
This commit is contained in:
parent
c8d943da0b
commit
9ba1afebee
@ -555,7 +555,7 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDefaultStretchMode(site) {
|
getDefaultStretchMode(site) {
|
||||||
if (site && this.active.sites[site] && this.active.sites[site].stretch !== Stretch.Default) {
|
if (site && this.active.sites[site]?.stretch !== Stretch.Default) {
|
||||||
return this.active.sites[site].stretch;
|
return this.active.sites[site].stretch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +563,7 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDefaultCropPersistenceMode(site) {
|
getDefaultCropPersistenceMode(site) {
|
||||||
if (site && this.active.sites[site] && this.active.sites[site].cropModePersistence !== Stretch.Default) {
|
if (site && this.active.sites[site]?.cropModePersistence !== Stretch.Default) {
|
||||||
return this.active.sites[site].cropModePersistence;
|
return this.active.sites[site].cropModePersistence;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,7 +572,7 @@ class Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDefaultVideoAlignment(site) {
|
getDefaultVideoAlignment(site) {
|
||||||
if (site && this.active.sites[site] && this.active.sites[site].videoAlignment !== VideoAlignment.Default) {
|
if (this.active.sites[site]?.videoAlignment !== VideoAlignment.Default) {
|
||||||
return this.active.sites[site].videoAlignment;
|
return this.active.sites[site].videoAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,11 +132,8 @@ class PageInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getVideos(host) {
|
getVideos(host) {
|
||||||
if (this.settings.active.sites[host]
|
if (this.settings.active.sites[host]?.DOM?.video?.manual
|
||||||
&& this.settings.active.sites[host].DOM
|
&& this.settings.active.sites[host]?.DOM?.video?.querySelector){
|
||||||
&& this.settings.active.sites[host].DOM.video
|
|
||||||
&& this.settings.active.sites[host].DOM.video.manual
|
|
||||||
&& this.settings.active.sites[host].DOM.video.querySelector){
|
|
||||||
const videos = document.querySelectorAll(this.settings.active.sites[host].DOM.video.querySelector);
|
const videos = document.querySelectorAll(this.settings.active.sites[host].DOM.video.querySelector);
|
||||||
|
|
||||||
if (videos.length) {
|
if (videos.length) {
|
||||||
|
@ -247,12 +247,9 @@ class PlayerData {
|
|||||||
this.logger.log('info', 'playerDetect', "\n\n[PlayerDetect::getPlayer()] element hierarchy (video->root)", logObj);
|
this.logger.log('info', 'playerDetect', "\n\n[PlayerDetect::getPlayer()] element hierarchy (video->root)", logObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.settings.active.sites[host]
|
if (this.settings.active.sites[host]?.DOM?.player?.manual) {
|
||||||
&& this.settings.active.sites[host].DOM
|
if (this.settings.active.sites[host]?.DOM?.player?.useRelativeAncestor
|
||||||
&& this.settings.active.sites[host].DOM.player
|
&& this.settings.active.sites[host]?.DOM?.player?.videoAncestor) {
|
||||||
&& this.settings.active.sites[host].DOM.player.manual) {
|
|
||||||
if (this.settings.active.sites[host].DOM.player.useRelativeAncestor
|
|
||||||
&& this.settings.active.sites[host].DOM.player.videoAncestor) {
|
|
||||||
|
|
||||||
let parentsLeft = this.settings.active.sites[host].DOM.player.videoAncestor - 1;
|
let parentsLeft = this.settings.active.sites[host].DOM.player.videoAncestor - 1;
|
||||||
while (parentsLeft --> 0) {
|
while (parentsLeft --> 0) {
|
||||||
@ -262,7 +259,7 @@ class PlayerData {
|
|||||||
this.updatePlayerDimensions(element);
|
this.updatePlayerDimensions(element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
} else if (this.settings.active.sites[host].DOM.player.querySelectors) {
|
} else if (this.settings.active.sites[host]?.DOM?.player?.querySelectors) {
|
||||||
const allSelectors = document.querySelectorAll(this.settings.active.sites[host].DOM.player.querySelectors);
|
const allSelectors = document.querySelectorAll(this.settings.active.sites[host].DOM.player.querySelectors);
|
||||||
// actually we'll also score this branch in a similar way we score the regular, auto branch
|
// actually we'll also score this branch in a similar way we score the regular, auto branch
|
||||||
while (element) {
|
while (element) {
|
||||||
@ -397,9 +394,7 @@ class PlayerData {
|
|||||||
// this 'if' is just here for debugging — real code starts later. It's safe to collapse and
|
// 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)
|
// ignore the contents of this if (unless we need to change how logging works)
|
||||||
if (this.logger.canLog('debug')){
|
if (this.logger.canLog('debug')){
|
||||||
if (!this.dimensions) {
|
if (this.dimensions?.fullscreen){
|
||||||
|
|
||||||
} else if (this.dimensions && this.dimensions.fullscreen){
|
|
||||||
if(! PlayerData.isFullScreen()){
|
if(! PlayerData.isFullScreen()){
|
||||||
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: exited fullscreen");
|
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: exited fullscreen");
|
||||||
}
|
}
|
||||||
@ -408,19 +403,17 @@ class PlayerData {
|
|||||||
this.logger.log('info', 'playerDetect', "[PlayerDetect] player element isn't defined");
|
this.logger.log('info', 'playerDetect', "[PlayerDetect] player element isn't defined");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.element && this.dimensions &&
|
if ( this.element &&
|
||||||
( this.dimensions.width != this.element.offsetWidth ||
|
( +this.dimensions?.width != +this.element?.offsetWidth ||
|
||||||
this.dimensions.height != this.element.offsetHeight )
|
+this.dimensions?.height != +this.element?.offsetHeight )
|
||||||
) {
|
) {
|
||||||
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.element.offsetWidth, this.element.offsetHeight);
|
this.logger.log('info', 'debug', "[PlayerDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions?.width, this.dimensions?.height, "new dimensions:", this.element?.offsetWidth, this.element?.offsetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if size doesn't match, update & return true
|
// if size doesn't match, update & return true
|
||||||
if (!this.dimensions
|
if (this.dimensions?.width != this.element.offsetWidth
|
||||||
|| this.dimensions.width != this.element.offsetWidth
|
|| this.dimensions?.height != this.element.offsetHeight ){
|
||||||
|| this.dimensions.height != this.element.offsetHeight ){
|
|
||||||
|
|
||||||
const isFullScreen = PlayerData.isFullScreen();
|
const isFullScreen = PlayerData.isFullScreen();
|
||||||
|
|
||||||
|
@ -420,18 +420,17 @@ class VideoData {
|
|||||||
if(! this.video) {
|
if(! this.video) {
|
||||||
this.logger.log('info', 'videoDetect', "[VideoDetect] player element isn't defined");
|
this.logger.log('info', 'videoDetect', "[VideoDetect] player element isn't defined");
|
||||||
}
|
}
|
||||||
if ( this.video && this.dimensions &&
|
if ( this.video &&
|
||||||
( this.dimensions.width != videoWidth ||
|
( this.dimensions?.width != videoWidth ||
|
||||||
this.dimensions.height != videoHeight )
|
this.dimensions?.height != videoHeight )
|
||||||
) {
|
) {
|
||||||
this.logger.log('info', 'debug', "[VideoDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.video.offsetWidth, this.video.offsetHeight);
|
this.logger.log('info', 'debug', "[VideoDetect] player size changed. reason: dimension change. Old dimensions?", this.dimensions.width, this.dimensions.height, "new dimensions:", this.video.offsetWidth, this.video.offsetHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if size doesn't match, update & return true
|
// if size doesn't match, update & return true
|
||||||
if (!this.dimensions
|
if (this.dimensions?.width != videoWidth
|
||||||
|| this.dimensions.width != videoWidth
|
|| this.dimensions?.height != videoHeight ){
|
||||||
|| this.dimensions.height != videoHeight ){
|
|
||||||
this.dimensions = {
|
this.dimensions = {
|
||||||
width: videoWidth,
|
width: videoWidth,
|
||||||
height: videoHeight,
|
height: videoHeight,
|
||||||
|
@ -167,32 +167,30 @@ class Resizer {
|
|||||||
ar.type === AspectRatio.Reset && this.lastAr.type === AspectRatio.Initial) {
|
ar.type === AspectRatio.Reset && this.lastAr.type === AspectRatio.Initial) {
|
||||||
// some sites do things that interfere with our site (and aspect ratio setting in general)
|
// some sites do things that interfere with our site (and aspect ratio setting in general)
|
||||||
// first, we check whether video contains anything we don't like
|
// first, we check whether video contains anything we don't like
|
||||||
if (siteSettings && siteSettings.autoarPreventConditions) {
|
if (siteSettings?.autoarPreventConditions?.videoStyleString) {
|
||||||
if (siteSettings.autoarPreventConditions.videoStyleString) {
|
const styleString = (this.video.getAttribute('style') || '').split(';');
|
||||||
const styleString = (this.video.getAttribute('style') || '').split(';');
|
|
||||||
|
if (siteSettings.autoarPreventConditions.videoStyleString.containsProperty) {
|
||||||
if (siteSettings.autoarPreventConditions.videoStyleString.containsProperty) {
|
const bannedProperties = siteSettings.autoarPreventConditions.videoStyleString.containsProperty;
|
||||||
const bannedProperties = siteSettings.autoarPreventConditions.videoStyleString.containsProperty;
|
for (const prop in bannedProperties) {
|
||||||
for (const prop in bannedProperties) {
|
for (const s of styleString) {
|
||||||
for (const s of styleString) {
|
if (s.trim().startsWith(prop)) {
|
||||||
if (s.trim().startsWith(prop)) {
|
|
||||||
|
// check if css property has a list of allowed values:
|
||||||
// check if css property has a list of allowed values:
|
if (bannedProperties[prop].allowedValues) {
|
||||||
if (bannedProperties[prop].allowedValues) {
|
const styleValue = s.split(':')[1].trim();
|
||||||
const styleValue = s.split(':')[1].trim();
|
|
||||||
|
// check if property value is on the list of allowed values
|
||||||
// check if property value is on the list of allowed values
|
// if it's not, we aren't allowed to start aard
|
||||||
// if it's not, we aren't allowed to start aard
|
if (bannedProperties[prop].allowedValues.indexOf(styleValue) === -1) {
|
||||||
if (bannedProperties[prop].allowedValues.indexOf(styleValue) === -1) {
|
this.logger.log('error', 'debug', "%c[Resizer::setAr] video style contains forbidden css property/value combo: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
||||||
this.logger.log('error', 'debug', "%c[Resizer::setAr] video style contains forbidden css property/value combo: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// no allowed values, no problem. We have forbidden property
|
|
||||||
// and this means aard can't start.
|
|
||||||
this.logger.log('info', 'debug', "%c[Resizer::setAr] video style contains forbidden css property: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// no allowed values, no problem. We have forbidden property
|
||||||
|
// and this means aard can't start.
|
||||||
|
this.logger.log('info', 'debug', "%c[Resizer::setAr] video style contains forbidden css property: ", "color: #900, background: #100", prop, " — we aren't allowed to start autoar.")
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,7 +366,7 @@ class Resizer {
|
|||||||
this.setAr({type: AspectRatio.Reset});
|
this.setAr({type: AspectRatio.Reset});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.lastAr && this.lastAr.ratio === null) {
|
if (this.lastAr?.ratio === null) {
|
||||||
// if this is the case, we do nothing as we have the correct aspect ratio
|
// if this is the case, we do nothing as we have the correct aspect ratio
|
||||||
// throw "Last ar is null!"
|
// throw "Last ar is null!"
|
||||||
return;
|
return;
|
||||||
@ -378,7 +376,7 @@ class Resizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reset(){
|
reset(){
|
||||||
this.setStretchMode(this.settings.active.sites[window.location.hostname] ? this.settings.active.sites[window.location.hostname].stretch : this.settings.active.sites['@global'].stretch);
|
this.setStretchMode(this.settings.active.sites[window.location.hostname]?.stretch ?? this.settings.active.sites['@global'].stretch);
|
||||||
this.zoom.setZoom(1);
|
this.zoom.setZoom(1);
|
||||||
this.resetPan();
|
this.resetPan();
|
||||||
this.setAr({type: AspectRatio.Reset});
|
this.setAr({type: AspectRatio.Reset});
|
||||||
|
@ -179,16 +179,10 @@ class UWServer {
|
|||||||
|
|
||||||
// preveri za osirotele/zastarele vrednosti ter jih po potrebi izbriši
|
// preveri za osirotele/zastarele vrednosti ter jih po potrebi izbriši
|
||||||
// check for orphaned/outdated values and remove them if neccessary
|
// check for orphaned/outdated values and remove them if neccessary
|
||||||
if (this.videoTabs[sender.tab.id]) {
|
if (this.videoTabs[sender.tab.id]?.host != tabHostname) {
|
||||||
if (this.videoTabs[sender.tab.id].host != tabHostname) {
|
delete this.videoTabs[sender.tab.id]
|
||||||
delete this.videoTabs[sender.tab.id]
|
} else if(this.videoTabs[sender.tab.id]?.frames[sender.frameId]?.host != frameHostname) {
|
||||||
} else {
|
delete this.videoTabs[sender.tab.id].frames[sender.frameId];
|
||||||
if(this.videoTabs[sender.tab.id].frames[sender.frameId]) {
|
|
||||||
if (this.videoTabs[sender.tab.id].frames[sender.frameId].host != frameHostname) {
|
|
||||||
delete this.videoTabs[sender.tab.id].frames[sender.frameId];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.videoTabs[sender.tab.id]) {
|
if (this.videoTabs[sender.tab.id]) {
|
||||||
|
Loading…
Reference in New Issue
Block a user