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)
|
||||
return {type: "direct"};
|
||||
|
||||
var tab = await browser.tabs.get(requestInfo.tabId);
|
||||
var proxy = await window.proxifiedContainers.retrieveFromBackground(tab.cookieStoreId);
|
||||
const tab = await browser.tabs.get(requestInfo.tabId);
|
||||
const proxy = await window.proxifiedContainers.retrieveFromBackground(tab.cookieStoreId);
|
||||
|
||||
return proxy;
|
||||
},
|
||||
|
@ -235,7 +235,6 @@ const assignManager = {
|
|||
});
|
||||
|
||||
// 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>"]});
|
||||
|
||||
// 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;
|
||||
});
|
||||
|
||||
var edit_proxy_dom = function(result) {
|
||||
if(result.type == "http")
|
||||
document.querySelector('#edit-container-panel-proxy').value = result.host.toString() + ":" + result.port.toString();
|
||||
else if(result.type == "direct")
|
||||
document.querySelector('#edit-container-panel-proxy').value = "";
|
||||
}
|
||||
const edit_proxy_dom = function(result) {
|
||||
if(result.type === "http")
|
||||
document.querySelector("#edit-container-panel-proxy").value = result.host.toString() + ":" + result.port.toString();
|
||||
else if(result.type === "direct")
|
||||
document.querySelector("#edit-container-panel-proxy").value = "";
|
||||
};
|
||||
|
||||
|
||||
|
||||
window.proxifiedContainers.retrieve(identity.cookieStoreId).then((result) => {
|
||||
edit_proxy_dom(result.proxy);
|
||||
}, (error) => {
|
||||
if(error.error == "uninitialized" || error.error == "doesnotexist") {
|
||||
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error == "uninitialized").then((result) => {
|
||||
if(error.error === "uninitialized" || error.error === "doesnotexist") {
|
||||
window.proxifiedContainers.set(identity.cookieStoreId, DEFAULT_PROXY, error.error === "uninitialized").then((result) => {
|
||||
edit_proxy_dom(result.proxy);
|
||||
}, (error) => {
|
||||
browser.extension.getBackgroundPage().console.log(error);
|
||||
window.proxifiedContainers.report_proxy_error(error);
|
||||
}).catch((error) => {
|
||||
window.proxifiedContainers.report_proxy_error(error);
|
||||
});
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -6,12 +6,21 @@ window.proxifiedContainers = {
|
|||
return new Promise((resolve, reject) => {
|
||||
window.proxifiedContainers.retrieve(cookieStoreId).then((success) => {
|
||||
resolve(success.proxy);
|
||||
}, (error) => {
|
||||
resolve({type: "direct"});
|
||||
}, function() {
|
||||
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
|
||||
retrieve: function(cookieStoreId = null) {
|
||||
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
|
||||
//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) {
|
||||
reject({error: "uninitialized", message: ""});
|
||||
}
|
||||
|
||||
else if(cookieStoreId == null) {
|
||||
if (Object.getOwnPropertyNames(results).length === 0) {
|
||||
reject({
|
||||
error: "uninitialized",
|
||||
message: ""
|
||||
});
|
||||
} else if (cookieStoreId === null) {
|
||||
resolve(results_array);
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
var val = results_array.find(o => o.cookieStoreId === cookieStoreId);
|
||||
if(val == null) {
|
||||
reject({error: "doesnotexist", message: ""});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
const val = results_array.find(o => o.cookieStoreId === cookieStoreId);
|
||||
if (val === null) {
|
||||
reject({
|
||||
error: "doesnotexist",
|
||||
message: ""
|
||||
});
|
||||
} else {
|
||||
resolve(val);
|
||||
}
|
||||
}
|
||||
|
||||
}, (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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if(initialize === true) {
|
||||
var proxifiedContainersStore = [];
|
||||
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
||||
if (initialize === true) {
|
||||
const proxifiedContainersStore = [];
|
||||
browser.storage.local.set({
|
||||
proxifiedContainersKey: proxifiedContainersStore
|
||||
});
|
||||
}
|
||||
|
||||
//Assumes proxy is a properly formatted object
|
||||
window.proxifiedContainers.retrieve().then((proxifiedContainersStore) => {
|
||||
|
||||
var index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
||||
if(index === -1)
|
||||
{
|
||||
proxifiedContainersStore.push({cookieStoreId: cookieStoreId, proxy: proxy});
|
||||
let index = proxifiedContainersStore.findIndex(i => i.cookieStoreId === cookieStoreId);
|
||||
if (index === -1) {
|
||||
proxifiedContainersStore.push({
|
||||
cookieStoreId: cookieStoreId,
|
||||
proxy: proxy
|
||||
});
|
||||
index = proxifiedContainersStore.length - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
proxifiedContainersStore[index] = {cookieStoreId: cookieStoreId, proxy: proxy};
|
||||
} else {
|
||||
proxifiedContainersStore[index] = {
|
||||
cookieStoreId: cookieStoreId,
|
||||
proxy: proxy
|
||||
};
|
||||
}
|
||||
|
||||
browser.storage.local.set({proxifiedContainersKey: proxifiedContainersStore});
|
||||
browser.storage.local.set({
|
||||
proxifiedContainersKey: proxifiedContainersStore
|
||||
});
|
||||
resolve(proxifiedContainersStore[index]);
|
||||
}, (errorObj) => {
|
||||
reject(errorObj);
|
||||
}).catch((error) => {
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
},
|
||||
parseProxy: function(proxy_str) {
|
||||
var regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
||||
if(regexp.test(proxy_str) !== true)
|
||||
const regexp = /(\b(\w+):(\w+)@)?(((?:\d{1,3}\.){3}\d{1,3}\b)|(\b(\w+)(\.(\w+))+))(:(\d+))?/;
|
||||
if (regexp.test(proxy_str) !== true)
|
||||
return false;
|
||||
|
||||
else
|
||||
{
|
||||
var matches = regexp.exec(proxy_str);
|
||||
else {
|
||||
const matches = regexp.exec(proxy_str);
|
||||
|
||||
var result = {
|
||||
const result = {
|
||||
type: "http",
|
||||
host: matches[4],
|
||||
port: parseInt(matches[11]) || 8080,
|
||||
port: parseInt(matches[11], 10) || 8080,
|
||||
username: matches[2] || "",
|
||||
password: matches[3] || ""
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue