popup now receives info about current tab as well as the list of frames with videos in that tab
This commit is contained in:
parent
5cf3ec9b86
commit
cbd7cbeb4a
@ -277,7 +277,7 @@ class CommsServer {
|
||||
}
|
||||
|
||||
if (message.cmd === 'get-current-site') {
|
||||
port.postMessage({cmd: 'set-current-site', site: await this.getCurrentTabHostname()});
|
||||
port.postMessage({cmd: 'set-current-site', site: this.server.getVideoTab()});
|
||||
}
|
||||
|
||||
if (message.cmd === 'get-config') {
|
||||
|
22
js/uw-bg.js
22
js/uw-bg.js
@ -14,6 +14,7 @@ class UWServer {
|
||||
this.setup();
|
||||
|
||||
this.videoTabs = {};
|
||||
this.currentTabId = 0;
|
||||
}
|
||||
|
||||
async setup() {
|
||||
@ -60,13 +61,13 @@ class UWServer {
|
||||
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
|
||||
|
||||
try {
|
||||
var tabId = activeInfo.tabId; // just for readability
|
||||
this.currentTabId = activeInfo.tabId; // just for readability
|
||||
|
||||
var tab;
|
||||
if (BrowserDetect.firefox) {
|
||||
var tab = await browser.tabs.get(tabId);
|
||||
var tab = await browser.tabs.get(this.currentTabId);
|
||||
} else if (BrowserDetect.chrome) {
|
||||
var tab = await this._promisifyTabsGet(chrome, tabId);
|
||||
var tab = await this._promisifyTabsGet(chrome, this.currentTabId);
|
||||
}
|
||||
|
||||
this.currentSite = this.extractHostname(tab.url);
|
||||
@ -145,6 +146,21 @@ class UWServer {
|
||||
console.log("[UWServer::ungisterVideo] video unregistered. current videoTabs:", this.videoTabs);
|
||||
}
|
||||
}
|
||||
|
||||
getVideoTab() {
|
||||
// friendly reminder: if current tab doesn't have a video,
|
||||
// there won't be anything in this.videoTabs[this.currentTabId]
|
||||
if (this.videoTabs[this.currentTabId]) {
|
||||
return this.videoTabs[this.currentTabId];
|
||||
}
|
||||
|
||||
// return something more or less empty if this tab doesn't have
|
||||
// a video registered for it
|
||||
return {
|
||||
host: this.currentSite,
|
||||
frames: []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var server = new UWServer();
|
@ -129,7 +129,8 @@ async function processReceivedMessage(message, port){
|
||||
port.postMessage({cmd: 'get-current-zoom'});
|
||||
}
|
||||
site = message.site;
|
||||
loadConfig(message.site);
|
||||
loadConfig(message.site.host);
|
||||
loadFrames(message.site);
|
||||
} else if (message.cmd === 'set-current-zoom') {
|
||||
setCurrentZoom(message.zoom);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user