import {Settings} from "./settings"
import * as Cookie from "js-cookie";

export function loadSettings(): Settings {
  try {
    const options = Cookie.getJSON("options") || {};
    return Settings.createFromObject(options);
  } catch (e) {
    console.error("Failed to load settings: ", e);
    return Settings.createFromObject({});
  }
}

export function saveSettings(settings: Settings) {
  Cookie.set("options", settings, {expires: 365});
}

import {Settings} from "./settings"
import * as Cookie from "js-cookie";

export function loadSettings(): Settings {
  try {
    const options = Cookie.getJSON("options") || {};
    return Settings.createFromObject(options);
  } catch (e) {
    console.error("Failed to load settings: ", e);
    return Settings.createFromObject({});
  }
}

export function saveSettings(settings: Settings) {
  Cookie.set("options", settings, {expires: 365, sameSite: "none"});
}

Allow cross-site usage of the options cookie
Allow cross-site usage of the options cookie

The [SameSite cookie](https://web.dev/samesite-cookies-explained/) setting (which now defaults to `lax` in Chrome) limits access of the `options` cookie.
This breaks [command.games](https://github.com/davidtorosyan/command.games), which depends on this cookie. 
This change sets `sameSite` to `none`, which should fix the plugin.

See issue #58.