Add settings configuration, not using it yet
This commit is contained in:
3
Makefile
3
Makefile
@@ -20,3 +20,6 @@ uninstall:
|
||||
|
||||
zip:
|
||||
zip -r -FS ../i2psetproxy.js.zip *
|
||||
|
||||
clobber:
|
||||
rm -f ../i2psetproxy.js.zip ../i2p_proxy*.xpi
|
||||
|
||||
@@ -4,32 +4,32 @@ browser.windows.onCreated.addListener(themeWindow);
|
||||
browser.windows.getAll().then(wins => wins.forEach(themeWindow));
|
||||
|
||||
function themeWindow(window) {
|
||||
// Check if the window is in private browsing
|
||||
if (window.incognito) {
|
||||
browser.theme.update(window.id, {
|
||||
images: {
|
||||
headerURL: "",
|
||||
},
|
||||
colors: {
|
||||
accentcolor: "#A0A0DE",
|
||||
textcolor: "white",
|
||||
toolbar: "#A0A0DE",
|
||||
toolbar_text: "white"
|
||||
}
|
||||
});
|
||||
}
|
||||
// Reset to the default theme otherwise
|
||||
else {
|
||||
browser.theme.update(window.id, {
|
||||
images: {
|
||||
headerURL: "",
|
||||
},
|
||||
colors: {
|
||||
accentcolor: "#BFA0DE",
|
||||
textcolor: "white",
|
||||
toolbar: "#BFA0DE",
|
||||
toolbar_text: "white"
|
||||
}
|
||||
});
|
||||
}
|
||||
// Check if the window is in private browsing
|
||||
if (window.incognito) {
|
||||
browser.theme.update(window.id, {
|
||||
images: {
|
||||
headerURL: "",
|
||||
},
|
||||
colors: {
|
||||
accentcolor: "#A0A0DE",
|
||||
textcolor: "white",
|
||||
toolbar: "#A0A0DE",
|
||||
toolbar_text: "white"
|
||||
}
|
||||
});
|
||||
}
|
||||
// Reset to the default theme otherwise
|
||||
else {
|
||||
browser.theme.update(window.id, {
|
||||
images: {
|
||||
headerURL: "",
|
||||
},
|
||||
colors: {
|
||||
accentcolor: "#BFA0DE",
|
||||
textcolor: "white",
|
||||
toolbar: "#BFA0DE",
|
||||
toolbar_text: "white"
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,14 @@
|
||||
"strict_min_version": "60.0"
|
||||
}
|
||||
},
|
||||
"permissions": ["theme", "proxy", "privacy"],
|
||||
"permissions": ["theme", "proxy", "privacy", "storage"],
|
||||
"manifest_version": 2,
|
||||
"name": "I2P Proxy",
|
||||
"version": "1.11",
|
||||
"description": "Set up a browser to use the i2p http proxy automatically",
|
||||
"options_ui": {
|
||||
"page": "options/options.html"
|
||||
},
|
||||
"background": {
|
||||
"scripts": ["background.js", "proxy.js"]
|
||||
}
|
||||
|
||||
35
options/options.css
Normal file
35
options/options.css
Normal file
@@ -0,0 +1,35 @@
|
||||
body {
|
||||
width: 25em;
|
||||
font-family: "Open Sans Light", sans-serif;
|
||||
font-size: 0.9em;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
section.scheme-options {
|
||||
padding: 0.5em 0;
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
#clear-button {
|
||||
margin: 0 1.3em 1em 0;
|
||||
}
|
||||
|
||||
section.scheme-options input,
|
||||
section.scheme-options>select,
|
||||
#clear-button {
|
||||
float: right;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
padding: 0.2em 0;
|
||||
}
|
||||
|
||||
label:hover {
|
||||
background-color: #EAEFF2;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 1.2em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
32
options/options.html
Normal file
32
options/options.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="options.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<section class="scheme-options">
|
||||
<span class="title">Proxy Scheme:</span>
|
||||
<select id="proxy_scheme">
|
||||
<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>
|
||||
|
||||
<label>Host: <input type="text" value="127.0.0.1"/></label>
|
||||
<br>
|
||||
<label>Port: <input type="text" value="4444"/></label>
|
||||
|
||||
</section>
|
||||
|
||||
<input type="button" value="Save preferences" id="save-button"/>
|
||||
|
||||
<script src="options.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
60
options/options.js
Normal file
60
options/options.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Store the currently selected settings using browser.storage.local.
|
||||
*/
|
||||
function storeSettings() {
|
||||
|
||||
function getSince() {
|
||||
const proxy_scheme = document.querySelector("#proxy_scheme");
|
||||
return proxy_scheme.value;
|
||||
}
|
||||
|
||||
function getTypes() {
|
||||
let proxy_value = [];
|
||||
const textboxes = document.querySelectorAll(".proxy-options [type=text]");
|
||||
for (let item of textboxes) {
|
||||
if (item.checked) {
|
||||
proxy_value.push(item.getAttribute("value"));
|
||||
}
|
||||
}
|
||||
return proxy_value;
|
||||
}
|
||||
|
||||
const proxy_scheme = getSince();
|
||||
const proxy_value = getTypes();
|
||||
browser.storage.local.set({
|
||||
proxy_scheme,
|
||||
proxy_value
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Update the options UI with the settings values retrieved from storage,
|
||||
or the default settings if the stored settings are empty.
|
||||
*/
|
||||
function updateUI(restoredSettings) {
|
||||
const selectList = document.querySelector("#proxy_scheme");
|
||||
selectList.value = restoredSettings.proxy_scheme;
|
||||
|
||||
const textboxes = document.querySelectorAll(".proxy-options [type=text]");
|
||||
for (let item of textboxes) {
|
||||
if (restoredSettings.proxy_value.indexOf(item.getAttribute("value")) != -1) {
|
||||
item.value = restoredSettings.proxy_value.indexOf(item.getAttribute("value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onError(e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
/*
|
||||
On opening the options page, fetch stored settings and update the UI with them.
|
||||
*/
|
||||
const gettingStoredSettings = browser.storage.local.get();
|
||||
gettingStoredSettings.then(updateUI, onError);
|
||||
|
||||
/*
|
||||
On clicking the save button, save the currently selected settings.
|
||||
*/
|
||||
const saveButton = document.querySelector("#save-button");
|
||||
saveButton.addEventListener("click", storeSettings);
|
||||
68
proxy.js
68
proxy.js
@@ -16,43 +16,67 @@ browser.privacy.network.webRTCIPHandlingPolicy.set({value: "disable_non_proxied_
|
||||
|
||||
console.log("Preliminarily disabled WebRTC.")
|
||||
|
||||
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()) {
|
||||
var proxySettings = {
|
||||
proxyType: "manual",
|
||||
http: "http://127.0.0.1:4444",
|
||||
passthrough: "",
|
||||
httpProxyAll: true
|
||||
};
|
||||
browser.proxy.settings.set({value:proxySettings});
|
||||
console.log("i2p settings created for Firefox")
|
||||
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: "http",
|
||||
host: "127.0.0.1",
|
||||
port: 4444
|
||||
scheme: proxy_scheme,
|
||||
host: proxy_host,
|
||||
port: proxy_port
|
||||
},
|
||||
proxyForFtp: {
|
||||
scheme: "http",
|
||||
host: "127.0.0.1",
|
||||
port: 4444
|
||||
scheme: proxy_scheme,
|
||||
host: proxy_host,
|
||||
port: proxy_port
|
||||
},
|
||||
proxyForHttps: {
|
||||
scheme: "http",
|
||||
host: "127.0.0.1",
|
||||
port: 4444
|
||||
scheme: proxy_scheme,
|
||||
host: proxy_host,
|
||||
port: proxy_port
|
||||
},
|
||||
fallbackProxy: {
|
||||
scheme: "http",
|
||||
host: "127.0.0.1",
|
||||
port: 4444
|
||||
scheme: proxy_scheme,
|
||||
host: proxy_host,
|
||||
port: proxy_port
|
||||
}
|
||||
}
|
||||
};
|
||||
chrome.proxy.settings.set(
|
||||
{value: config, scope: 'regular'},
|
||||
function() {});
|
||||
{value: config, scope: 'regular'},
|
||||
function() {});
|
||||
console.log("i2p settings created for Chromium")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user