Skip to content

Commit f04887a

Browse files
committed
Add option to configure basic map type for Mapy.cz
1 parent 670fbf7 commit f04887a

File tree

11 files changed

+91
-30
lines changed

11 files changed

+91
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
[2.1.0](../../releases/tag/v2.1.0) - 2025-03-25
5+
-----------------------------------------------
6+
### Added
7+
- option to configure the basic map type for Mapy.cz
8+
49
[2.0.0](../../releases/tag/v2.0.0) - 2025-03-19
510
-----------------------------------------------
611
### Added

src/_locales/cs/messages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extension_name": {"message": "MapSwitcher"},
33
"extension_description": {"message": "Přidá do různých mapových služeb tlačítka pro otevření stejné pozice na mapě v jiných mapových službách."},
44
"visible_buttons_header": {"message": "Zobrazit tlačítka na přepínání do"},
5+
"button_options_header": {"message": "Možnosti tlačítek"},
6+
"mapy_cz_use_outdoor_for_basic": {"message": "Použít Turistickou mapu místo Základní mapy v Mapy.cz"},
57
"GOOGLE_MAPS": {"message": "Mapy Google"},
68
"MAPY_CZ": {"message": "Mapy.cz"},
79
"OPEN_STREET_MAP": {"message": "OpenStreetMap"}

src/_locales/en/messages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"extension_name": {"message": "MapSwitcher"},
33
"extension_description": {"message" :"Adds buttons to various map services for opening the same location in different map services."},
44
"visible_buttons_header": {"message": "Show buttons to switch to"},
5+
"button_options_header": {"message": "Button options"},
6+
"mapy_cz_use_outdoor_for_basic": {"message": "Use \"Outdoor\" instead of \"Basic\" map in Mapy.cz"},
57
"GOOGLE_MAPS": {"message": "Google Maps"},
68
"MAPY_CZ": {"message": "Mapy.cz"},
79
"OPEN_STREET_MAP": {"message": "OpenStreetMap"}

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "__MSG_extension_name__",
44
"description": "__MSG_extension_description__",
55
"default_locale": "en",
6-
"version": "2.0.0",
6+
"version": "2.1.0",
77
"browser_specific_settings": {
88
"gecko": {
99
"id": "{0516BC41-6FA3-4326-87FE-7EA9101412FE}"

src/pages/options.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
<span i18n-id="OPEN_STREET_MAP">OpenStreetMap</span>
4343
</label>
4444
</div>
45+
<div class="options-group">
46+
<div class="options-group-header" i18n-id="button_options_header">Button options</div>
47+
<label>
48+
<input type="checkbox" id="mapy-cz-use-outdoor-for-basic">
49+
<span i18n-id="mapy_cz_use_outdoor_for_basic">Use "Outdoor" instead of "Basic" map in Mapy.cz</span>
50+
</label>
51+
</div>
4552
</div>
4653
<div id="google-maps-opera-warning">
4754
If you want this to work on Google Maps in Opera, you need to enable "Allow access to search page results" for this extensions.

src/scripts/js/options.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const defaultOptions = {
55
[MAP_SERVICE.MAPY_CZ]: true,
66
[MAP_SERVICE.OPEN_STREET_MAP]: false,
77
},
8+
mapyCzUseOutdoorForBasic: true,
89
};
910

1011
// Saves options to chrome.storage.sync, returns a promise to maybe let the user know when it's done
@@ -23,14 +24,17 @@ async function loadOptionsFromStorage() {
2324
}
2425
if (retrievedStorage.options.optionsVersion === '1.0') {
2526
// migrate from version 1.0 to 2.0
26-
const migratedOptions = {
27-
optionsVersion: "2.0",
28-
shownButtons: {
29-
[MAP_SERVICE.GOOGLE_MAPS]: retrievedStorage.options.showGMapsButton,
30-
[MAP_SERVICE.MAPY_CZ]: retrievedStorage.options.showMapyczButton,
31-
[MAP_SERVICE.OPEN_STREET_MAP]: false,
27+
const migratedOptions = Object.assign(
28+
{},
29+
structuredClone(defaultOptions),
30+
{
31+
shownButtons: {
32+
[MAP_SERVICE.GOOGLE_MAPS]: retrievedStorage.options.showGMapsButton,
33+
[MAP_SERVICE.MAPY_CZ]: retrievedStorage.options.showMapyczButton,
34+
[MAP_SERVICE.OPEN_STREET_MAP]: false,
35+
},
3236
},
33-
};
37+
)
3438
await chrome.storage.sync.set({ options: migratedOptions });
3539
return migratedOptions;
3640
}

src/scripts/js/pages/options.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ async function saveOptionsFromElements() {
55
key,
66
!!document.querySelector(`.show-button-checkbox[data-service="${key}"]`)?.checked,
77
])),
8+
mapyCzUseOutdoorForBasic: document.querySelector("#mapy-cz-use-outdoor-for-basic")?.checked,
89
});
910
}
1011

