2018-01-26 00:09:08 +01:00
|
|
|
var BgVars = {
|
|
|
|
arIsActive: true,
|
2018-02-02 00:21:29 +01:00
|
|
|
hasVideos: false,
|
|
|
|
currentSite: ""
|
|
|
|
}
|
|
|
|
|
2018-05-26 23:08:49 +02:00
|
|
|
class UWServer {
|
2018-06-27 23:55:37 +02:00
|
|
|
|
2018-05-26 23:08:49 +02:00
|
|
|
constructor() {
|
|
|
|
this.ports = [];
|
2018-06-27 23:55:37 +02:00
|
|
|
this.arIsActive = true;
|
|
|
|
this.hasVideos = false;
|
|
|
|
this.currentSite = "";
|
2018-05-26 23:08:49 +02:00
|
|
|
this.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
async setup() {
|
2018-08-07 23:31:28 +02:00
|
|
|
this.settings = new Settings();
|
|
|
|
|
|
|
|
await this.settings.init();
|
2018-06-27 23:55:37 +02:00
|
|
|
this.comms = new CommsServer(this);
|
|
|
|
|
|
|
|
|
|
|
|
var ths = this;
|
|
|
|
if(BrowserDetect.firefox) {
|
2018-08-22 23:16:08 +02:00
|
|
|
browser.tabs.onActivated.addListener(function(m) {ths.onTabSwitched(m)});
|
2018-06-27 23:55:37 +02:00
|
|
|
} else if (BrowserDetect.chrome) {
|
2018-08-22 23:16:08 +02:00
|
|
|
chrome.tabs.onActivated.addListener(function(m) {ths.onTabSwitched(m)});
|
2018-06-27 23:55:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async _promisifyTabsGet(browserObj, tabId){
|
|
|
|
return new Promise( (resolve, reject) => {
|
|
|
|
browserObj.tabs.get(tabId, (tab) => resolve(tab));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
extractHostname(url){
|
|
|
|
var hostname;
|
|
|
|
|
|
|
|
// extract hostname
|
|
|
|
if (url.indexOf("://") > -1) { //find & remove protocol (http, ftp, etc.) and get hostname
|
|
|
|
hostname = url.split('/')[2];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
hostname = url.split('/')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
hostname = hostname.split(':')[0]; //find & remove port number
|
|
|
|
hostname = hostname.split('?')[0]; //find & remove "?"
|
|
|
|
|
|
|
|
return hostname;
|
2018-05-26 23:08:49 +02:00
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
|
|
|
|
async onTabSwitched(activeInfo){
|
|
|
|
this.hasVideos = false;
|
|
|
|
|
|
|
|
if(Debug.debug)
|
|
|
|
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
|
|
|
|
|
|
|
|
try {
|
2018-09-13 23:47:20 +02:00
|
|
|
var tabId = activeInfo.tabId; // just for readability
|
2018-06-27 23:55:37 +02:00
|
|
|
|
2018-09-13 23:47:20 +02:00
|
|
|
var tab;
|
|
|
|
if (BrowserDetect.firefox) {
|
|
|
|
var tab = await browser.tabs.get(tabId);
|
|
|
|
} else if (BrowserDetect.chrome) {
|
|
|
|
var tab = await this._promisifyTabsGet(chrome, tabId);
|
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
|
2018-09-13 23:47:20 +02:00
|
|
|
this.currentSite = this.extractHostname(tab.url);
|
2018-06-27 23:55:37 +02:00
|
|
|
} catch(e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
|
2018-07-15 16:35:08 +02:00
|
|
|
if(Debug.debug) {
|
|
|
|
console.log("TAB SWITCHED!", this.currentSite)
|
|
|
|
}
|
2018-06-27 23:55:37 +02:00
|
|
|
//TODO: change extension icon based on whether there's any videos on current page
|
|
|
|
}
|
|
|
|
|
2018-05-26 23:08:49 +02:00
|
|
|
}
|
|
|
|
|
2018-08-02 23:16:07 +02:00
|
|
|
var server = new UWServer();
|