diff --git a/options/options.js b/options/options.js index 17adf0b..7f40ea7 100644 --- a/options/options.js +++ b/options/options.js @@ -1,3 +1,86 @@ + +function isFirefox() { + testPlain = navigator.userAgent.indexOf('Firefox') !== -1; + if (testPlain) { + return testPlain + } + testTorBrowser = navigator.userAgent.indexOf('Tor') !== -1; + if (testTorBrowser) { + return testTorBrowser + } + return false +} + +function setupProxy() { + + 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()) { + 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: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + proxyForFtp: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + proxyForHttps: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + fallbackProxy: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + } + } + }; + chrome.proxy.settings.set( + {value: config, scope: 'regular'}, + function() {}); + console.log("i2p settings created for Chromium") + } + +} + + /* Store the currently selected settings using browser.storage.local. */ @@ -38,6 +121,7 @@ function storeSettings() { proxy_host, proxy_port, }); + setupProxy() } /* @@ -74,3 +158,4 @@ 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 bcef000..51e3eca 100644 --- a/proxy.js +++ b/proxy.js @@ -16,67 +16,73 @@ 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 +function setupProxy() { -var defaultSettings = { - proxy_scheme: proxy_scheme, - proxy_value: [proxy_host, proxy_port] -}; + let proxy_scheme = "http" + let proxy_host = "127.0.0.1" + let proxy_port = 4444 -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()) { - 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: proxy_scheme, - host: proxy_host, - port: proxy_port - }, - proxyForFtp: { - scheme: proxy_scheme, - host: proxy_host, - port: proxy_port - }, - proxyForHttps: { - scheme: proxy_scheme, - host: proxy_host, - port: proxy_port - }, - fallbackProxy: { - scheme: proxy_scheme, - host: proxy_host, - port: proxy_port - } - } + var defaultSettings = { + proxy_scheme: proxy_scheme, + proxy_value: [proxy_host, proxy_port] }; - chrome.proxy.settings.set( - {value: config, scope: 'regular'}, - function() {}); - console.log("i2p settings created for Chromium") + + 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()) { + 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: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + proxyForFtp: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + proxyForHttps: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + }, + fallbackProxy: { + scheme: proxy_scheme, + host: proxy_host, + port: proxy_port + } + } + }; + chrome.proxy.settings.set( + {value: config, scope: 'regular'}, + function() {}); + console.log("i2p settings created for Chromium") + } + } + +setupProxy()