aboutsummaryrefslogtreecommitdiff
path: root/addons/qwantjunior/content-script.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/qwantjunior/content-script.js')
-rw-r--r--addons/qwantjunior/content-script.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/qwantjunior/content-script.js b/addons/qwantjunior/content-script.js
new file mode 100644
index 0000000..01b3976
--- /dev/null
+++ b/addons/qwantjunior/content-script.js
@@ -0,0 +1,34 @@
+"use strict";
+
+function changeSettings(managed) {
+ var preferred = managed.settings;
+ var userStorage = JSON.parse(localStorage.getItem('user'));
+ var needsReload = false;
+
+ if (userStorage == null) {
+ localStorage.setItem('user', JSON.stringify({
+ userSetting: preferred
+ }));
+
+ needsReload = true;
+ } else if (userStorage.version == "2") {
+ var setting = userStorage.userSetting;
+
+ for (const [key, value] of Object.entries(preferred)) {
+ if (setting[key] != preferred[key]) {
+ setting[key] = preferred[key];
+ needsReload = true;
+ }
+ }
+
+ localStorage.setItem('user', JSON.stringify(userStorage));
+ }
+
+ if (needsReload) {
+ location.reload();
+ }
+}
+
+browser.storage.managed
+ .get("settings")
+ .then(changeSettings);