about summary refs log tree commit diff stats
path: root/src/pages/options/maps.js
blob: ff83f9e86ef30aa145dbdae195a7e5b0498a3217 (plain) (blame)
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
35
import mapsHelper from "../../assets/javascripts/helpers/google-maps.js";
import commonHelper from "../../assets/javascripts/helpers/common.js";
import shared from "./shared.js";

const osmInstances = mapsHelper.redirects;
let osmInstance = document.getElementById("osm-instance");
let disableOsm = document.getElementById("disable-osm");

browser.storage.sync.get(
    [
        "osmInstance",
        "disableOsm",
    ],
    (result) => {
        osmInstance.value = result.osmInstance || "";
        disableOsm.checked = !result.disableOsm;
        let id = "osm-instance"
        let instances = osmInstances
        shared.autocompletes.push({ id: id, instances: instances })
        shared.autocomplete(document.getElementById(id), instances);
    }
)

const osmInstanceChange = commonHelper.debounce(() => {
    if (osmInstance.checkValidity()) {
        browser.storage.sync.set({
            osmInstance: shared.parseURL(osmInstance.value),
        });
    }
}, 500);
osmInstance.addEventListener("input", osmInstanceChange);

disableOsm.addEventListener("change", (event) => {
    browser.storage.sync.set({ disableOsm: !event.target.checked });
});