diff options
author | Martin Fischer <martin@push-f.com> | 2025-03-14 06:21:05 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2025-03-14 08:35:51 +0100 |
commit | 86426290ebf2b8b2a2655621fa4342c5cb984de3 (patch) | |
tree | f4fd40ddb09e7de76b24c9066a4a9a4ff466c1b8 | |
parent | cba78193c72ea02cc0fe83df9b8d46ec325affc9 (diff) |
refactor: define available links as constant
It makes sense to treat configuration as data
(that could be (de)serialized in the future).
-rw-r--r-- | script.js | 44 |
1 files changed, 21 insertions, 23 deletions
@@ -1,27 +1,25 @@ +const LINKS = [ + { + label: 'Google Maps', + url: 'https://www.google.com/maps/search/?api=1&query={lat},{lon}', + }, + { + label: 'Apple Maps', + url: 'https://maps.apple.com/?q={lat},{lon}&t=m', + }, + { + label: 'Default app', + url: 'geo:{lat},{lon}', + }, + { + label: 'OpenStreetMap', + url: 'https://www.openstreetmap.org/?mlat={lat}&mlon={lon}&zoom=15&layers=M', + }, +]; + const latlon = location.hash.substring(1); const [lat, lon] = latlon.split(','); -function getLinks(lat, lon) { - return [ - { - label: 'Google Maps', - url: `https://www.google.com/maps/search/?api=1&query=${lat},${lon}`, - }, - { - label: 'Apple Maps', - url: `https://maps.apple.com/?q=${lat},${lon}&t=m` - }, - { - label: 'Default app', - url: `geo:${lat},${lon}` - }, - { - label: 'OpenStreetMap', - url: `https://www.openstreetmap.org/?mlat=${lat}&mlon=${lon}&zoom=15&layers=M` - }, - ] -} - const heading = document.getElementById('heading'); // TODO: listen on hashChange @@ -34,10 +32,10 @@ if (isNaN(lat) || isNaN(lon)) { document.title = 'Open location'; - for (const link of getLinks(lat, lon)) { + for (const link of LINKS) { const li = document.createElement('li'); const a = document.createElement('a'); - a.href = link.url; + a.href = link.url.replace('{lat}', lat).replace('{lon}', lon); a.textContent = link.label; li.appendChild(a); linkList.appendChild(li); |