Use optional chaining
This commit is contained in:
parent
c8d943da0b
commit
9ba1afebee
@ -555,7 +555,7 @@ class Settings {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -563,7 +563,7 @@ class Settings {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -572,7 +572,7 @@ class Settings {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -132,11 +132,8 @@ class PageInfo {
|
||||
}
|
||||
|
||||
getVideos(host) {
|
||||
if (this.settings.active.sites[host]
|
||||
&& this.settings.active.sites[host].DOM
|
||||
&& this.settings.active.sites[host].DOM.video
|
||||
&& this.settings.active.sites[host].DOM.video.manual
|
||||
&& this.settings.active.sites[host].DOM.video.querySelector){
|
||||
if (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);
|
||||
|
||||
if (videos.length) {
|
||||
|
@ -247,12 +247,9 @@ class PlayerData {
|
||||
this.logger.log('info', 'playerDetect', "\n\n[PlayerDetect::getPlayer()] element hierarchy (video->root)", logObj);
|
||||
}
|
||||
|
||||
if (this.settings.active.sites[host]
|
||||
&& this.settings.active.sites[host].DOM
|
||||
&& this.settings.active.sites[host].DOM.player
|
||||
&& 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) {
|
||||
if (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;
|
||||
while (parentsLeft --> 0) {
|
||||
@ -262,7 +259,7 @@ class PlayerData {
|
||||
this.updatePlayerDimensions(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);
|
||||
// actually we'll also score this branch in a similar way we score the regular, auto branch
|
||||
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
|
||||
// ignore the contents of this if (unless we need to change how logging works)
|
||||
if (this.logger.canLog('debug')){
|
||||
if (!this.dimensions) {
|
||||
|
||||
} else if (this.dimensions && this.dimensions.fullscreen){
|
||||
if (this.dimensions?.fullscreen){
|
||||
if(! PlayerData.isFullScreen()){
|
||||
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");
|
||||
}
|
||||
|
||||
if ( this.element && this.dimensions &&
|
||||
( this.dimensions.width != this.element.offsetWidth ||
|
||||
this.dimensions.height != this.element.offsetHeight )
|
||||
if ( this.element &&
|
||||
( +this.dimensions?.width != +this.element?.offsetWidth ||
|
||||
+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 (!this.dimensions
|
||||
|| this.dimensions.width != this.element.offsetWidth
|
||||
|| this.dimensions.height != this.element.offsetHeight ){
|
||||
if (this.dimensions?.width != this.element.offsetWidth
|
||||
|| this.dimensions?.height != this.element.offsetHeight ){
|
||||
|
||||
const isFullScreen = PlayerData.isFullScreen();
|
||||
|
||||
|
@ -420,18 +420,17 @@ class VideoData {
|
||||
if(! this.video) {
|
||||
this.logger.log('info', 'videoDetect', "[VideoDetect] player element isn't defined");
|
||||
}
|
||||
if ( this.video && this.dimensions &&
|
||||
( this.dimensions.width != videoWidth ||
|
||||
this.dimensions.height != videoHeight )
|
||||
if ( this.video &&
|
||||
( this.dimensions?.width != videoWidth ||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// if size doesn't match, update & return true
|
||||
if (!this.dimensions
|
||||
|| this.dimensions.width != videoWidth
|
||||
|| this.dimensions.height != videoHeight ){
|
||||
if (this.dimensions?.width != videoWidth
|
||||
|| this.dimensions?.height != videoHeight ){
|
||||
this.dimensions = {
|
||||
width: videoWidth,
|
||||
height: videoHeight,
|
||||
|
@ -167,32 +167,30 @@ class Resizer {
|
||||
ar.type === AspectRatio.Reset && this.lastAr.type === AspectRatio.Initial) {
|
||||
// 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
|
||||
if (siteSettings && siteSettings.autoarPreventConditions) {
|
||||
if (siteSettings.autoarPreventConditions.videoStyleString) {
|
||||
const styleString = (this.video.getAttribute('style') || '').split(';');
|
||||
|
||||
if (siteSettings.autoarPreventConditions.videoStyleString.containsProperty) {
|
||||
const bannedProperties = siteSettings.autoarPreventConditions.videoStyleString.containsProperty;
|
||||
for (const prop in bannedProperties) {
|
||||
for (const s of styleString) {
|
||||
if (s.trim().startsWith(prop)) {
|
||||
|
||||
// check if css property has a list of allowed values:
|
||||
if (bannedProperties[prop].allowedValues) {
|
||||
const styleValue = s.split(':')[1].trim();
|
||||
|
||||
// check if property value is on the list of allowed values
|
||||
// if it's not, we aren't allowed to start aard
|
||||
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.")
|
||||
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.")
|
||||
if (siteSettings?.autoarPreventConditions?.videoStyleString) {
|
||||
const styleString = (this.video.getAttribute('style') || '').split(';');
|
||||
|
||||
if (siteSettings.autoarPreventConditions.videoStyleString.containsProperty) {
|
||||
const bannedProperties = siteSettings.autoarPreventConditions.videoStyleString.containsProperty;
|
||||
for (const prop in bannedProperties) {
|
||||
for (const s of styleString) {
|
||||
if (s.trim().startsWith(prop)) {
|
||||
|
||||
// check if css property has a list of allowed values:
|
||||
if (bannedProperties[prop].allowedValues) {
|
||||
const styleValue = s.split(':')[1].trim();
|
||||
|
||||
// check if property value is on the list of allowed values
|
||||
// if it's not, we aren't allowed to start aard
|
||||
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.")
|
||||
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});
|
||||
}
|
||||
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
|
||||
// throw "Last ar is null!"
|
||||
return;
|
||||
@ -378,7 +376,7 @@ class Resizer {
|
||||
}
|
||||
|
||||
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.resetPan();
|
||||
this.setAr({type: AspectRatio.Reset});
|
||||
|
@ -179,16 +179,10 @@ class UWServer {
|
||||
|
||||
// preveri za osirotele/zastarele vrednosti ter jih po potrebi izbriši
|
||||
// check for orphaned/outdated values and remove them if neccessary
|
||||
if (this.videoTabs[sender.tab.id]) {
|
||||
if (this.videoTabs[sender.tab.id].host != tabHostname) {
|
||||
delete this.videoTabs[sender.tab.id]
|
||||
} else {
|
||||
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]?.host != tabHostname) {
|
||||
delete this.videoTabs[sender.tab.id]
|
||||
} else 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]) {
|
||||
|
Loading…
Reference in New Issue
Block a user