prepare to actually use the settings somewhat

This commit is contained in:
idk
2019-02-07 17:25:06 -05:00
parent 9a9d4e7336
commit db5dbcc6fd
2 changed files with 151 additions and 60 deletions

View File

@@ -1,3 +1,86 @@
function isFirefox() {
testPlain = navigator.userAgent.indexOf('Firefox') !== -1;
if (testPlain) {
return testPlain
}
testTorBrowser = navigator.userAgent.indexOf('Tor') !== -1;
if (testTorBrowser) {
return testTorBrowser
}
return false
}
function setupProxy() {
let proxy_scheme = "http"
let proxy_host = "127.0.0.1"
let proxy_port = 4444
var defaultSettings = {
proxy_scheme: proxy_scheme,
proxy_value: [proxy_host, proxy_port]
};
function checkStoredSettings(storedSettings) {
if (!storedSettings.proxy_scheme || !storedSettings.proxy_value) {
browser.storage.local.set(defaultSettings);
}
}
function onError(e) {
console.error(e);
}
const gettingStoredSettings = browser.storage.local.get();
gettingStoredSettings.then(checkStoredSettings, onError);
if (isFirefox()) {
if (proxy_scheme == "http") {
var proxySettings = {
proxyType: "manual",
http: proxy_host+":"+proxy_port,
passthrough: "",
httpProxyAll: true
};
browser.proxy.settings.set({value:proxySettings});
console.log("i2p settings created for Firefox")
}
}else{
var config = {
mode: "fixed_servers",
rules: {
proxyForHttp: {
scheme: proxy_scheme,
host: proxy_host,
port: proxy_port
},
proxyForFtp: {
scheme: proxy_scheme,
host: proxy_host,
port: proxy_port
},
proxyForHttps: {
scheme: proxy_scheme,
host: proxy_host,
port: proxy_port
},
fallbackProxy: {
scheme: proxy_scheme,
host: proxy_host,
port: proxy_port
}
}
};
chrome.proxy.settings.set(
{value: config, scope: 'regular'},
function() {});
console.log("i2p settings created for Chromium")
}
}
/*
Store the currently selected settings using browser.storage.local.
*/
@@ -38,6 +121,7 @@ function storeSettings() {
proxy_host,
proxy_port,
});
setupProxy()
}
/*
@@ -74,3 +158,4 @@ On clicking the save button, save the currently selected settings.
*/
const saveButton = document.querySelector("#save-button");
saveButton.addEventListener("click", storeSettings);