unborked saving/loading options (forgot to change site -> site.host everywhere where applicable)

This commit is contained in:
Tamius Han 2018-11-09 00:57:05 +01:00
parent a2c127fef5
commit 701a1b1123
3 changed files with 40 additions and 35 deletions

View File

@ -277,7 +277,7 @@ class CommsServer {
} }
if (message.cmd === 'get-current-site') { if (message.cmd === 'get-current-site') {
port.postMessage({cmd: 'set-current-site', site: this.server.getVideoTab()}); port.postMessage({cmd: 'set-current-site', site: this.server.getVideoTab(), tabHostname: await this.getCurrentTabHostname()});
} }
if (message.cmd === 'get-config') { if (message.cmd === 'get-config') {

View File

@ -29,7 +29,7 @@ class PageInfo {
clearTimeout(this.rescanTimer); clearTimeout(this.rescanTimer);
} }
for (var video of this.videos) { for (var video of this.videos) {
this.comms.unregister(video.id) this.comms.unregisterVideo(video.id)
video.destroy(); video.destroy();
} }
} }

View File

@ -28,10 +28,16 @@ async function processReceivedMessage(message, port){
} }
if(message.cmd === 'set-current-site'){ if(message.cmd === 'set-current-site'){
if (site !== message.site) { if (site) {
if (!site.host) {
site.host = site.tabHostname;
}
}
if (!site || site.host !== message.site.host) {
port.postMessage({cmd: 'get-current-zoom'}); port.postMessage({cmd: 'get-current-zoom'});
} }
site = message.site; site = message.site;
if(message.site.host)
loadConfig(message.site.host); loadConfig(message.site.host);
loadFrames(message.site); loadFrames(message.site);
} else if (message.cmd === 'set-current-zoom') { } else if (message.cmd === 'set-current-zoom') {
@ -41,11 +47,11 @@ async function processReceivedMessage(message, port){
async function updateConfig() { async function updateConfig() {
if (Debug.debug) { if (Debug.debug) {
console.log("[popup.js] settings changed. updating popup if site exists. Site:", site); console.log("[popup.js] settings changed. updating popup if site exists. Site:", site.host);
} }
if (site) { if (site && site.host) {
loadConfig(site); loadConfig(site.host);
} }
} }
@ -169,11 +175,11 @@ function configureSitesTab(site) {
if (Debug.debug) { if (Debug.debug) {
console.log("[popup.js] Configuring sites tab (SitePanel).", console.log("[popup.js] Configuring sites tab (SitePanel).",
"\nsite: ", site, "\nsite: ", site,
"\nextension mode: ", settings.active.sites[site] ? settings.active.sites[site].status : 'no site-special settings for this site', "\nextension mode: ", settings.active.sites[site.host] ? settings.active.sites[site.host].status : 'no site-special settings for this site',
"\narDetect mode: ", settings.active.sites[site] ? settings.active.sites[site].arStatus : 'no site-special settings for this site', "\narDetect mode: ", settings.active.sites[site.host] ? settings.active.sites[site.host].arStatus : 'no site-special settings for this site',
"\nvideo float mode:", settings.active.sites[site] ? settings.active.sites[site].videoFloat : 'no site-special settings for this site', "\nvideo float mode:", settings.active.sites[site.host] ? settings.active.sites[site.host].videoFloat : 'no site-special settings for this site',
"\ndefault ar: ", settings.active.sites[site] ? settings.active.sites[site].ar : 'no site-special settings for this site', "\ndefault ar: ", settings.active.sites[site.host] ? settings.active.sites[site.host].ar : 'no site-special settings for this site',
"\nstretch mode: ", settings.active.sites[site] ? settings.active.sites[site].stretch : 'no site-special settings for this site', "\nstretch mode: ", settings.active.sites[site.host] ? settings.active.sites[site.host].stretch : 'no site-special settings for this site',
"\n...") "\n...")
} }
@ -190,24 +196,24 @@ function configureSitesTab(site) {
SitePanel.stretch[button].classList.remove("selected"); SitePanel.stretch[button].classList.remove("selected");
} }
if (settings.active.sites[site] && settings.active.sites[site]) { if (settings.active.sites[site.host] && settings.active.sites[site.host]) {
console.log("settings for", site, "exist!") console.log("settings for", site, "exist!")
SitePanel.extOptions[settings.active.sites[site].status].classList.add("selected"); SitePanel.extOptions[settings.active.sites[site.host].status].classList.add("selected");
SitePanel.arOptions[settings.active.sites[site].arStatus].classList.add("selected"); SitePanel.arOptions[settings.active.sites[site.host].arStatus].classList.add("selected");
} else { } else {
SitePanel.extOptions.default.classList.add("selected"); SitePanel.extOptions.default.classList.add("selected");
SitePanel.arOptions.default.classList.add("selected"); SitePanel.arOptions.default.classList.add("selected");
} }
// optional settings: // optional settings:
if (settings.active.sites[site] && settings.active.sites[site].videoAlignment) { if (settings.active.sites[site.host] && settings.active.sites[site.host].videoAlignment) {
SitePanel.alignment[settings.active.sites[site].videoAlignment].classList.add("selected"); SitePanel.alignment[settings.active.sites[site.host].videoAlignment].classList.add("selected");
} else { } else {
SitePanel.alignment.default.classList.add('selected'); SitePanel.alignment.default.classList.add('selected');
} }
if(settings.active.sites[site] && settings.active.sites[site].stretch !== undefined) { // can be 0 if(settings.active.sites[site.host] && settings.active.sites[site.host].stretch !== undefined) { // can be 0
SitePanel.stretch[settings.active.sites[site].stretch].classList.add("selected"); SitePanel.stretch[settings.active.sites[site.host].stretch].classList.add("selected");
} else { } else {
SitePanel.stretch['-1'].classList.add("selected"); SitePanel.stretch['-1'].classList.add("selected");
} }
@ -343,7 +349,6 @@ function loadFrames(videoTab) {
click.target.classList.add('selected'); click.target.classList.add('selected');
click.target.classList.add('tabitem-selected'); click.target.classList.add('tabitem-selected');
loadConfig(videoTab.frames[frame].host); loadConfig(videoTab.frames[frame].host);
console.log("click:", click, "target classlist", click.target.classList)
click.stopPropagation(); click.stopPropagation();
} }
); );
@ -490,11 +495,11 @@ document.addEventListener("click", (e) => {
mode = "default"; mode = "default";
} }
if(settings.active.sites[site]) { if(settings.active.sites[site.host]) {
settings.active.sites[site].status = mode; settings.active.sites[site.host].status = mode;
settings.active.sites[site].statusEmbedded = mode; settings.active.sites[site.host].statusEmbedded = mode;
} else { } else {
settings.active.sites[site] = { settings.active.sites[site.host] = {
status: mode, status: mode,
statusEmbedded: mode, statusEmbedded: mode,
arStatus: 'default', arStatus: 'default',
@ -578,15 +583,15 @@ document.addEventListener("click", (e) => {
// stretch, site // stretch, site
if (e.target.classList.contains("_ar_stretch_site")) { if (e.target.classList.contains("_ar_stretch_site")) {
if (e.target.classList.contains("_none")) { if (e.target.classList.contains("_none")) {
settings.active.sites[site].stretch = 0; settings.active.sites[site.host].stretch = 0;
} else if (e.target.classList.contains("_basic")) { } else if (e.target.classList.contains("_basic")) {
settings.active.sites[site].stretch = 1; settings.active.sites[site.host].stretch = 1;
} else if (e.target.classList.contains("_hybrid")) { } else if (e.target.classList.contains("_hybrid")) {
settings.active.sites[site].stretch = 2; settings.active.sites[site.host].stretch = 2;
} else if (e.target.classList.contains("_conditional")) { } else if (e.target.classList.contains("_conditional")) {
settings.active.sites[site].stretch = 3; settings.active.sites[site.host].stretch = 3;
} else { } else {
delete(settings.active.sites[site].stretch); delete(settings.active.sites[site.host].stretch);
} }
settings.save(); settings.save();
return; return;
@ -637,10 +642,10 @@ document.addEventListener("click", (e) => {
mode = "default"; mode = "default";
} }
if(settings.active.sites[site]) { if(settings.active.sites[site.host]) {
settings.active.sites[site].arStatus = mode; settings.active.sites[site.host].arStatus = mode;
} else { } else {
settings.active.sites[site] = { settings.active.sites[site.host] = {
status: settings.active.extensionMode, status: settings.active.extensionMode,
statusEmbedded: settings.active.extensionMode, statusEmbedded: settings.active.extensionMode,
arStatus: mode, arStatus: mode,
@ -670,14 +675,14 @@ document.addEventListener("click", (e) => {
return; return;
} }
if (e.target.classList.contains("_align_site_left")) { if (e.target.classList.contains("_align_site_left")) {
settings.active.sites[site].videoAlignment = 'left'; settings.active.sites[site.host].videoAlignment = 'left';
} else if (e.target.classList.contains("_align_site_center")) { } else if (e.target.classList.contains("_align_site_center")) {
settings.active.sites[site].videoAlignment = 'center'; settings.active.sites[site.host].videoAlignment = 'center';
} else if (e.target.classList.contains("_align_site_right")) { } else if (e.target.classList.contains("_align_site_right")) {
settings.active.sites[site].videoAlignment = 'right'; settings.active.sites[site.host].videoAlignment = 'right';
} else { } else {
// default case — remove this object // default case — remove this object
delete(settings.active.sites[site].videoAlignment); delete(settings.active.sites[site.host].videoAlignment);
} }
settings.save(); settings.save();