From 3cb3e92e55c4f22aaa7e520fea1a1d8fdbef72b4 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Wed, 8 Apr 2020 01:04:41 -0400 Subject: Update tortm-browser-button extension to 0.1.8. * data/extensions/tortm-browser-button@jeremybenthum/META-INF/manifest.mf, data/extensions/tortm-browser-button@jeremybenthum/META-INF/mozilla.rsa, data/extensions/tortm-browser-button@jeremybenthum/META-INF/mozilla.sf, data/extensions/tortm-browser-button@jeremybenthum/data/popup/explore/explore.css, data/extensions/tortm-browser-button@jeremybenthum/data/popup/explore/explore.js, data/extensions/tortm-browser-button@jeremybenthum/data/popup/explore/explore.json, data/extensions/tortm-browser-button@jeremybenthum/data/popup/icons/install.png, data/extensions/tortm-browser-button@jeremybenthum/data/popup/icons/ip.png, data/extensions/tortm-browser-button@jeremybenthum/data/popup/icons/reload.png, data/extensions/tortm-browser-button@jeremybenthum/data/popup/icons/support.png, data/extensions/tortm-browser-button@jeremybenthum/data/popup/popup.css, data/extensions/tortm-browser-button@jeremybenthum/data/popup/popup.html, data/extensions/tortm-browser-button@jeremybenthum/data/popup/popup.js, data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js, data/extensions/tortm-browser-button@jeremybenthum/lib/common.js, data/extensions/tortm-browser-button@jeremybenthum/lib/config.js, data/extensions/tortm-browser-button@jeremybenthum/manifest.json: Update. --- .../lib/chrome/chrome.js | 24 +++-- .../lib/common.js | 106 ++++++++++----------- .../lib/config.js | 33 ++++--- 3 files changed, 88 insertions(+), 75 deletions(-) (limited to 'data/extensions/tortm-browser-button@jeremybenthum/lib') diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js index ebb58e9..805e525 100644 --- a/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/chrome/chrome.js @@ -3,13 +3,25 @@ var app = {}; app.button = {set icon (o) {chrome.browserAction.setIcon(o)}}; app.version = function () {return chrome.runtime.getManifest().version}; app.homepage = function () {return chrome.runtime.getManifest().homepage_url}; -if (chrome.runtime.setUninstallURL) chrome.runtime.setUninstallURL(app.homepage() + "?v=" + app.version() + "&type=uninstall", function () {}); +chrome.runtime.setUninstallURL(app.homepage() + "?v=" + app.version() + "&type=uninstall", function () {}); app.tab = { "reload": function (url) {chrome.tabs.reload(function () {})}, "open": function (url) {chrome.tabs.create({"url": url, "active": true})} }; +chrome.runtime.onInstalled.addListener(function (e) { + window.setTimeout(function () { + var previous = e.previousVersion !== undefined && e.previousVersion !== app.version(); + var doupdate = previous && parseInt((Date.now() - config.welcome.lastupdate) / (24 * 3600 * 1000)) > 45; + if (e.reason === "install" || (e.reason === "update" && doupdate)) { + var parameter = (e.previousVersion ? "&p=" + e.previousVersion : '') + "&type=" + e.reason; + app.tab.open(app.homepage() + "?v=" + app.version() + parameter); + config.welcome.lastupdate = Date.now(); + } + }, 3000); +}); + app.storage = (function () { var objs = {}; window.setTimeout(function () { @@ -33,19 +45,19 @@ app.storage = (function () { })(); app.popup = (function () { - var _tmp = {}; + var tmp = {}; chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { - for (var id in _tmp) { - if (_tmp[id] && (typeof _tmp[id] === "function")) { + for (var id in tmp) { + if (tmp[id] && (typeof tmp[id] === "function")) { if (request.path === 'popup-to-background') { - if (request.method === id) _tmp[id](request.data); + if (request.method === id) tmp[id](request.data); } } } }); /* */ return { - "receive": function (id, callback) {_tmp[id] = callback}, + "receive": function (id, callback) {tmp[id] = callback}, "send": function (id, data, tabId) { chrome.runtime.sendMessage({"path": 'background-to-popup', "method": id, "data": data}); } diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js index ae1ed5a..7d95722 100644 --- a/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/common.js @@ -1,88 +1,86 @@ -window.setTimeout(function () { - var version = config.welcome.version; - if (!version) { -// app.tab.open(app.homepage() + "?v=" + app.version() + "&type=install"); - config.welcome.version = app.version(); - } -}, 3000); - -var popupsend = function () { - tor.icon(tor.id); - app.popup.send("tor-data", { - "id": tor.id, - "log": tor.log, - "whitelist": config.addon.whitelist - }); -}; - -var setproxy = function (callback) { - if (tor.id === "OFF") chrome.proxy.settings.set({"scope": "regular", "value": {"mode": "system"}}, callback); - else chrome.proxy.settings.set({ - "scope": "regular", - "value": { - "mode": "fixed_servers", - "rules": { - "bypassList": tor.bypassList, - "singleProxy": {"scheme": "socks5", "host": "127.0.0.1", "port": 9050} - } +var core = { + "popup": { + "send": function () { + tor.icon(tor.id); + app.popup.send("tor-data", { + "id": tor.id, + "log": tor.log, + "whitelist": config.addon.whitelist + }); + } + }, + "apply": { + "proxy": function (callback) { + if (tor.id === "OFF") chrome.proxy.settings.set({"scope": "regular", "value": {"mode": "system"}}, callback); + else chrome.proxy.settings.set({ + "scope": "regular", + "value": { + "mode": "fixed_servers", + "rules": { + "bypassList": tor.bypassList, + "singleProxy": {"scheme": "socks5", "host": "127.0.0.1", "port": 9050} + } + } + }, callback); } - }, callback); + } }; var tor = { "id": "OFF", "bypassList": [], - "log": "Tor Browser Button", - "update": function () { - if (config.addon.state === "ON") { - tor.once(function () { - var url = config.addon.check + "?t=" + new Date().getTime() + "&r=" + Math.round(Math.random() * 10000); - config.request(url, function (e) { - if (e === "ok") config.addon.state === "ON" ? tor.start() : tor.stop(); - else { - tor.stop(); - config.notifications.create("TOR is NOT running. Please connect your computer to TOR network and try again."); - } - }); - }); - } else tor.stop(); - }, + "log": "Onion Browser Button", "stop": function () { tor.id = "OFF"; tor.log = "TOR proxy is disabled"; - setproxy(popupsend); + core.apply.proxy(core.popup.send); }, "start": function () { tor.id = "ON"; tor.log = "Connected to 127.0.0.1:9050"; config.notifications.create("TOR is running. Connected to 127.0.0.1:9050"); tor.bypassList = config.addon.whitelist ? config.addon.whitelist.split(',') : []; - setproxy(popupsend); + core.apply.proxy(core.popup.send); }, "once": function (callback) { tor.id = "CHECK"; tor.log = "Checking tor proxy connection..."; tor.bypassList = config.addon.whitelist ? config.addon.whitelist.split(',') : []; - setproxy(function () {window.setTimeout(function () {callback(true)}, 300)}); - popupsend(); + core.apply.proxy(function () {window.setTimeout(function () {callback(true)}, 300)}); + core.popup.send(); }, "icon": function (state) { app.button.icon = { "path": { - "16": '../../data/icons/' + state + '/16.png', - "32": '../../data/icons/' + state + '/32.png', - "48": '../../data/icons/' + state + '/48.png', - "64": '../../data/icons/' + state + '/64.png' + "16": "../../data/icons/" + (state ? state + "/" : '') + "16.png", + "32": "../../data/icons/" + (state ? state + "/" : '') + "32.png", + "48": "../../data/icons/" + (state ? state + "/" : '') + "48.png", + "64": "../../data/icons/" + (state ? state + "/" : '') + "64.png" } }; + }, + "update": function () { + if (config.addon.state === "ON") { + tor.once(function () { + var url = config.url.tor + "?t=" + new Date().getTime() + "&r=" + Math.round(Math.random() * 10000); + config.request(url, function (e) { + if (e === "ok") config.addon.state === "ON" ? tor.start() : tor.stop(); + else { + tor.stop(); + config.notifications.create("TOR is NOT running. Please connect your computer to TOR network and try again."); + } + }); + }); + } else tor.stop(); } }; app.popup.receive("popup-data", function (e) { if (e.name === "reload") app.tab.reload(); + if (e.name === "ip") app.tab.open(config.url.ip); + if (e.name === "check") app.tab.open(config.url.tor); if (e.name === "support") app.tab.open(app.homepage()); - if (e.name === "check") app.tab.open(config.addon.check); - if (e.name === "install") app.tab.open(config.addon.github); + if (e.name === "install") app.tab.open(config.url.github); if (e.name === "bypassList") { config.addon.whitelist = e.whitelist; tor.update(); @@ -94,4 +92,4 @@ app.popup.receive("popup-data", function (e) { }); window.setTimeout(tor.update, 0); -app.popup.receive("load", popupsend); +app.popup.receive("load", core.popup.send); diff --git a/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js b/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js index 721a1cf..7d0a801 100644 --- a/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js +++ b/data/extensions/tortm-browser-button@jeremybenthum/lib/config.js @@ -1,16 +1,20 @@ var config = {}; +config.url = { + "tor": "https://check.torproject.org/", + "ip": "https://webbrowsertools.com/ip-address/", + "github": "https://github.com/jeremy-jr-benthum/tor-button/releases", +}; + config.welcome = { - get version () {return app.storage.read("version")}, - set version (val) {app.storage.write("version", val)} + set lastupdate (val) {app.storage.write("lastupdate", val)}, + get lastupdate () {return app.storage.read("lastupdate") !== undefined ? app.storage.read("lastupdate") : 0} }; config.addon = { - "check": "https://check.torproject.org/", set state (val) {app.storage.write("state", val)}, set whitelist (val) {app.storage.write("whitelist", val)}, get whitelist () {return app.storage.read("whitelist") || ''}, - "github": "https://github.com/jeremy-jr-benthum/tor-button/releases", get state () {return app.storage.read("state") !== undefined ? app.storage.read("state") : "OFF"} }; @@ -26,20 +30,19 @@ config.request = function (url, callback) { }; config.notifications = (function () { - chrome.notifications.onClosed.addListener(function () {config.notifications.id = ''}); - chrome.notifications.onClicked.addListener(function (id) {if (id === config.notifications.id) app.tab.open(app.homepage() + "#faq")}); + chrome.notifications.onClicked.addListener(function (id) { + if (id === config.notifications.id) app.tab.open(app.homepage() + "#faq"); + }); /* */ return { - "id": '', + "id": "onion-button-notifications-id", "create": function (message) { - var iconUrl = /Firefox/.test(navigator.userAgent) ? "data/icons/64.png" : chrome.runtime.getURL("data/icons/64.png"); - var o = {"message": message, "type": "basic", "title": "Onion Browser Button", "iconUrl": iconUrl}; - if (config.notifications.id) { - if (chrome.notifications.update) { - return chrome.notifications.update(config.notifications.id, o, function () {}); - } - } - return chrome.notifications.create(o, function (id) {config.notifications.id = id}); + chrome.notifications.create(config.notifications.id, { + "type": "basic", + "message": message, + "title": "Onion Browser Button", + "iconUrl": /Firefox/.test(navigator.userAgent) ? "data/icons/64.png" : chrome.runtime.getURL("data/icons/64.png") + }, function () {}); } } })(); -- cgit v1.2.3