@@ -18,6 +19,10 @@ async function loadOptionsToElements() {
1819
checkbox.checked = !!options.shownButtons[key];
1920
}
2021
}
22+
const mapyCzUseOutdoorForBasicCheckbox = document.querySelector("#mapy-cz-use-outdoor-for-basic");
23+
if (mapyCzUseOutdoorForBasicCheckbox) {
24+
mapyCzUseOutdoorForBasicCheckbox.checked = !!options.mapyCzUseOutdoorForBasic;
25+
}
2126
}
2227

2328
document.addEventListener("DOMContentLoaded", () => loadOptionsToElements());

src/scripts/js/urls/common.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
let loadedOptions = structuredClone(defaultOptions);
2+
13
const converters = {};
2-
function registerConverter(service, converter) {
3-
converters[service] = converter;
4+
function registerConverter(service, ConverterClass) {
5+
converters[service] = new ConverterClass(loadedOptions);
46
}
57

8+
loadOptionsFromStorage().then((options) => {
9+
loadedOptions = options;
10+
for (const converter of Object.values(converters)) {
11+
converter.updateExtensionOptions(loadedOptions);
12+
}
13+
});
14+
615
function getConverterForCurrentService() {
716
const service = detectCurrentMapService();
817
if (!service) throw new Error("No map service detected");
@@ -24,3 +33,21 @@ function getDestinationUrl(destination, mapInfo) {
2433
if (!converter) return "";
2534
return converter.universalToUrl(mapInfo);
2635
}
36+
37+
class UrlConverter {
38+
constructor(extensionOptions) {
39+
this.extensionOptions = extensionOptions;
40+
}
41+
42+
updateExtensionOptions(extensionOptions) {
43+
this.extensionOptions = extensionOptions;
44+
}
45+
46+
universalToUrl(universal) {
47+
throw new Error("universalToUrl not implemented");
48+
}
49+
50+
urlToUniversal(url) {
51+
throw new Error("urlToUniversal not implemented");
52+
}
53+
}

src/scripts/js/urls/google_maps.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
registerConverter(MAP_SERVICE.GOOGLE_MAPS, {
2-
universalToUrl: function (universal) {
1+
class GoogleMapsUrlConverter extends UrlConverter{
2+
universalToUrl(universal) {
33
let data = "";
44
let zoom = universal.zoom + "z";
55

@@ -14,8 +14,9 @@ registerConverter(MAP_SERVICE.GOOGLE_MAPS, {
1414
const lat = universal.lat;
1515

1616
return `https://www.google.com/maps/@${lat},${lon},${zoom}/${data}`;
17-
},
18-
urlToUniversal: function (url) {
17+
}
18+
19+
urlToUniversal(url) {
1920
// check if maps are in satellite mode, or not
2021
// based on https://mstickles.wordpress.com/2015/06/12/gmaps-urls-options/
2122
// the URL should be parsed more thoroughly if we wanted to do this properly, but this seems to work fine for our use case
@@ -68,5 +69,7 @@ registerConverter(MAP_SERVICE.GOOGLE_MAPS, {
6869
lon: lon,
6970
zoom: zoom,
7071
};
71-
},
72-
});
72+
}
73+
}
74+
75+
registerConverter(MAP_SERVICE.GOOGLE_MAPS, GoogleMapsUrlConverter);

src/scripts/js/urls/mapy_cz.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
registerConverter(MAP_SERVICE.MAPY_CZ, {
2-
universalToUrl: function (universal) {
1+
class MapyCzUrlConverter extends UrlConverter {
2+
universalToUrl(universal) {
33
let lon = universal.lon;
44
let lat = universal.lat;
55
let zoom = Math.round(universal.zoom);
66

7-
let type = "zakladni";
7+
let type = this.extensionOptions.mapyCzUseOutdoorForBasic ? "turisticka" : "zakladni";
88
if (universal.type == "satellite") {
99
type = "letecka";
1010
}
1111

1212
// put the URL together
1313
return `https://www.mapy.cz/${type}?x=${lon}&y=${lat}&z=${zoom}&l=0`;
14-
},
15-
urlToUniversal: function (url) {
14+
}
15+
16+
urlToUniversal(url) {
1617
// check if maps are in satellite mode, or not
1718
let type = "basic";
1819
if ((url.indexOf("base=ophoto") >= 0) || (url.indexOf("letecka") >= 0)) {
@@ -29,7 +30,7 @@ registerConverter(MAP_SERVICE.MAPY_CZ, {
2930
let zoom = 1;
3031

3132
// parse the address parameters
32-
for (field of addrFields) {
33+
for (const field of addrFields) {
3334
let par = field.split("=")[0];
3435
let val = field.split("=")[1];
3536

@@ -51,5 +52,7 @@ registerConverter(MAP_SERVICE.MAPY_CZ, {
5152
lon: lon,
5253
zoom: zoom,
5354
};
54-
},
55-
});
55+
}
56+
}
57+
58+
registerConverter(MAP_SERVICE.MAPY_CZ, MapyCzUrlConverter);

0 commit comments

Comments
 (0)