aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
authorhackademix <giorgio@maone.net>2018-09-18 23:43:28 +0200
committerhackademix <giorgio@maone.net>2018-09-18 23:43:28 +0200
commit475a6b9e9ab5a47f8ea15c5b7e17f38d596b51a4 (patch)
tree83e7cc6395cd6e1d3b94ba5cd23822963db8598d /main_background.js
parent813daae97602ad7143e23fd6d955bef5e413dc7a (diff)
Initial refactoring and unhiding of contact finder / complaint UI.
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js38
1 files changed, 31 insertions, 7 deletions
diff --git a/main_background.js b/main_background.js
index 5b745c1..fdd895e 100644
--- a/main_background.js
+++ b/main_background.js
@@ -372,7 +372,7 @@ function connected(p) {
// invoke_contact_finder
if(m["invoke_contact_finder"] !== undefined){
contact_finder = true;
- inject_contact_finder();
+ await injectContactFinder();
}
// a debug feature (maybe give the user an option to do this?)
if(m["deletelocalstorage"] !== undefined){
@@ -1120,11 +1120,35 @@ var listManager = new ListManager(whitelist, blacklist,
.map(script => script.hash)
);
+
+async function initDefaults() {
+ let defaults = {
+ pref_subject: "Issues with Javascript on your website",
+ pref_body: `Please consider using a free license for the Javascript on your website.
+
+[Message generated by LibreJS. See https://www.gnu.org/software/librejs/ for more information]
+`
+ };
+ let keys = Object.keys(defaults);
+ let prefs = await browser.storage.local.get(keys);
+ let changed = false;
+ for (let k of keys) {
+ if (!(k in prefs)) {
+ prefs[k] = defaults[k];
+ changed = true;
+ }
+ }
+ if (changed) {
+ await browser.storage.local.set(prefs);
+ }
+}
+
/**
* Initializes various add-on functions
* only meant to be called once when the script starts
*/
-async function init_addon(){
+async function init_addon() {
+ await initDefaults();
await whitelist.load();
browser.runtime.onConnect.addListener(connected);
browser.storage.onChanged.addListener(options_listener);
@@ -1154,11 +1178,11 @@ async function init_addon(){
/**
* Loads the contact finder on the given tab ID.
*/
-function inject_contact_finder(tab_id){
- function executed(result) {
- dbg_print("[TABID:"+tab_id+"]"+"finished executing contact finder: " + result);
- }
- var executing = browser.tabs.executeScript(tab_id, {file: "/contact_finder.js"}, executed);
+async function injectContactFinder(tabId){
+ await Promise.all([
+ browser.tabs.executeScript(tabId, {file: "/content/contactFinder.js"}),
+ browser.tabs.insertCSS(tabId, {file: "/content/contactFinder.css", cssOrigin: "user"})
+ ]);
}
init_addon();