aboutsummaryrefslogtreecommitdiff
path: root/addons/qwantjunior/content-script.js
blob: 01b3976053cf1d9f3e331ead468b50c8feeacc79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);