From d6902eea60acea9f1ea3828e1cdb0bf6288e7b06 Mon Sep 17 00:00:00 2001 From: hackademix Date: Tue, 14 Aug 2018 00:58:14 +0200 Subject: Removed browser->webex "shim". --- contact_finder.js | 38 +------------------------------------- html/preferences_panel/pref.js | 24 ++---------------------- main_background.js | 39 +++++++++------------------------------ 3 files changed, 12 insertions(+), 89 deletions(-) diff --git a/contact_finder.js b/contact_finder.js index 90f0108..48f9c27 100644 --- a/contact_finder.js +++ b/contact_finder.js @@ -289,45 +289,9 @@ function main(){ new_debug_button("Complain to website",handler); } -// See main_background.js -var webex; -var myPort; -function set_webex(){ - if(typeof(browser) == "object"){ - webex = browser; - } - if(typeof(chrome) == "object"){ - webex = chrome; - } -} -set_webex(); -var myPort = webex.runtime.connect({name:"contact_finder"}); +var myPort = browser.runtime.connect({name:"contact_finder"}); myPort.onMessage.addListener(function(m) { prefs = m; main(); }); - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/html/preferences_panel/pref.js b/html/preferences_panel/pref.js index 757bf5e..4642d32 100644 --- a/html/preferences_panel/pref.js +++ b/html/preferences_panel/pref.js @@ -19,25 +19,7 @@ * along with GNU LibreJS. If not, see . */ -/** -* -* Sets global variable "webex" to either "chrome" or "browser" for -* use on Chrome or a Firefox variant. -* -* Change this to support a new browser that isn't Chrome or Firefox, -* given that it supports webExtensions. -* -* (Use the variable "webex" for all API calls after calling this) -*/ var store; -function set_webex(){ - if(typeof(browser) == "undefined"){ - webex = chrome; - } else{ - webex = browser; - } -} -set_webex(); function storage_got(items){ var inputs = document.getElementsByTagName("input"); @@ -67,7 +49,7 @@ function storage_got(items){ } -webex.storage.local.get(storage_got); +browser.storage.local.get(storage_got); document.getElementById("save_changes").addEventListener("click", function(){ var inputs = document.getElementsByTagName("input"); @@ -91,7 +73,5 @@ document.getElementById("save_changes").addEventListener("click", function(){ } console.log(data); - webex.storage.local.set(data); + browser.storage.local.set(data); }); - - diff --git a/main_background.js b/main_background.js index 1f3cdae..35081ea 100644 --- a/main_background.js +++ b/main_background.js @@ -111,26 +111,6 @@ var reserved_objects = [ "eval" ]; -/** -* -* Sets global variable "webex" to either "chrome" or "browser" for -* use on Chrome or a Firefox variant. -* -* Change this to support a new browser that isn't Chrome or Firefox, -* given that it supports webExtensions. -* -* (Use the variable "webex" for all API calls after calling this) -*/ -var webex; -function set_webex(){ - if(typeof(browser) == "object"){ - webex = browser; - } - if(typeof(chrome) == "object"){ - webex = chrome; - } -} - // Generates JSON key for local storage function get_storage_key(script_name,src_hash){ return script_name; @@ -154,7 +134,7 @@ function options_listener(changes, area){ function flushed(){ dbg_print("cache flushed"); } - //var flushingCache = webex.webRequest.handlerBehaviorChanged(flushed); + //var flushingCache = browser.webRequest.handlerBehaviorChanged(flushed); dbg_print("Items updated in area" + area +": "); @@ -206,7 +186,7 @@ async function openReportInTab(data) { * */ function debug_delete_local(){ - webex.storage.local.clear(); + browser.storage.local.clear(); dbg_print("Local storage cleared"); } @@ -224,7 +204,7 @@ function debug_print_local(){ } console.log("%c Variable 'activityReports': ", 'color: red;'); console.log(activityReports); - webex.storage.local.get(storage_got); + browser.storage.local.get(storage_got); } /** @@ -362,7 +342,7 @@ function connected(p) { function cb(items){ p.postMessage(items); } - webex.storage.local.get(cb); + browser.storage.local.get(cb); return; } p.onMessage.addListener(async function(m) { @@ -1118,10 +1098,9 @@ var listManager = new ListManager(whitelist, blacklist, */ async function init_addon(){ await whitelist.load(); - set_webex(); - webex.runtime.onConnect.addListener(connected); - webex.storage.onChanged.addListener(options_listener); - webex.tabs.onRemoved.addListener(delete_removed_tab_info); + browser.runtime.onConnect.addListener(connected); + browser.storage.onChanged.addListener(options_listener); + browser.tabs.onRemoved.addListener(delete_removed_tab_info); browser.tabs.onUpdated.addListener(onTabUpdated); browser.tabs.onActivated.addListener(onTabActivated); // Prevents Google Analytics from being loaded from Google servers @@ -1131,7 +1110,7 @@ async function init_addon(){ "web_manifest", "websocket", "xbl", "xml_dtd", "xmlhttprequest", "xslt", "other" ]; - webex.webRequest.onBeforeRequest.addListener( + browser.webRequest.onBeforeRequest.addListener( block_ga, {urls: [""], types: all_types}, ["blocking"] @@ -1151,7 +1130,7 @@ function inject_contact_finder(tab_id){ function executed(result) { dbg_print("[TABID:"+tab_id+"]"+"finished executing contact finder: " + result); } - var executing = webex.tabs.executeScript(tab_id, {file: "/contact_finder.js"}, executed); + var executing = browser.tabs.executeScript(tab_id, {file: "/contact_finder.js"}, executed); } init_addon(); -- cgit v1.2.3