diff --git a/Makefile b/Makefile index 69ec99b..0d9edb5 100644 --- a/Makefile +++ b/Makefile @@ -20,3 +20,6 @@ uninstall: zip: zip -r -FS ../i2psetproxy.js.zip * + +clobber: + rm -f ../i2psetproxy.js.zip ../i2p_proxy*.xpi diff --git a/background.js b/background.js index 9bf2659..459f4f1 100644 --- a/background.js +++ b/background.js @@ -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" + } + }); + } } diff --git a/manifest.json b/manifest.json index 286808a..ea24948 100644 --- a/manifest.json +++ b/manifest.json @@ -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"] } diff --git a/options/options.css b/options/options.css new file mode 100644 index 0000000..f744774 --- /dev/null +++ b/options/options.css @@ -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; +} diff --git a/options/options.html b/options/options.html new file mode 100644 index 0000000..841009c --- /dev/null +++ b/options/options.html @@ -0,0 +1,32 @@ + + + + + + + + + +
+ Proxy Scheme: + +
+ +
+
Proxy Options
+ + +
+ + +
+ + + + + + + diff --git a/options/options.js b/options/options.js new file mode 100644 index 0000000..fffb2b7 --- /dev/null +++ b/options/options.js @@ -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); diff --git a/proxy.js b/proxy.js index 10d2332..bcef000 100644 --- a/proxy.js +++ b/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") }