aboutsummaryrefslogtreecommitdiff
path: root/main_background.js
diff options
context:
space:
mode:
Diffstat (limited to 'main_background.js')
-rw-r--r--main_background.js55
1 files changed, 42 insertions, 13 deletions
diff --git a/main_background.js b/main_background.js
index 5b745c1..a145cc5 100644
--- a/main_background.js
+++ b/main_background.js
@@ -339,13 +339,18 @@ function get_domain(url){
*
*/
var portFromCS;
-function connected(p) {
- if(p["name"] == "contact_finder"){
+async function connected(p) {
+ if(p.name === "contact_finder"){
+ // style the contact finder panel
+ await browser.tabs.insertCSS(p.sender.tab.id, {
+ file: "/content/dialog.css",
+ cssOrigin: "user",
+ matchAboutBlank: true,
+ allFrames: true
+ });
+
// Send a message back with the relevant settings
- function cb(items){
- p.postMessage(items);
- }
- browser.storage.local.get(cb);
+ p.postMessage(await browser.storage.local.get(["prefs_subject", "prefs_body"]));
return;
}
p.onMessage.addListener(async function(m) {
@@ -372,7 +377,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 +1125,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 +1183,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.insertCSS(tabId, {file: "/content/overlay.css", cssOrigin: "user"}),
+ browser.tabs.executeScript(tabId, {file: "/content/contactFinder.js"}),
+ ]);
}
init_addon();