Fixed lint JS errors
This commit is contained in:
parent
790a9273f9
commit
e3531fb7b5
3 changed files with 87 additions and 61 deletions
|
@ -121,8 +121,8 @@ const assignManager = {
|
||||||
if(requestInfo.tabId === -1)
|
if(requestInfo.tabId === -1)
|
||||||
return {type: "direct"};
|
return {type: "direct"};
|
||||||
|
|
||||||
var tab = await browser.tabs.get(requestInfo.tabId);
|
const tab = await browser.tabs.get(requestInfo.tabId);
|
||||||
var proxy = await window.proxifiedContainers.retrieveFromBackground(tab.cookieStoreId);
|
const proxy = await window.proxifiedContainers.retrieveFromBackground(tab.cookieStoreId);
|
||||||
|
|
||||||
return proxy;
|
return proxy;
|
||||||
},
|
},
|
||||||
|
@ -235,7 +235,6 @@ const assignManager = {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Before anything happens we decide if the request should be proxified
|
// Before anything happens we decide if the request should be proxified
|
||||||
browser.extension.getBackgroundPage().console.log('[SAMUEL CODE] Adding proxy.onRequest listener');
|
|
||||||
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
|
browser.proxy.onRequest.addListener(this.handleProxifiedRequest, {urls: ["<all_urls>"]});
|
||||||
|
|
||||||
// Before a request is handled by the browser we decide if we should route through a different container
|
// Before a request is handled by the browser we decide if we should route through a different container
|
||||||
|
|
|
@ -1069,26 +1069,32 @@ Logic.registerPanel(P_CONTAINER_EDIT, {
|
||||||
iconInput.checked = iconInput.value === identity.icon;
|
iconInput.checked = iconInput.value === identity.icon;
|
||||||
});
|
});
|
||||||
|
|
||||||
var edit_proxy_dom = function(result) {
|
const edit_proxy_dom = function(result) {
|
||||||
if(result.type == "http")
|
if(result.type === "http")
|
||||||
document.querySelector('#edit-container-panel-proxy').value = result.host.toString() + ":" + result.port.toString();
|
document.querySelector("#edit-container-panel-proxy").value = result.host.toString() + ":" + result.port.toString();
|
||||||
else if(result.type == "direct")
|
else if(result.type === "direct")
|
||||||
document.querySelector('#edit-container-panel-proxy').value = "";
|
document.querySelector("#edit-container-panel-proxy").value = "";
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => {
|
window.proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => {
|
||||||
edit_proxy_dom(result.proxy);
|
edit_proxy_dom(result.proxy);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
if(error.error == "uninitialized" || error.error == "doesnotexist") {
|
if(error.error === "uninitialized" || error.error === "doesnotexist") {
|
||||||
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error == "uninitialized").then((result) => {
|
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error === "uninitialized").then((result) => {
|
||||||
edit_proxy_dom(result.proxy);
|
edit_proxy_dom(result.proxy);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
browser.extension.getBackgroundPage().console.log(error);
|
window.proxifiedContainers.report_proxy_error(error);
|
||||||
|
}).catch((error) => {
|
||||||
|
window.proxifiedContainers.report_proxy_error(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
browser.extension.getBackgroundPage().console.log(error);
|
window.proxifiedContainers.report_proxy_error(error);
|
||||||
}
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
window.proxifiedContainers.report_proxy_error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.resolve(null);
|
return Promise.resolve(null);
|
||||||
|
|
|
@ -6,12 +6,21 @@ window.proxifiedContainers = {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
window.proxifiedContainers.retrieve(cookieStoreId).then((success) => {
|
window.proxifiedContainers.retrieve(cookieStoreId).then((success) => {
|
||||||
resolve(success.proxy);
|
resolve(success.proxy);
|
||||||
}, (error) => {
|
}, function() {
|
||||||
resolve({type: "direct"});
|
resolve({
|
||||||
|
type: "direct"
|
||||||
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
report_proxy_error: function(error) {
|
||||||
|
//Currently I print to console but this is inefficient
|
||||||
|
browser.extension.getBackgroundPage().console.log("proxifiedContainers error occured: " + JSON.Stringify(error));
|
||||||
|
},
|
||||||
|
|
||||||
//Resolves to a proxy object which can be used in the return of the listener required for browser.proxy.onRequest.addListener
|
//Resolves to a proxy object which can be used in the return of the listener required for browser.proxy.onRequest.addListener
|
||||||
retrieve: function(cookieStoreId = null) {
|
retrieve: function(cookieStoreId = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -22,74 +31,86 @@ window.proxifiedContainers = {
|
||||||
//3. If there doesn't exist an entry for the associated cookieStoreId, inform the caller of this
|
//3. If there doesn't exist an entry for the associated cookieStoreId, inform the caller of this
|
||||||
//4. Normal operation - if the cookieStoreId exists in the map, we can simply resolve with the correct proxy value
|
//4. Normal operation - if the cookieStoreId exists in the map, we can simply resolve with the correct proxy value
|
||||||
|
|
||||||
var results_array = results["proxifiedContainersKey"];
|
const results_array = results["proxifiedContainersKey"];
|
||||||
|
|
||||||
if (Object.getOwnPropertyNames(results).length == 0) {
|
if (Object.getOwnPropertyNames(results).length === 0) {
|
||||||
reject({error: "uninitialized", message: ""});
|
reject({
|
||||||
}
|
error: "uninitialized",
|
||||||
|
message: ""
|
||||||
else if(cookieStoreId == null) {
|
});
|
||||||
|
} else if (cookieStoreId === null) {
|
||||||
resolve(results_array);
|
resolve(results_array);
|
||||||
}
|
} else {
|
||||||
|
const val = results_array.find(o => o.cookieStoreId === cookieStoreId);
|
||||||
|
if (val === null) {
|
||||||
else {
|
reject({
|
||||||
var val = results_array.find(o => o.cookieStoreId === cookieStoreId);
|
error: "doesnotexist",
|
||||||
if(val == null) {
|
message: ""
|
||||||
reject({error: "doesnotexist", message: ""});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
resolve(val);
|
resolve(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
reject({error: "internal", message: error});
|
reject({
|
||||||
}
|
error: "internal",
|
||||||
);
|
message: error
|
||||||
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
window.proxifiedContainers.report_proxy_error(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
set: function(cookieStoreId, proxy, initialize = false) {
|
set: function(cookieStoreId, proxy, initialize = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if(initialize === true) {
|
if (initialize === true) {
|
||||||
var proxifiedContainersStore = [];
|
const proxifiedContainersStore = [];
|
||||||
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
browser.storage.local.set({
|
||||||
|
proxifiedContainersKey: proxifiedContainersStore
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//Assumes proxy is a properly formatted object
|
//Assumes proxy is a properly formatted object
|
||||||
window.proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
|
window.proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
|
||||||
|
|
||||||
var index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
||||||
if(index === -1)
|
if (index === -1) {
|
||||||
{
|
proxifiedContainersStore.push({
|
||||||
proxifiedContainersStore.push({cookieStoreId: cookieStoreId, proxy: proxy});
|
cookieStoreId: cookieStoreId,
|
||||||
|
proxy: proxy
|
||||||
|
});
|
||||||
index = proxifiedContainersStore.length - 1;
|
index = proxifiedContainersStore.length - 1;
|
||||||
}
|
} else {
|
||||||
else
|
proxifiedContainersStore[index] = {
|
||||||
{
|
cookieStoreId: cookieStoreId,
|
||||||
proxifiedContainersStore[index] = {cookieStoreId: cookieStoreId, proxy: proxy};
|
proxy: proxy
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
browser.storage.local.set({
|
||||||
|
proxifiedContainersKey: proxifiedContainersStore
|
||||||
|
});
|
||||||
resolve(proxifiedContainersStore[index]);
|
resolve(proxifiedContainersStore[index]);
|
||||||
}, (errorObj) => {
|
}, (errorObj) => {
|
||||||
reject(errorObj);
|
reject(errorObj);
|
||||||
|
}).catch((error) => {
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parseProxy: function(proxy_str) {
|
parseProxy: function(proxy_str) {
|
||||||
var regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
||||||
if(regexp.test(proxy_str) !== true)
|
if (regexp.test(proxy_str) !== true)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
const matches = regexp.exec(proxy_str);
|
||||||
var matches = regexp.exec(proxy_str);
|
|
||||||
|
|
||||||
var result = {
|
const result = {
|
||||||
type: "http",
|
type: "http",
|
||||||
host: matches[4],
|
host: matches[4],
|
||||||
port: parseInt(matches[11]) || 8080,
|
port: parseInt(matches[11], 10) || 8080,
|
||||||
username: matches[2] || "",
|
username: matches[2] || "",
|
||||||
password: matches[3] || ""
|
password: matches[3] || ""
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue