2019-02-07 17:25:06 -05:00
|
|
|
|
2019-02-19 14:56:55 -05:00
|
|
|
var hosttext = browser.i18n.getMessage("hostText");
|
|
|
|
var porttext = browser.i18n.getMessage("portText");
|
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
function getScheme() {
|
|
|
|
const proxy_scheme = document.querySelector("#proxy_scheme");
|
|
|
|
console.log("Got i2p proxy scheme:", proxy_scheme.value);
|
|
|
|
return proxy_scheme.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getHost() {
|
|
|
|
proxy_host = document.getElementById("host").value
|
|
|
|
console.log("Got i2p proxy host:", proxy_host);
|
|
|
|
if (proxy_host == undefined){
|
|
|
|
return "127.0.0.1"
|
|
|
|
}
|
|
|
|
return proxy_host;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPort() {
|
|
|
|
proxy_port = document.getElementById("port").value
|
|
|
|
console.log("Got i2p proxy port:", proxy_port);
|
|
|
|
if (proxy_port == undefined){
|
|
|
|
return 4444
|
|
|
|
}
|
|
|
|
return proxy_port;
|
|
|
|
}
|
|
|
|
|
2019-02-07 17:25:06 -05:00
|
|
|
function isFirefox() {
|
|
|
|
testPlain = navigator.userAgent.indexOf('Firefox') !== -1;
|
|
|
|
if (testPlain) {
|
|
|
|
return testPlain
|
|
|
|
}
|
|
|
|
testTorBrowser = navigator.userAgent.indexOf('Tor') !== -1;
|
|
|
|
if (testTorBrowser) {
|
|
|
|
return testTorBrowser
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
function checkStoredSettings(storedSettings) {
|
|
|
|
let defaultSettings = {};
|
|
|
|
if (!storedSettings.proxy_scheme){
|
|
|
|
defaultSettings["proxy_scheme"] = "http"
|
2019-02-07 17:25:06 -05:00
|
|
|
}
|
2019-02-07 20:14:57 -05:00
|
|
|
if (!storedSettings.proxy_host) {
|
|
|
|
defaultSettings["proxy_host"] = "127.0.0.1"
|
|
|
|
}
|
|
|
|
if (!storedSettings.proxy_port) {
|
|
|
|
defaultSettings["proxy_port"] = 4444
|
2019-02-07 17:25:06 -05:00
|
|
|
}
|
2019-02-07 20:14:57 -05:00
|
|
|
browser.storage.local.set(defaultSettings);
|
|
|
|
}
|
2019-02-07 17:25:06 -05:00
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
function onError(e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2019-02-07 17:25:06 -05:00
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
function setupProxy() {
|
2019-02-07 17:25:06 -05:00
|
|
|
if (isFirefox()) {
|
2019-02-07 20:14:57 -05:00
|
|
|
if (getScheme() == "http") {
|
2019-02-07 17:25:06 -05:00
|
|
|
var proxySettings = {
|
|
|
|
proxyType: "manual",
|
2019-02-07 20:14:57 -05:00
|
|
|
http: getHost()+":"+getPort(),
|
2019-02-07 17:25:06 -05:00
|
|
|
passthrough: "",
|
|
|
|
httpProxyAll: true
|
|
|
|
};
|
|
|
|
browser.proxy.settings.set({value:proxySettings});
|
|
|
|
console.log("i2p settings created for Firefox")
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
var config = {
|
|
|
|
mode: "fixed_servers",
|
|
|
|
rules: {
|
|
|
|
proxyForHttp: {
|
2019-02-07 20:14:57 -05:00
|
|
|
scheme: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
2019-02-07 17:25:06 -05:00
|
|
|
},
|
|
|
|
proxyForFtp: {
|
2019-02-07 20:14:57 -05:00
|
|
|
scheme: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
2019-02-07 17:25:06 -05:00
|
|
|
},
|
|
|
|
proxyForHttps: {
|
2019-02-07 20:14:57 -05:00
|
|
|
scheme: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
2019-02-07 17:25:06 -05:00
|
|
|
},
|
|
|
|
fallbackProxy: {
|
2019-02-07 20:14:57 -05:00
|
|
|
scheme: getScheme(),
|
|
|
|
host: getHost(),
|
|
|
|
port: getPort()
|
2019-02-07 17:25:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
chrome.proxy.settings.set(
|
|
|
|
{value: config, scope: 'regular'},
|
|
|
|
function() {});
|
|
|
|
console.log("i2p settings created for Chromium")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 17:09:31 -05:00
|
|
|
function storeSettings() {
|
2019-02-07 20:14:57 -05:00
|
|
|
let proxy_scheme = getScheme()
|
|
|
|
let proxy_host = getHost()
|
|
|
|
let proxy_port = getPort()
|
|
|
|
browser.storage.local.set({
|
|
|
|
proxy_scheme,
|
|
|
|
proxy_host,
|
|
|
|
proxy_port,
|
|
|
|
});
|
|
|
|
console.log("storing proxy host:", proxy_scheme)
|
|
|
|
console.log("storing proxy host:", proxy_host)
|
|
|
|
console.log("storing proxy port:", proxy_port)
|
|
|
|
setupProxy()
|
2019-02-07 17:09:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateUI(restoredSettings) {
|
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
const selectList = document.querySelector("#proxy_scheme")
|
|
|
|
selectList.value = restoredSettings.proxy_scheme
|
|
|
|
console.log("showing proxy scheme:", selectList.value)
|
|
|
|
|
|
|
|
const hostitem = document.getElementById("host")
|
|
|
|
hostitem.value = restoredSettings.proxy_host.getAttribute("value")
|
|
|
|
console.log("showing proxy host:", hostitem.value)
|
2019-02-19 14:56:55 -05:00
|
|
|
var hostid = document.getElementById('hostText');
|
|
|
|
var hostlabel = usersec.getElementsByTagName('label')[0];
|
|
|
|
hostlabel.innerHTML = hosttext;
|
2019-02-07 20:14:57 -05:00
|
|
|
|
|
|
|
const portitem = document.getElementById("port")
|
|
|
|
portitem.value = restoredSettings.proxy_port.getAttribute("value")
|
|
|
|
console.log("showing proxy port:", portitem.value)
|
2019-02-19 14:56:55 -05:00
|
|
|
var portid = document.getElementById('portText');
|
|
|
|
var portlabel = usersec.getElementsByTagName('label')[0];
|
|
|
|
portlabel.innerHTML = porttext;
|
2019-02-07 20:14:57 -05:00
|
|
|
|
2019-02-07 17:09:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function onError(e) {
|
2019-02-07 20:14:57 -05:00
|
|
|
console.error(e);
|
2019-02-07 17:09:31 -05:00
|
|
|
}
|
|
|
|
|
2019-02-07 20:14:57 -05:00
|
|
|
const assureStoredSettings = browser.storage.local.get();
|
|
|
|
assureStoredSettings.then(checkStoredSettings, onError);
|
|
|
|
|
2019-02-07 17:09:31 -05:00
|
|
|
const gettingStoredSettings = browser.storage.local.get();
|
|
|
|
gettingStoredSettings.then(updateUI, onError);
|
|
|
|
|
|
|
|
const saveButton = document.querySelector("#save-button");
|
|
|
|
saveButton.addEventListener("click", storeSettings);
|