Files
I2P_in_Private_Browsing_Mod…/options/options.js

462 lines
16 KiB
JavaScript
Raw Normal View History

function SetBookButton() {
2020-12-03 12:20:43 -05:00
// var bmid = document.getElementById("bookmark");
//bmid.textContent = chrome.i18n.getMessage("bookmarkButton");
}
function SetHostText() {
2022-10-24 19:57:51 -04:00
var hostid = document.getElementById("hostText");
hostid.textContent = chrome.i18n.getMessage("hostText");
2019-03-13 23:32:16 -04:00
}
function SetPortText() {
2022-10-24 19:57:51 -04:00
var portid = document.getElementById("portText");
portid.textContent = chrome.i18n.getMessage("portText");
2019-03-13 23:32:16 -04:00
}
function SetPortHelpText() {
2022-10-24 19:57:51 -04:00
var portid = document.getElementById("proxyHelpText");
portid.textContent = chrome.i18n.getMessage("proxyHelpText");
}
function SetControlHostText() {
2022-10-24 19:57:51 -04:00
var controlhostid = document.getElementById("controlHostText");
controlhostid.textContent = chrome.i18n.getMessage("controlHostText");
2019-03-13 23:32:16 -04:00
}
2019-06-17 19:17:11 -04:00
function SetControlPortText() {
2022-10-24 19:57:51 -04:00
var controlportid = document.getElementById("controlPortText");
controlportid.textContent = chrome.i18n.getMessage("controlPortText");
2019-03-13 23:32:16 -04:00
}
function SetControlHelpText() {
2022-10-24 19:57:51 -04:00
var portid = document.getElementById("controlHelpText");
portid.textContent = chrome.i18n.getMessage("controlHelpText");
2019-03-13 23:32:16 -04:00
}
function getBookmarksCreated() {
2022-10-24 19:57:51 -04:00
bookmarks_state = document.getElementById("bookmarks");
console.log("(options)Got i2p bookmarks state:", bookmarks_state);
if (bookmarks_state == undefined) {
return false;
}
2022-10-24 19:57:51 -04:00
if (bookmarks_state.value == "false") {
2020-12-03 12:20:43 -05:00
return false;
}
2022-10-24 19:57:51 -04:00
if (bookmarks_state.value == "true") {
2020-12-03 12:20:43 -05:00
return true;
}
return false;
}
2019-02-07 20:14:57 -05:00
function getScheme() {
2022-10-24 19:57:51 -04:00
const proxy_scheme = document.querySelector("#proxy_scheme");
console.log("(options)Got i2p proxy scheme:", proxy_scheme.value);
if (proxy_scheme.value == "HTTP") {
return "http";
}
2022-10-24 19:57:51 -04:00
if (proxy_scheme.value == "SOCKS") {
return "socks";
}
2022-10-24 19:57:51 -04:00
if (proxy_scheme.value == "http") return "http";
if (proxy_scheme.value == "socks") return "socks";
else return "http";
2019-02-07 20:14:57 -05:00
}
function getHost() {
2022-10-24 19:57:51 -04:00
proxy_host = document.getElementById("host").value;
console.log("(options)Got i2p proxy host:", proxy_host);
if (proxy_host == undefined) {
2022-10-24 19:57:51 -04:00
return "127.0.0.1";
}
return proxy_host;
2019-02-07 20:14:57 -05:00
}
function getPort() {
2022-10-24 19:57:51 -04:00
proxy_port = document.getElementById("port").value;
console.log("(options)Got i2p proxy port:", proxy_port);
if (proxy_port == undefined) {
2022-10-24 19:57:51 -04:00
return "4444";
}
return proxy_port;
2019-02-07 20:14:57 -05:00
}
2019-05-02 17:31:04 -04:00
2019-02-21 22:51:59 -05:00
function getControlHost() {
2022-10-24 19:57:51 -04:00
control_host = document.getElementById("controlhost").value;
console.log("(options)Got i2p control host:", control_host);
if (control_host == undefined) {
2022-10-24 19:57:51 -04:00
return "127.0.0.1";
}
return control_host;
2019-02-21 22:51:59 -05:00
}
function getControlPort() {
2022-10-24 19:57:51 -04:00
control_port = document.getElementById("controlport").value;
console.log("(options)Got i2p control port:", control_port);
if (control_port == undefined) {
2022-10-24 19:57:51 -04:00
return "4444";
}
return control_port;
2019-02-21 22:51:59 -05:00
}
2019-05-02 17:31:04 -04:00
2020-01-14 21:40:02 -05:00
function getRPCHost() {
2022-10-24 19:57:51 -04:00
rpc_host = document.getElementById("rpchost").value;
console.log("(options)Got i2pcontrol rpc host:", rpc_host);
2020-01-14 21:40:02 -05:00
if (rpc_host == undefined) {
2022-10-24 19:57:51 -04:00
return "127.0.0.1";
2020-01-14 21:40:02 -05:00
}
return rpc_host;
}
function getRPCPort() {
2022-10-24 19:57:51 -04:00
rpc_port = document.getElementById("rpcport").value;
console.log("(options)Got i2pcontrol rpc port:", rpc_port);
2020-01-14 21:40:02 -05:00
if (rpc_port == undefined) {
2022-10-24 19:57:51 -04:00
return "7657";
2020-01-14 21:40:02 -05:00
}
return rpc_port;
}
function getRPCPath() {
2022-10-24 19:57:51 -04:00
rpc_path = document.getElementById("rpcpath").value;
console.log("(options)Got i2pcontrol rpc path:", rpc_path);
2020-01-14 21:40:02 -05:00
if (rpc_path == undefined) {
2022-10-24 19:57:51 -04:00
return "jsonrpc";
2020-01-14 21:40:02 -05:00
}
return rpc_path;
}
function getRPCPass() {
2022-10-24 19:57:51 -04:00
rpc_pass = document.getElementById("rpcpass").value;
console.log("(options)Got i2pcontrol rpc password:");
2020-01-14 21:40:02 -05:00
if (rpc_pass == undefined) {
2022-10-24 19:57:51 -04:00
return "itoopie";
2020-01-14 21:40:02 -05:00
}
return rpc_pass;
}
function getBTRPCHost() {
2022-10-24 19:57:51 -04:00
bt_rpc_host = document.getElementById("btrpchost").value;
console.log("(options)Got torrent rpc host:", bt_rpc_host);
2020-01-14 21:40:02 -05:00
if (bt_rpc_host == undefined) {
2022-10-24 19:57:51 -04:00
return "127.0.0.1";
2020-01-14 21:40:02 -05:00
}
return bt_rpc_host;
}
function getBTRPCPort() {
2022-10-24 19:57:51 -04:00
bt_rpc_port = document.getElementById("btrpcport").value;
console.log("(options)Got torrent rpc port:", bt_rpc_port);
2020-01-14 21:40:02 -05:00
if (bt_rpc_port == undefined) {
2022-10-24 19:57:51 -04:00
return "7657";
2020-01-14 21:40:02 -05:00
}
return bt_rpc_port;
}
function getBTRPCPath() {
2022-10-24 19:57:51 -04:00
bt_rpc_path = document.getElementById("btrpcpath").value;
console.log("(options)Got torrent rpc path:", bt_rpc_path);
2020-01-14 21:40:02 -05:00
if (bt_rpc_path == undefined) {
2022-10-24 19:57:51 -04:00
return "transmission/rpc";
2020-01-14 21:40:02 -05:00
}
return bt_rpc_path;
}
function getBTRPCPass() {
2022-10-24 19:57:51 -04:00
bt_rpc_pass = document.getElementById("btrpcpass").value;
console.log("(options)Got torrent rpc password:");
2020-01-14 21:40:02 -05:00
if (bt_rpc_pass == undefined) {
2022-10-24 19:57:51 -04:00
return "itoopie";
2020-01-14 21:40:02 -05:00
}
return bt_rpc_pass;
}
2019-02-07 20:14:57 -05:00
function checkStoredSettings(storedSettings) {
function gotProxyInfo(info) {
let defaultSettings = {};
2022-10-24 19:57:51 -04:00
let host = info.value.http.split(":")[0];
let port = info.value.http.split(":")[1];
if (port != 7644) {
port = undefined;
}
2022-10-24 19:57:51 -04:00
console.log("(options)proxy", "'" + host + "'", ":", port);
if (!storedSettings["bookmarks_state"])
defaultSettings["bookmarks_state"] = false;
else defaultSettings["bookmarks_state"] = storedSettings["bookmarks_state"];
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 defaultSettings["proxy_host"] = storedSettings["proxy_host"];
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 defaultSettings["proxy_port"] = storedSettings.proxy_port;
if (!storedSettings["control_host"]) {
if (host == "") defaultSettings["control_host"] = "127.0.0.1";
else defaultSettings["control_host"] = host;
} else defaultSettings["control_host"] = storedSettings.control_host;
if (!storedSettings["control_port"]) {
defaultSettings["control_port"] = 7657;
} else defaultSettings["control_port"] = storedSettings.control_port;
if (!storedSettings["rpc_host"]) {
if (host == "") defaultSettings["rpc_host"] = "127.0.0.1";
else defaultSettings["rpc_host"] = host;
} else defaultSettings["rpc_host"] = storedSettings.rpc_host;
if (!storedSettings["rpc_port"]) {
defaultSettings["rpc_port"] = 7657;
} else defaultSettings["rpc_port"] = storedSettings.rpc_port;
if (!storedSettings["rpc_path"]) {
defaultSettings["rpc_path"] = "jsonrpc";
} else defaultSettings["rpc_path"] = storedSettings.rpc_path;
if (!storedSettings["rpc_pass"]) {
defaultSettings["rpc_pass"] = "itoopie";
} else defaultSettings["rpc_pass"] = storedSettings.rpc_pass;
if (!storedSettings["bt_rpc_host"]) {
if (host == "") defaultSettings["bt_rpc_host"] = "127.0.0.1";
else defaultSettings["bt_rpc_host"] = host;
} else defaultSettings["bt_rpc_host"] = storedSettings.bt_rpc_host;
if (!storedSettings["bt_rpc_port"]) {
defaultSettings["bt_rpc_port"] = 7657;
} else defaultSettings["bt_rpc_port"] = storedSettings.bt_rpc_port;
if (!storedSettings["bt_rpc_path"]) {
defaultSettings["bt_rpc_path"] = "transmission/";
} else defaultSettings["bt_rpc_path"] = storedSettings.bt_rpc_path;
if (!storedSettings["bt_rpc_pass"]) {
defaultSettings["bt_rpc_pass"] = "transmission";
} else defaultSettings["bt_rpc_pass"] = storedSettings.bt_rpc_pass;
console.log("(options)(browserinfo) NATIVE PROXYSETTINGS", info.value);
defaultSettings["base_url"] =
"http://" +
defaultSettings["bt_rpc_host"] +
":" +
defaultSettings["bt_rpc_port"] +
"/" +
defaultSettings["bt_rpc_path"];
console.log(
2022-10-24 19:57:51 -04:00
"(options)",
defaultSettings["proxy_scheme"],
defaultSettings["proxy_host"],
defaultSettings["proxy_port"],
defaultSettings["control_host"],
defaultSettings["control_port"],
defaultSettings["base_url"]
);
chrome.storage.local.set(defaultSettings);
return defaultSettings;
}
var gettingInfo = browser.proxy.settings.get({});
return gettingInfo.then(gotProxyInfo);
2019-02-07 20:14:57 -05:00
}
function checkAndroidStoredSettings(storedSettings) {
let defaultSettings = {};
2022-10-24 19:57:51 -04:00
let host = "";
let port = "";
if (!storedSettings["bookmarks_state"])
defaultSettings["bookmarks_state"] = false;
else defaultSettings["bookmarks_state"] = storedSettings["bookmarks_state"];
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 defaultSettings["proxy_host"] = storedSettings["proxy_host"];
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 defaultSettings["proxy_port"] = storedSettings.proxy_port;
if (!storedSettings["control_host"]) {
if (host == "") defaultSettings["control_host"] = "127.0.0.1";
else defaultSettings["control_host"] = host;
} else defaultSettings["control_host"] = storedSettings.control_host;
if (!storedSettings["control_port"]) {
defaultSettings["control_port"] = 7657;
} else defaultSettings["control_port"] = storedSettings.control_port;
if (!storedSettings["rpc_host"]) {
if (host == "") defaultSettings["rpc_host"] = "127.0.0.1";
else defaultSettings["rpc_host"] = host;
} else defaultSettings["rpc_host"] = storedSettings.rpc_host;
if (!storedSettings["rpc_port"]) {
defaultSettings["rpc_port"] = 7657;
} else defaultSettings["rpc_port"] = storedSettings.rpc_port;
if (!storedSettings["rpc_path"]) {
defaultSettings["rpc_path"] = "jsonrpc";
} else defaultSettings["rpc_path"] = storedSettings.rpc_path;
if (!storedSettings["rpc_pass"]) {
defaultSettings["rpc_pass"] = "itoopie";
} else defaultSettings["rpc_pass"] = storedSettings.rpc_pass;
if (!storedSettings["bt_rpc_host"]) {
if (host == "") defaultSettings["bt_rpc_host"] = "127.0.0.1";
else defaultSettings["bt_rpc_host"] = host;
} else defaultSettings["bt_rpc_host"] = storedSettings.bt_rpc_host;
if (!storedSettings["bt_rpc_port"]) {
defaultSettings["bt_rpc_port"] = 7657;
} else defaultSettings["bt_rpc_port"] = storedSettings.bt_rpc_port;
if (!storedSettings["bt_rpc_path"]) {
defaultSettings["bt_rpc_path"] = "transmission/rpc";
} else defaultSettings["bt_rpc_path"] = storedSettings.bt_rpc_path;
if (!storedSettings["bt_rpc_pass"]) {
defaultSettings["bt_rpc_pass"] = "transmission";
} else defaultSettings["bt_rpc_pass"] = storedSettings.bt_rpc_pass;
console.log("(options)(browserinfo) NATIVE PROXYSETTINGS", info.value);
console.log(
2022-10-24 19:57:51 -04:00
"(options)",
defaultSettings["proxy_scheme"],
defaultSettings["proxy_host"],
defaultSettings["proxy_port"],
defaultSettings["control_host"],
defaultSettings["control_port"]
);
chrome.storage.local.set(defaultSettings);
return defaultSettings;
}
2019-02-07 20:14:57 -05:00
function onError(e) {
console.error(e);
2019-02-07 20:14:57 -05:00
}
function storeSettings() {
let storableSettings = {};
2022-10-24 19:57:51 -04:00
storableSettings["bookmarks_state"] = getBookmarksCreated();
storableSettings["proxy_scheme"] = getScheme();
storableSettings["proxy_host"] = getHost();
storableSettings["proxy_port"] = getPort();
storableSettings["control_host"] = getControlHost();
storableSettings["control_port"] = getControlPort();
storableSettings["rpc_host"] = getRPCHost();
storableSettings["rpc_port"] = getRPCPort();
storableSettings["rpc_path"] = getRPCPath();
storableSettings["rpc_pass"] = getRPCPass();
storableSettings["bt_rpc_host"] = getBTRPCHost();
storableSettings["bt_rpc_port"] = getBTRPCPort();
storableSettings["bt_rpc_path"] = getBTRPCPath();
storableSettings["bt_rpc_pass"] = getBTRPCPass();
storableSettings["base_url"] =
"http://" + bt_rpc_host + ":" + bt_rpc_port + "/" + bt_rpc_path;
console.log("storing", storableSettings);
chrome.storage.local.set(storableSettings);
}
function updateUI(restoredSettings) {
2022-10-24 19:57:51 -04:00
const selectList = document.querySelector("#proxy_scheme");
if (selectList != undefined) selectList.value = restoredSettings.proxy_scheme;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing proxy scheme:", selectList.value);
2020-12-03 12:20:43 -05:00
console.log(restoredSettings);
2022-10-24 19:57:51 -04:00
const bms = document.getElementById("bookmarksState");
if (bms != undefined) bms.checked = restoredSettings.bookmarks_state;
2022-10-24 19:57:51 -04:00
const hostitem = document.getElementById("host");
if (hostitem != undefined) hostitem.value = restoredSettings.proxy_host;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing proxy host:", hostitem.value);
2019-02-19 15:08:05 -05:00
2022-10-24 19:57:51 -04:00
const portitem = document.getElementById("port");
if (portitem != undefined) portitem.value = restoredSettings.proxy_port;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing proxy port:", portitem.value);
2019-02-07 20:14:57 -05:00
2022-10-24 19:57:51 -04:00
const controlhostitem = document.getElementById("controlhost");
2020-01-14 21:40:02 -05:00
if (controlhostitem == undefined)
controlhostitem.value = restoredSettings.control_host;
//console.log("(options)showing control host:", controlhostitem.value);
2019-02-21 22:51:59 -05:00
2022-10-24 19:57:51 -04:00
const controlportitem = document.getElementById("controlport");
2020-01-14 21:40:02 -05:00
if (controlportitem == undefined)
controlportitem.value = restoredSettings.control_port;
//console.log("(options)showing control port:", controlportitem.value);
2022-10-24 19:57:51 -04:00
const rpchostitem = document.getElementById("rpchost");
if (rpchostitem != undefined) rpchostitem.value = restoredSettings.rpc_host;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing rpc host:", rpchostitem.value);
2022-10-24 19:57:51 -04:00
const rpcportitem = document.getElementById("rpcport");
if (rpcportitem != undefined) rpcportitem.value = restoredSettings.rpc_port;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing rpc port:", rpcportitem.value);
2022-10-24 19:57:51 -04:00
const rpcpathitem = document.getElementById("rpcpath");
if (rpcpathitem != undefined) rpcpathitem.value = restoredSettings.rpc_path;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing rpc path:", rpcpathitem.value);
2022-10-24 19:57:51 -04:00
const rpcpassitem = document.getElementById("rpcpass");
if (rpcpassitem != undefined) rpcpassitem.value = restoredSettings.rpc_pass;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing rpc pass:");
2022-10-24 19:57:51 -04:00
const btrpchostitem = document.getElementById("btrpchost");
if (btrpchostitem != undefined)
2021-01-31 01:07:14 -05:00
btrpchostitem.value = restoredSettings.bt_rpc_host;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing bt rpc host:", btrpchostitem.value);
2022-10-24 19:57:51 -04:00
const btrpcportitem = document.getElementById("btrpcport");
if (btrpcportitem != undefined)
2021-01-31 01:07:14 -05:00
btrpcportitem.value = restoredSettings.bt_rpc_port;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing rbt pc port:", rpcportitem.value);
2022-10-24 19:57:51 -04:00
const btrpcpathitem = document.getElementById("btrpcpath");
if (btrpcpathitem != undefined)
2021-01-31 01:07:14 -05:00
btrpcpathitem.value = restoredSettings.bt_rpc_path;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing bt rpc path:", btrpcpathitem.value);
2022-10-24 19:57:51 -04:00
const btrpcpassitem = document.getElementById("btrpcpass");
if (btrpcpassitem != undefined)
2021-01-31 01:07:14 -05:00
btrpcpassitem.value = restoredSettings.bt_rpc_pass;
2020-01-14 21:40:02 -05:00
//console.log("(options)showing bt rpc pass:");
2019-06-17 19:17:11 -04:00
2020-12-03 12:20:43 -05:00
SetBookButton();
2019-10-06 15:18:10 -04:00
SetHostText();
SetPortText();
SetPortHelpText();
2019-10-06 15:18:10 -04:00
SetControlHostText();
SetControlPortText();
SetControlHelpText();
}
function onError(e) {
console.error(e);
}
var gettingInfo = browser.runtime.getPlatformInfo();
2020-11-10 21:48:08 -05:00
gettingInfo.then((got) => {
2022-10-24 19:57:51 -04:00
if (got.os != "android") {
chrome.storage.local.get(function (got) {
let settings = checkStoredSettings(got);
settings.then(updateUI);
});
} else {
2022-10-24 19:57:51 -04:00
chrome.storage.local.get(function (got) {
checkAndroidStoredSettings(got);
updateUI(got);
});
}
2019-05-02 17:31:04 -04:00
});
2022-10-24 19:57:51 -04:00
const saveButton = document.querySelector("#save-button");
saveButton.addEventListener("click", storeSettings);