tidy up some of my settings stuff and expose configurable router console port

This commit is contained in:
idk
2020-01-13 14:48:02 -05:00
parent 923688b914
commit 72954ceda6
6 changed files with 129 additions and 184 deletions

View File

@@ -203,6 +203,10 @@
"message": "Visit the I2P Forum to learn more or ask for assistance",
"description": "Help Message"
},
"proxyHelpText": {
"message": "Configure your I2P proxy here.",
"description": "Help for configuring the options for the Reset Tunnel button"
},
"hostText": {
"message": "Host: ",
"description": "Host for the HTTP or SOCKS5 Proxy"
@@ -212,7 +216,7 @@
"description": "Port for the HTTP or SOCKS5 Proxy"
},
"controlHelpText": {
"message": "These options will be inert if used with the default i2p HTTP or SOCKS proxy.",
"message": "Configure your router console here.",
"description": "Help for configuring the options for the Reset Tunnel button"
},
"controlHostText": {

View File

@@ -53,9 +53,9 @@ span.identity {
margin-left: 1em;
}
.control-options {
/*.control-options {
display: none;
}
}*/
.identity-options {
display: none;

View File

@@ -4,20 +4,21 @@
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="options.css"/>
<link rel="stylesheet" href="/home.css"/>
</head>
<body>
<section class="scheme-options">
<span class="title">Proxy Scheme:</span>
<select id="proxy_scheme">
<option value="http" selected="selected">HTTP</option>
<option value="http" selected>HTTP</option>
<option value="socks5">SOCKS5</option>
</select>
</section>
<section class="scheme-options proxy-options">
<div class="title" >Proxy Options</div>
<p id="proxyHelpText"> </p>
<label id="portText">Host: </label>
<input type="text" data="host" id="host" value="127.0.0.1"/>
<br>
@@ -32,14 +33,13 @@
</section>
<section class="scheme-options control-options">
<div class="title" >Controller Options</div>
<p id="controlHelpText"> These options will be inert if used with the default i2p HTTP or SOCKS
proxy. </p>
<div class="title" >Router Console Options</div>
<p id="controlHelpText"> </p>
<label id="controlPortText">Control Host: </label>
<input type="text" data="controlhost" id="controlhost" value="127.0.0.1"/>
<br>
<label id="controlHostText">Control Port: </label>
<input type="text" data="controlport" id="controlport" value="4444"/>
<input type="text" data="controlport" id="controlport" value="7657"/>
</section>

View File

@@ -8,6 +8,11 @@ function SetPortText() {
portid.textContent = chrome.i18n.getMessage("portText");
}
function SetPortHelpText() {
var portid = document.getElementById("proxyHelpText");
portid.textContent = chrome.i18n.getMessage("proxyHelpText");
}
function SetControlHostText() {
var controlhostid = document.getElementById("controlHostText");
controlhostid.textContent = chrome.i18n.getMessage("controlHostText");
@@ -25,19 +30,20 @@ function SetControlHelpText() {
function getScheme() {
const proxy_scheme = document.querySelector("#proxy_scheme");
console.log("Got i2p proxy scheme:", proxy_scheme.value);
if (proxy_scheme == "HTTP") {
console.log("(options)Got i2p proxy scheme:", proxy_scheme.value);
if (proxy_scheme.value == "HTTP") {
return "http";
}
if (proxy_scheme == "SOCKS") {
if (proxy_scheme.value == "SOCKS") {
return "socks";
}
return proxy_scheme.value;
if (proxy_scheme.value != "http" && proxy_scheme.value != "socks")
return "http";
}
function getHost() {
proxy_host = document.getElementById("host").value;
console.log("Got i2p proxy host:", proxy_host);
console.log("(options)Got i2p proxy host:", proxy_host);
if (proxy_host == undefined) {
return "127.0.0.1";
}
@@ -46,7 +52,7 @@ function getHost() {
function getPort() {
proxy_port = document.getElementById("port").value;
console.log("Got i2p proxy port:", proxy_port);
console.log("(options)Got i2p proxy port:", proxy_port);
if (proxy_port == undefined) {
return "4444";
}
@@ -55,7 +61,7 @@ function getPort() {
function getControlHost() {
control_host = document.getElementById("controlhost").value;
console.log("Got i2p control host:", control_host);
console.log("(options)Got i2p control host:", control_host);
if (control_host == undefined) {
return "127.0.0.1";
}
@@ -64,7 +70,7 @@ function getControlHost() {
function getControlPort() {
control_port = document.getElementById("controlport").value;
console.log("Got i2p control port:", control_port);
console.log("(options)Got i2p control port:", control_port);
if (control_port == undefined) {
return "4444";
}
@@ -76,142 +82,94 @@ function checkStoredSettings(storedSettings) {
let defaultSettings = {};
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
console.log("proxy", "'" + host + "'", ":", port);
if (!storedSettings.proxy_scheme) {
if (port != 7644) {
port = undefined;
}
console.log("(options)proxy", "'" + host + "'", ":", port);
if (!storedSettings["proxy_scheme"])
defaultSettings["proxy_scheme"] = "http";
}
if (!storedSettings.proxy_host) {
if (host == "") {
defaultSettings["proxy_host"] = "127.0.0.1";
} else {
defaultSettings["proxy_host"] = host;
}
else defaultSettings["proxy_scheme"] = storedSettings["proxy_scheme"];
if (!storedSettings["proxy_host"]) {
if (host == "") defaultSettings["proxy_host"] = "127.0.0.1";
else defaultSettings["proxy_host"] = host;
} else {
if (host != "") {
defaultSettings["proxy_host"] = host;
} else {
defaultSettings["proxy_host"] = storedSettings.proxy_host;
}
defaultSettings["proxy_host"] = storedSettings["proxy_host"];
}
if (!storedSettings.proxy_port) {
if (port == undefined) {
defaultSettings["proxy_port"] = 4444;
} else {
defaultSettings["proxy_port"] = port;
}
if (!storedSettings["proxy_port"]) {
if (port == undefined) defaultSettings["proxy_port"] = 4444;
else if (port == 7644) defaultSettings["proxy_port"] = port;
else defaultSettings["proxy_port"] = 4444;
} else {
if (port != undefined) {
defaultSettings["proxy_port"] = port;
} else {
defaultSettings["proxy_port"] = storedSettings.proxy_port;
}
defaultSettings["proxy_port"] = storedSettings.proxy_port;
}
if (!storedSettings.control_host) {
if (host == "") {
defaultSettings["control_host"] = "127.0.0.1";
} else {
defaultSettings["control_host"] = host;
}
if (!storedSettings["control_host"]) {
if (host == "") defaultSettings["control_host"] = "127.0.0.1";
else defaultSettings["control_host"] = host;
} else {
if (host != "") {
defaultSettings["control_host"] = host;
} else {
defaultSettings["control_host"] = storedSettings.control_host;
}
defaultSettings["control_host"] = storedSettings.control_host;
}
if (!storedSettings.control_port) {
if (port == undefined) {
defaultSettings["control_port"] = 4444;
} else {
defaultSettings["control_port"] = port;
}
if (!storedSettings["control_port"]) {
defaultSettings["control_port"] = 7657;
} else {
if (port != undefined) {
defaultSettings["control_port"] = port;
} else {
defaultSettings["control_port"] = storedSettings.control_port;
}
defaultSettings["control_port"] = storedSettings.control_port;
}
console.log("(browserinfo) NATIVE PROXYSETTINGS", info.value);
console.log("(options)(browserinfo) NATIVE PROXYSETTINGS", info.value);
console.log(
"(options)",
defaultSettings["proxy_sheme"],
defaultSettings["proxy_host"],
defaultSettings["proxy_port"],
defaultSettings["control_host"],
defaultSettings["control_port"]
);
chrome.storage.local.set(defaultSettings);
return defaultSettings;
}
var gettingInfo = browser.proxy.settings.get({});
gettingInfo.then(gotProxyInfo);
return gettingInfo.then(gotProxyInfo);
}
function checkAndroidStoredSettings(storedSettings) {
let defaultSettings = {};
let host = "";
let port = "";
console.log("proxy", "'" + host + "'", ":", port);
if (!storedSettings.proxy_scheme) {
defaultSettings["proxy_scheme"] = "http";
}
if (!storedSettings.proxy_host) {
if (host == "") {
defaultSettings["proxy_host"] = "127.0.0.1";
} else {
defaultSettings["proxy_host"] = host;
}
if (!storedSettings["proxy_scheme"]) defaultSettings["proxy_scheme"] = "http";
else defaultSettings["proxy_scheme"] = storedSettings["proxy_scheme"];
if (!storedSettings["proxy_host"]) {
if (host == "") defaultSettings["proxy_host"] = "127.0.0.1";
else defaultSettings["proxy_host"] = host;
} else {
if (host != "") {
defaultSettings["proxy_host"] = host;
} else {
defaultSettings["proxy_host"] = storedSettings.proxy_host;
}
defaultSettings["proxy_host"] = storedSettings["proxy_host"];
}
if (!storedSettings.proxy_port) {
if (port == undefined) {
defaultSettings["proxy_port"] = 4444;
} else {
defaultSettings["proxy_port"] = port;
}
if (!storedSettings["proxy_port"]) {
if (port == undefined) defaultSettings["proxy_port"] = 4444;
else if (port == 7644) defaultSettings["proxy_port"] = port;
else defaultSettings["proxy_port"] = 4444;
} else {
if (port != undefined) {
defaultSettings["proxy_port"] = port;
} else {
defaultSettings["proxy_port"] = storedSettings.proxy_port;
}
defaultSettings["proxy_port"] = storedSettings.proxy_port;
}
if (!storedSettings.control_host) {
if (host == "") {
defaultSettings["control_host"] = "127.0.0.1";
} else {
defaultSettings["control_host"] = host;
}
if (!storedSettings["control_host"]) {
if (host == "") defaultSettings["control_host"] = "127.0.0.1";
else defaultSettings["control_host"] = host;
} else {
if (host != "") {
defaultSettings["control_host"] = host;
} else {
defaultSettings["control_host"] = storedSettings.control_host;
}
defaultSettings["control_host"] = storedSettings.control_host;
}
if (!storedSettings.control_port) {
if (port == undefined) {
defaultSettings["control_port"] = 4444;
} else {
defaultSettings["control_port"] = port;
}
if (!storedSettings["control_port"]) {
defaultSettings["control_port"] = 7657;
} else {
if (port != undefined) {
defaultSettings["control_port"] = port;
} else {
defaultSettings["control_port"] = storedSettings.control_port;
}
defaultSettings["control_port"] = storedSettings.control_port;
}
console.log("(options)(browserinfo) NATIVE PROXYSETTINGS", info.value);
console.log(
"(options)",
defaultSettings["proxy_scheme"],
defaultSettings["proxy_host"],
defaultSettings["proxy_port"],
defaultSettings["control_host"],
defaultSettings["control_port"]
);
chrome.storage.local.set(defaultSettings);
return defaultSettings;
}
function onError(e) {
@@ -231,36 +189,37 @@ function storeSettings() {
control_host,
control_port
});
console.log("storing proxy scheme:", proxy_scheme);
console.log("storing proxy host:", proxy_host);
console.log("storing proxy port:", proxy_port);
console.log("storing control host:", control_host);
console.log("storing control port:", control_port);
console.log("(options)storing proxy scheme:", proxy_scheme);
console.log("(options)storing proxy host:", proxy_host);
console.log("(options)storing proxy port:", proxy_port);
console.log("(options)storing control host:", control_host);
console.log("(options)storing control port:", control_port);
}
function updateUI(restoredSettings) {
const selectList = document.querySelector("#proxy_scheme");
selectList.value = restoredSettings.proxy_scheme;
console.log("showing proxy scheme:", selectList.value);
console.log("(options)showing proxy scheme:", selectList.value);
const hostitem = document.getElementById("host");
hostitem.value = restoredSettings.proxy_host;
console.log("showing proxy host:", hostitem.value);
console.log("(options)showing proxy host:", hostitem.value);
const portitem = document.getElementById("port");
portitem.value = restoredSettings.proxy_port;
console.log("showing proxy port:", portitem.value);
console.log("(options)showing proxy port:", portitem.value);
const controlhostitem = document.getElementById("controlhost");
controlhostitem.value = restoredSettings.control_host;
console.log("showing control host:", controlhostitem.value);
console.log("(options)showing control host:", controlhostitem.value);
const controlportitem = document.getElementById("controlport");
controlportitem.value = restoredSettings.control_port;
console.log("showing control port:", controlportitem.value);
console.log("(options)showing control port:", controlportitem.value);
SetHostText();
SetPortText();
SetPortHelpText();
SetControlHostText();
SetControlPortText();
SetControlHelpText();
@@ -274,8 +233,8 @@ var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os != "android") {
chrome.storage.local.get(function(got) {
checkStoredSettings(got);
updateUI(got);
let settings = checkStoredSettings(got);
settings.then(updateUI);
});
} else {
chrome.storage.local.get(function(got) {
@@ -287,5 +246,3 @@ gettingInfo.then(got => {
const saveButton = document.querySelector("#save-button");
saveButton.addEventListener("click", storeSettings);
//EXPERIMENTAL: Open in I2P Tab

View File

@@ -1,5 +1,12 @@
var titlepref = chrome.i18n.getMessage("titlePreface");
var proxy_scheme = "HTTP";
var proxy_host = "127.0.0.1";
var proxy_port = "4444";
var control_host = "127.0.0.1";
var control_port = "7657";
var disable_history = false;
function onSet(result) {
if (result) {
console.log("->: Value was updated");

View File

@@ -166,13 +166,6 @@ var handleContextProxyRequest = async function(requestDetails) {
}
};
var proxy_scheme = "HTTP";
var proxy_host = "127.0.0.1";
var proxy_port = "4444";
var control_host = "127.0.0.1";
var control_port = "7657";
var disable_history = false;
function SetupSettings() {
console.log("Initialising Settings");
function onSetupError() {
@@ -180,12 +173,10 @@ function SetupSettings() {
}
//
function checkSchemeStoredSettings(storedSettings) {
if (storedSettings.proxy_scheme === undefined) {
proxy_scheme = "http";
storedSettings.proxy_scheme = proxy_scheme;
} else {
proxy_scheme = storedSettings.proxy_scheme;
}
if (storedSettings.proxy_scheme == undefined)
storedSettings.proxy_scheme = "http";
else proxy_scheme = storedSettings.proxy_scheme;
console.log("Initialising Proxy Scheme", storedSettings.proxy_scheme);
setupProxy();
}
@@ -194,12 +185,10 @@ function SetupSettings() {
//
function checkHostStoredSettings(storedSettings) {
if (storedSettings.proxy_host == undefined) {
proxy_host = "127.0.0.1";
storedSettings.proxy_host = proxy_host;
} else {
proxy_host = storedSettings.proxy_host;
}
if (storedSettings.proxy_host == undefined)
storedSettings.proxy_host = "127.0.0.1";
else proxy_host = storedSettings.proxy_host;
console.log("Initialising Host", storedSettings.proxy_host);
setupProxy();
}
@@ -208,12 +197,10 @@ function SetupSettings() {
//
function checkPortStoredSettings(storedSettings) {
if (storedSettings.proxy_port == undefined) {
proxy_port = "4444";
storedSettings.proxy_port = proxy_port;
} else {
proxy_port = storedSettings.proxy_port;
}
if (storedSettings.proxy_port == undefined)
storedSettings.proxy_port = "4444";
else proxy_port = storedSettings.proxy_port;
console.log("Initialising Port", storedSettings.proxy_port);
setupProxy();
}
@@ -222,12 +209,10 @@ function SetupSettings() {
//
function checkControlHostStoredSettings(storedSettings) {
if (storedSettings.control_host == undefined) {
control_host = "127.0.0.1";
storedSettings.control_host = control_host;
} else {
control_host = storedSettings.control_host;
}
if (storedSettings.control_host == undefined)
storedSettings.control_host = "127.0.0.1";
else control_host = storedSettings.control_host;
console.log("Initialising Control Host", storedSettings.control_host);
setupProxy();
}
@@ -241,12 +226,10 @@ function SetupSettings() {
//
function checkControlPortStoredSettings(storedSettings) {
if (storedSettings.control_port == undefined) {
let new_control_port = "7657";
storedSettings.control_port = new_control_port;
} else {
let control_port = storedSettings.control_port;
}
if (storedSettings.control_port == undefined)
storedSettings.control_port = "7657";
else control_port = storedSettings.control_port;
console.log("Initialising Control Port", storedSettings.control_port);
setupProxy();
}
@@ -260,12 +243,10 @@ function SetupSettings() {
//
function checkHistoryStoredSettings(storedSettings) {
if (storedSettings.disable_history == undefined) {
disable_history = false;
storedSettings.disable_history = disable_history;
} else {
disable_history = storedSettings.disable_history;
}
if (storedSettings.disable_history == undefined)
storedSettings.disable_history = false;
else disable_history = storedSettings.disable_history;
console.log(
"Initialising Disabled History",
storedSettings.disable_history
@@ -348,25 +329,21 @@ function update() {
function updateFromStorage() {
console.log("updating settings from storage");
chrome.storage.local.get(function() {
SetupSettings();
update();
setupProxy();
});
var gettingInfo = browser.runtime.getPlatformInfo();
gettingInfo.then(got => {
if (got.os == "android") {
chrome.storage.local.get(function() {
SetupSettings();
update();
setupProxy();
});
} else {
if (got.os != "android") {
browser.windows.getAll().then(wins => wins.forEach(themeWindow));
chrome.storage.local.get(function() {
SetupSettings();
update();
setupProxy();
});
}
});
}
updateFromStorage();
browser.storage.onChanged.addListener(updateFromStorage);
SetupSettings();
setupProxy();