Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ function focusOn() {
const url = new URL(window.location.href);
const params = url.searchParams;

applyURLLayers(params);

const fromMGCG = params.get("from") === "MFCG" && document.referrer;
if (fromMGCG) {
if (params.get("seed").length === 13) {
Expand Down
53 changes: 53 additions & 0 deletions public/modules/ui/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,3 +1063,56 @@ function getLayer(id) {
if (id === "toggleTrade") return $("#tradeAnimation");
if (id === "toggleRulers") return $("#ruler");
}

function applyURLLayers(params) {
const presetParam = params.get("preset");
const layersParam = params.get("layers");

if (!presetParam && !layersParam) return;

const normalize = str => str.toLowerCase().replace(/[^a-z0-9]/g, "");

if (presetParam) {
let matchedPreset = null;
const lowerParam = presetParam.toLowerCase().trim();
for (const key in presets) {
if (key.toLowerCase() === lowerParam) {
matchedPreset = key;
break;
}
}
if (!matchedPreset) {
const selectEl = document.getElementById("layersPreset");
if (selectEl) {
for (const option of selectEl.options) {
const optionText = option.text.toLowerCase();
if (optionText.includes(lowerParam) || lowerParam.includes(optionText)) {
matchedPreset = option.value;
break;
}
}
}
}
if (matchedPreset) {
handleLayersPresetChange(matchedPreset);
}
}

if (layersParam) {
const visibleNames = layersParam.split(",").map(s => normalize(s));
document.querySelectorAll("#mapLayers > li").forEach(el => {
const idNormalized = normalize(el.id);
const idWithoutToggleNormalized = normalize(el.id.replace(/^toggle/, ""));
const textNormalized = normalize(el.innerText || el.textContent || "");

const shouldBeOn = visibleNames.some(
name => name === idNormalized || name === idWithoutToggleNormalized || name === textNormalized
);

const isOn = layerIsOn(el.id);
if (shouldBeOn && !isOn) el.click();
if (isOn && !shouldBeOn) el.click();
});
}
}

Loading