Add more sources for markers#45
Conversation
| const urlParams = new URLSearchParams(window.location.search); | ||
| // Possible markers sources | ||
| // A) https://example.com?m=<base64-json-str>#32368,32198,7:0 | ||
| // B) https://example.com?mf=https://example.com/pack.json#32368,32198,7:0 | ||
| // C) <div id="map" data-marker-json="<json-str>" ...> | ||
| // D) <div id="map" data-marker-pack="https://example.com/pack.json" ...> | ||
| // E) fallback: https://tibiamaps.github.io/tibia-map-data/markers.json | ||
| if (urlParams.get('m')) { | ||
| buildMarkerLayers(atob(JSON.parse(urlParams.get('m')))); | ||
| } else if (urlParams.get('mf')) { | ||
| loadMarkersPack(urlParams.get('mf')); | ||
| } else if (mapContainer.dataset.markerJson) { | ||
| buildMarkerLayers(JSON.parse(mapContainer.dataset.markerJson)); | ||
| } else if (mapContainer.dataset.markerPack) { | ||
| loadMarkersPack(URL_PREFIX + mapContainer.dataset.markerPack); | ||
| } else { | ||
| loadMarkersPack(URL_PREFIX + 'markers.json'); | ||
| } |
There was a problem hiding this comment.
I think it would be nice to extract this logic to a separate function (called getMarkerPackUrl or some such) that returns a URL to load, so we could have early returns instead of all the else ifs.
There was a problem hiding this comment.
I don't think this could be much cleaner given the hierarchy I proposed (A behavior overrides B, B overrides C, etc.), but I gave it a try on my latest changes. Lemme know if it looks better. We can also consider other hierarchy or removing some of the sources.
|
The marker data is now user-controlled (either by loading a third-party URL or embedding the data in the URL itself), so we have to be careful not to introduce XSS. |
9fa13fb to
5ca9c0d
Compare
Do you have any suggestions in mind? Given that user input in being sent to |
It's not |
Addresses #43 with a few more ways to override sources for markers