Hopefully this fixes #104. Turns out 'location.host' and 'location.hostname' aren't quite interchangeable

This commit is contained in:
Tamius Han 2020-06-04 22:47:04 +02:00
parent e7957b6503
commit d59a78b039
8 changed files with 29 additions and 29 deletions

View File

@ -32,8 +32,8 @@ class ActionHandler {
var actions; var actions;
try { try {
if (this.settings.active.sites[window.location.host].actions) { if (this.settings.active.sites[window.location.hostname].actions) {
actions = this.settings.active.sites[window.location.host].actions; actions = this.settings.active.sites[window.location.hostname].actions;
} else { } else {
actions = this.settings.active.actions; actions = this.settings.active.actions;
} }
@ -247,7 +247,7 @@ class ActionHandler {
this.setKeyboardLocal(cmd.arg); this.setKeyboardLocal(cmd.arg);
} }
} else { } else {
let site = action.scope === 'site' ? window.location.host : '@global'; let site = action.scope === 'site' ? window.location.hostname : '@global';
if (cmd.action === "set-stretch") { if (cmd.action === "set-stretch") {
this.settings.active.sites[site].stretch = cmd.arg; this.settings.active.sites[site].stretch = cmd.arg;

View File

@ -36,7 +36,7 @@ class PlayerPickerHelper {
} }
findPlayerForVideo(settings, video) { findPlayerForVideo(settings, video) {
const host = window.location.host; const host = window.location.hostname;
let element = video.parentNode; let element = video.parentNode;
if (this.settings.active.sites[host] if (this.settings.active.sites[host]

View File

@ -495,10 +495,10 @@ class Settings {
canStartAutoAr(site) { canStartAutoAr(site) {
// 'site' argument is only ever used when calling this function recursively for debugging // 'site' argument is only ever used when calling this function recursively for debugging
if (!site) { if (!site) {
site = window.location.host; site = window.location.hostname;
if (!site) { if (!site) {
this.logger.log('warn', ['settings', 'init', 'debug'], `[Settings::canStartAutoAr] No site — even window.location.host returned nothing!: ${window.location.host}`); this.logger.log('warn', ['settings', 'init', 'debug'], `[Settings::canStartAutoAr] No site — even window.location.hostname returned nothing!: ${window.location.hostname}`);
return false; return false;
} }
} }

View File

@ -19,7 +19,7 @@ class CommsClient {
(history) => { (history) => {
this.logger.log('info', 'comms', 'Sending logging-stop-and-save to background script ...'); this.logger.log('info', 'comms', 'Sending logging-stop-and-save to background script ...');
try { try {
this.port.postMessage({cmd: 'logging-stop-and-save', host: window.location.host, history}) this.port.postMessage({cmd: 'logging-stop-and-save', host: window.location.hostname, history})
} catch (e) { } catch (e) {
this.logger.log('error', 'comms', 'Failed to send message to background script. Error:', e); this.logger.log('error', 'comms', 'Failed to send message to background script. Error:', e);
} }

View File

@ -29,7 +29,7 @@ class PageInfo {
try { try {
// request inject css immediately // request inject css immediately
const playerStyleString = this.settings.active.sites[window.location.host].css.replace('\\n', ''); const playerStyleString = this.settings.active.sites[window.location.hostname].css.replace('\\n', '');
this.comms.sendMessage({ this.comms.sendMessage({
cmd: 'inject-css', cmd: 'inject-css',
cssString: playerStyleString cssString: playerStyleString
@ -39,11 +39,11 @@ class PageInfo {
} }
// try getting default crop immediately. // try getting default crop immediately.
// const cropModePersistence = this.settings.getDefaultCropPersistenceMode(window.location.host); // const cropModePersistence = this.settings.getDefaultCropPersistenceMode(window.location.hostname);
// try { // try {
// if (cropModePersistence === CropModePersistence.Forever) { // if (cropModePersistence === CropModePersistence.Forever) {
// this.defaultCrop = this.settings.active.sites[window.location.host].defaultCrop; // this.defaultCrop = this.settings.active.sites[window.location.hostname].defaultCrop;
// } else if (cropModePersistence === CropModePersistence.CurrentSession) { // } else if (cropModePersistence === CropModePersistence.CurrentSession) {
// this.defaultCrop = JSON.parse(sessionStorage.getItem('uw-crop-mode-session-persistence')); // this.defaultCrop = JSON.parse(sessionStorage.getItem('uw-crop-mode-session-persistence'));
// } // }
@ -95,7 +95,7 @@ class PageInfo {
} }
try { try {
playerStyleString = this.settings.active.sites[window.location.host].css; playerStyleString = this.settings.active.sites[window.location.hostname].css;
if (playerStyleString) { if (playerStyleString) {
this.comms.sendMessage({ this.comms.sendMessage({
cmd: 'eject-css', cmd: 'eject-css',
@ -150,7 +150,7 @@ class PageInfo {
const oldVideoCount = this.videos.length; const oldVideoCount = this.videos.length;
try{ try{
var vids = this.getVideos(window.location.host); var vids = this.getVideos(window.location.hostname);
if(!vids || vids.length == 0){ if(!vids || vids.length == 0){
this.hasVideos = false; this.hasVideos = false;
@ -245,9 +245,9 @@ class PageInfo {
// } // }
if (this.videos.length > 0) { if (this.videos.length > 0) {
this.comms.registerVideo({host: window.location.host, location: window.location}); this.comms.registerVideo({host: window.location.hostname, location: window.location});
} else { } else {
this.comms.unregisterVideo({host: window.location.host, location: window.location}); this.comms.unregisterVideo({host: window.location.hostname, location: window.location});
} }
} }
@ -582,12 +582,12 @@ class PageInfo {
if (persistenceMode === CropModePersistence.CurrentSession) { if (persistenceMode === CropModePersistence.CurrentSession) {
sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(this.currentCrop)); sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(this.currentCrop));
} else if (persistenceMode === CropModePersistence.Forever) { } else if (persistenceMode === CropModePersistence.Forever) {
if (this.settings.active.sites[window.location.host]) { if (this.settings.active.sites[window.location.hostname]) {
// | key may be missing, so we do this // | key may be missing, so we do this
this.settings.active.sites[window.location.host]['defaultAr'] = this.currentCrop; this.settings.active.sites[window.location.hostname]['defaultAr'] = this.currentCrop;
} else { } else {
this.settings.active.sites[window.location.host] = this.settings.getDefaultOption(); this.settings.active.sites[window.location.hostname] = this.settings.getDefaultOption();
this.settings.active.sites[window.location.host]['defaultAr'] = this.currentCrop; this.settings.active.sites[window.location.hostname]['defaultAr'] = this.currentCrop;
} }
this.settings.saveWithoutReload(); this.settings.saveWithoutReload();
@ -599,7 +599,7 @@ class PageInfo {
// This means crop persistance is disabled. If crop persistance is enabled, then settings for current // This means crop persistance is disabled. If crop persistance is enabled, then settings for current
// site MUST exist (crop persistence mode is disabled by default) // site MUST exist (crop persistence mode is disabled by default)
const cropModePersistence = this.settings.getDefaultCropPersistenceMode(window.location.host); const cropModePersistence = this.settings.getDefaultCropPersistenceMode(window.location.hostname);
if (cropModePersistence === CropModePersistence.Disabled) { if (cropModePersistence === CropModePersistence.Disabled) {
return; return;
@ -610,12 +610,12 @@ class PageInfo {
if (cropModePersistence === CropModePersistence.CurrentSession) { if (cropModePersistence === CropModePersistence.CurrentSession) {
sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(ar)); sessionStorage.setItem('uw-crop-mode-session-persistence', JSON.stringify(ar));
} else if (cropModePersistence === CropModePersistence.Forever) { } else if (cropModePersistence === CropModePersistence.Forever) {
if (this.settings.active.sites[window.location.host]) { if (this.settings.active.sites[window.location.hostname]) {
// | key may be missing, so we do this // | key may be missing, so we do this
this.settings.active.sites[window.location.host]['defaultAr'] = ar; this.settings.active.sites[window.location.hostname]['defaultAr'] = ar;
} else { } else {
this.settings.active.sites[window.location.host] = this.settings.getDefaultOption(); this.settings.active.sites[window.location.hostname] = this.settings.getDefaultOption();
this.settings.active.sites[window.location.host]['defaultAr'] = ar; this.settings.active.sites[window.location.hostname]['defaultAr'] = ar;
} }
this.settings.saveWithoutReload(); this.settings.saveWithoutReload();

View File

@ -47,7 +47,7 @@ class PlayerData {
this.periodicallyRefreshPlayerElement = false; this.periodicallyRefreshPlayerElement = false;
try { try {
this.periodicallyRefreshPlayerElement = this.settings.active.sites[window.location.host].DOM.player.periodicallyRefreshPlayerElement; this.periodicallyRefreshPlayerElement = this.settings.active.sites[window.location.hostname].DOM.player.periodicallyRefreshPlayerElement;
} catch (e) { } catch (e) {
// no biggie — that means we don't have any special settings for this site. // no biggie — that means we don't have any special settings for this site.
} }
@ -226,7 +226,7 @@ class PlayerData {
} }
getPlayer() { getPlayer() {
const host = window.location.host; const host = window.location.hostname;
let element = this.video.parentNode; let element = this.video.parentNode;
const videoWidth = this.video.offsetWidth; const videoWidth = this.video.offsetWidth;
const videoHeight = this.video.offsetHeight; const videoHeight = this.video.offsetHeight;

View File

@ -151,7 +151,7 @@ class Resizer {
return; return;
} }
const siteSettings = this.settings.active.sites[window.location.host]; const siteSettings = this.settings.active.sites[window.location.hostname];
// reset zoom, but only on aspect ratio switch. We also know that aspect ratio gets converted to // reset zoom, but only on aspect ratio switch. We also know that aspect ratio gets converted to
// AspectRatio.Fixed when zooming, so let's keep that in mind // AspectRatio.Fixed when zooming, so let's keep that in mind
@ -354,7 +354,7 @@ class Resizer {
resetPan() { resetPan() {
this.pan = {}; this.pan = {};
this.videoAlignment = this.settings.getDefaultVideoAlignment(window.location.host); this.videoAlignment = this.settings.getDefaultVideoAlignment(window.location.hostname);
} }
setPan(relativeMousePosX, relativeMousePosY){ setPan(relativeMousePosX, relativeMousePosY){
@ -585,7 +585,7 @@ class Resizer {
let extraStyleString; let extraStyleString;
try { try {
extraStyleString = this.settings.active.sites[window.location.host].DOM.video.additionalCss; extraStyleString = this.settings.active.sites[window.location.hostname].DOM.video.additionalCss;
} catch (e) { } catch (e) {
// do nothing. It's ok if no special settings are defined for this site, we'll just do defaults // do nothing. It's ok if no special settings are defined for this site, we'll just do defaults
} }

View File

@ -48,7 +48,7 @@ class ExecAction {
if (scope === 'global') { if (scope === 'global') {
site = '@global'; site = '@global';
} else if (!this.site) { } else if (!this.site) {
site = window.location.host; site = window.location.hostname;
} }
if (scope === 'site' && !this.settings.active.sites[site]) { if (scope === 'site' && !this.settings.active.sites[site]) {