async function getSettingsFromStorage(storageKey, defaultSettings) {
  const storedSettings = await browser.storage.local.get(storageKey);

  return {
    ...defaultSettings,
    ...(storedSettings[storageKey] ?? {})
  };
}

async function setSettingInStorage(storageKey, defaultSettings, key, value) {
  const settings = await getSettingsFromStorage(storageKey, defaultSettings);

  await browser.storage.local.set({
    [storageKey]: {
      ...settings,
      [key]: value
    }
  });
}
