commit 27a92ab03a1e296a4e73f6861b31931e4aeba221 Author: Arlo Breault arlolra@gmail.com Date: Sat Jul 6 16:40:03 2019 +0200
Close over init so that we can return if a feature isn't detected
I guess alternatively, just use an if/else block. --- proxy/init-badge.js | 124 +++++++++++++++++++++++++++------------------------ proxy/init-webext.js | 119 ++++++++++++++++++++++++------------------------ 2 files changed, 126 insertions(+), 117 deletions(-)
diff --git a/proxy/init-badge.js b/proxy/init-badge.js index 7e5277f..30c0218 100644 --- a/proxy/init-badge.js +++ b/proxy/init-badge.js @@ -2,72 +2,78 @@ Entry point. */
-if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) { - console.log('webrtc feature not detected. shutting down'); - return; -} +var snowflake, query, debug, silenceNotifications, log, dbg, init;
-var snowflake = null; +;(function() {
-var query = Query.parse(location); + if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) { + console.log('webrtc feature not detected. shutting down'); + return; + }
-var debug = Params.getBool(query, 'debug', false); + snowflake = null;
-var silenceNotifications = Params.getBool(query, 'silent', false); + query = Query.parse(location);
-// Log to both console and UI if applicable. -// Requires that the snowflake and UI objects are hooked up in order to -// log to console. -var log = function(msg) { - console.log('Snowflake: ' + msg); - return snowflake != null ? snowflake.ui.log(msg) : void 0; -}; + debug = Params.getBool(query, 'debug', false);
-var dbg = function(msg) { - if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) { - return log(msg); - } -}; + silenceNotifications = Params.getBool(query, 'silent', false);
-var init = function() { - var broker, config, ui; - config = new Config; - if ('off' !== query['ratelimit']) { - config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes); - } - ui = null; - if (document.getElementById('badge') !== null) { - ui = new BadgeUI(); - } else if (document.getElementById('status') !== null) { - ui = new DebugUI(); - } else { - ui = new UI(); - } - broker = new Broker(config.brokerUrl); - snowflake = new Snowflake(config, ui, broker); - log('== snowflake proxy =='); - if (Util.snowflakeIsDisabled(config.cookieName)) { - // Do not activate the proxy if any number of conditions are true. - log('Currently not active.'); - return; - } - // Otherwise, begin setting up WebRTC and acting as a proxy. - dbg('Contacting Broker at ' + broker.url); - snowflake.setRelayAddr(config.relayAddr); - return snowflake.beginWebRTC(); -}; + // Log to both console and UI if applicable. + // Requires that the snowflake and UI objects are hooked up in order to + // log to console. + log = function(msg) { + console.log('Snowflake: ' + msg); + return snowflake != null ? snowflake.ui.log(msg) : void 0; + };
-// Notification of closing tab with active proxy. -window.onbeforeunload = function() { - if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) { - return Snowflake.MESSAGE.CONFIRMATION; - } - return null; -}; + dbg = function(msg) { + if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) { + return log(msg); + } + }; + + init = function() { + var broker, config, ui; + config = new Config; + if ('off' !== query['ratelimit']) { + config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes); + } + ui = null; + if (document.getElementById('badge') !== null) { + ui = new BadgeUI(); + } else if (document.getElementById('status') !== null) { + ui = new DebugUI(); + } else { + ui = new UI(); + } + broker = new Broker(config.brokerUrl); + snowflake = new Snowflake(config, ui, broker); + log('== snowflake proxy =='); + if (Util.snowflakeIsDisabled(config.cookieName)) { + // Do not activate the proxy if any number of conditions are true. + log('Currently not active.'); + return; + } + // Otherwise, begin setting up WebRTC and acting as a proxy. + dbg('Contacting Broker at ' + broker.url); + snowflake.setRelayAddr(config.relayAddr); + return snowflake.beginWebRTC(); + }; + + // Notification of closing tab with active proxy. + window.onbeforeunload = function() { + if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) { + return Snowflake.MESSAGE.CONFIRMATION; + } + return null; + }; + + window.onunload = function() { + snowflake.disable(); + return null; + };
-window.onunload = function() { - snowflake.disable(); - return null; -}; + window.onload = init;
-window.onload = init; +}()); diff --git a/proxy/init-webext.js b/proxy/init-webext.js index 89072b8..3a2b120 100644 --- a/proxy/init-webext.js +++ b/proxy/init-webext.js @@ -2,73 +2,76 @@ Entry point. */
-var debug = false; +var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
-var snowflake = null; +;(function () {
-var config = null; + silenceNotifications = false; + debug = false; + snowflake = null; + config = null; + broker = null; + ui = null;
-var broker = null; + // Log to both console and UI if applicable. + // Requires that the snowflake and UI objects are hooked up in order to + // log to console. + log = function(msg) { + console.log('Snowflake: ' + msg); + return snowflake != null ? snowflake.ui.log(msg) : void 0; + };
-var ui = null; + dbg = function(msg) { + if (debug) { + return log(msg); + } + };
-// Log to both console and UI if applicable. -// Requires that the snowflake and UI objects are hooked up in order to -// log to console. -var log = function(msg) { - console.log('Snowflake: ' + msg); - return snowflake != null ? snowflake.ui.log(msg) : void 0; -}; - -var dbg = function(msg) { - if (debug) { - return log(msg); + if (!Util.featureDetect()) { + chrome.runtime.onConnect.addListener(function(port) { + return port.postMessage({ + missingFeature: true + }); + }); + return; } -};
-if (!Util.featureDetect()) { - chrome.runtime.onConnect.addListener(function(port) { - return port.postMessage({ - missingFeature: true - }); - }); - return; -} + init = function() { + config = new Config; + ui = new WebExtUI(); + broker = new Broker(config.brokerUrl); + snowflake = new Snowflake(config, ui, broker); + log('== snowflake proxy =='); + return ui.initToggle(); + };
-var init = function() { - config = new Config; - ui = new WebExtUI(); - broker = new Broker(config.brokerUrl); - snowflake = new Snowflake(config, ui, broker); - log('== snowflake proxy =='); - return ui.initToggle(); -}; + update = function() { + if (!ui.enabled) { + // Do not activate the proxy if any number of conditions are true. + snowflake.disable(); + log('Currently not active.'); + return; + } + // Otherwise, begin setting up WebRTC and acting as a proxy. + dbg('Contacting Broker at ' + broker.url); + log('Starting snowflake'); + snowflake.setRelayAddr(config.relayAddr); + return snowflake.beginWebRTC(); + };
-var update = function() { - if (!ui.enabled) { - // Do not activate the proxy if any number of conditions are true. - snowflake.disable(); - log('Currently not active.'); - return; - } - // Otherwise, begin setting up WebRTC and acting as a proxy. - dbg('Contacting Broker at ' + broker.url); - log('Starting snowflake'); - snowflake.setRelayAddr(config.relayAddr); - return snowflake.beginWebRTC(); -}; + // Notification of closing tab with active proxy. + window.onbeforeunload = function() { + if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) { + return Snowflake.MESSAGE.CONFIRMATION; + } + return null; + };
-// Notification of closing tab with active proxy. -window.onbeforeunload = function() { - if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) { - return Snowflake.MESSAGE.CONFIRMATION; - } - return null; -}; + window.onunload = function() { + snowflake.disable(); + return null; + };
-window.onunload = function() { - snowflake.disable(); - return null; -}; + window.onload = init;
-window.onload = init; +}());
tor-commits@lists.torproject.org