show(i));
return { b, f };
});
let show = function (i) {
items.forEach((it, k) => { it.f.hidden = k !== i; it.b.setAttribute("aria-selected", k === i); });
try { sessionStorage.setItem("dlad-tab", i); } catch (e) {}
};
// Adresszeile: #tabname=CODE (Generatoren melden ihren Stand per postMessage)
const norm = t => t.toLowerCase();
const codes = {};
let pending = null;
function parseHash() {
const m = /^#([^=]+)=(.*)$/.exec(location.hash); if (!m) return null;
let code = ""; try { code = decodeURIComponent(m[2]); } catch (e) { return null; }
const i = GENERATOREN.findIndex(g => norm(g.titel) === decodeURIComponent(m[1]));
return i < 0 ? null : { i: i, tab: GENERATOREN[i].titel, code: code };
}
function setHash(tab) {
try { history.replaceState(null, "", tab && codes[tab] ? "#" + norm(tab) + "=" + encodeURIComponent(codes[tab]) : location.pathname + location.search); } catch (e) {}
}
window.addEventListener("message", ev => {
const m = ev.data; if (!m || !m.dlad) return;
const i = GENERATOREN.findIndex(g => g.titel === m.tab); if (i < 0) return;
if (m.dlad === "ready" && pending && pending.tab === m.tab) { items[i].f.contentWindow.postMessage({ dlad: "load", tab: m.tab, code: pending.code }, "*"); pending = null; }
else if (m.dlad === "state") {
if (pending && pending.tab === m.tab) return;
codes[m.tab] = m.code; if (!items[i].f.hidden) setHash(m.tab);
}
});
const baseShow = show;
show = function (i) { baseShow(i); setHash(GENERATOREN[i].titel); };
window.addEventListener("hashchange", () => { const h = parseHash(); if (!h) return; show(h.i); items[h.i].f.contentWindow.postMessage({ dlad: "load", tab: h.tab, code: h.code }, "*"); });
let start = 0;
try { start = Math.min(+sessionStorage.getItem("dlad-tab") || 0, items.length - 1); } catch (e) {}
const h0 = parseHash(); if (h0) { start = h0.i; pending = h0; }
show(start);
})();