summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2023-02-22 21:08:00 +0100
committerNicholas Tay <nick@windblume.net>2023-02-22 21:08:00 +0100
commit93e082dfa376f4ca63628a9a0eb70a8a83a88592 (patch)
tree2ebb6b0a1b28a5c8484cd748a1bd20ac6d18a1a6
parentd538892da62ce2614b9493e64b79f8bac1438fb6 (diff)
downloadcertain-93e082dfa376f4ca63628a9a0eb70a8a83a88592.tar.gz
certain-93e082dfa376f4ca63628a9a0eb70a8a83a88592.tar.bz2
certain-93e082dfa376f4ca63628a9a0eb70a8a83a88592.zip
Handle config updates dynamically
-rw-r--r--background.js40
1 files changed, 21 insertions, 19 deletions
diff --git a/background.js b/background.js
index 59c6c2b..0df541a 100644
--- a/background.js
+++ b/background.js
@@ -43,23 +43,25 @@ function setIcon(icon) {
browser.browserAction.setIcon({ path: "icons/" + icon + ".png" });
}
-function onReady() {
- // Listen for all header receive events, which contain the cert details we want
- browser.webRequest.onHeadersReceived.addListener(
- onHeaderReceive,
- {
- urls: ["<all_urls>"]
- },
- [
- "blocking"
- ]
- );
-}
+// Listen for all header receive events, which contain the cert details we want
+browser.webRequest.onHeadersReceived.addListener(
+ onHeaderReceive,
+ {
+ urls: ["<all_urls>"]
+ },
+ [
+ "blocking"
+ ]
+);
-// Fetch config for certs list
-const getting = browser.storage.sync.get("certs");
-getting.then(saved => {
- certs = saved.certs;
- console.log("certs=" + certs)
- onReady();
-}, console.error); \ No newline at end of file
+function updateCerts() {
+ const getting = browser.storage.sync.get("certs");
+ getting.then(saved => {
+ certs = saved.certs;
+ console.log("certs=" + certs)
+ }, console.error)
+}
+// Listen to config change for certs list
+browser.storage.local.onChanged.addListener(() => updateCerts());
+// Initial config fetch
+updateCerts(); \ No newline at end of file