/* === BEGIN CP-CONNECT-WR-SEED-CHECKOUT-NOTE-INLINE 2026-08-03 === */
/* Inline twin of the user-scripts.js seeder. Lives in the page HTML (never cached,
max-age=0) so returning visitors get it immediately, bypassing the 30-day cache
on user-scripts.js. Seeds cpConnectWrHybridConfig from the visible config card so
the checkout note is populated even with the default config and overwrites any
stale localStorage from older card versions. Idempotent. Scoped to Connect WR. */
(function(){
if (!/erreplus-connect-wr-mono-dressursadel-p3100/.test(location.pathname)) return;
var KEY = 'cpConnectWrHybridConfig';
function sel(card, field){
var el = card.querySelector('[data-field="' + field + '"].is-selected');
return el ? (el.getAttribute('data-value') || '') : '';
}
function seatLabel(v){ return /"$/.test(String(v)) ? v : v + '"'; }
function seed(){
var card = document.querySelector('.cp-product-config-card');
if (!card) return;
var s = sel(card, 'seat'), t = sel(card, 'tree'), c = sel(card, 'color');
if (!s || !t || !c) return;
var text = 'Sadelkonfiguration: Sæde ' + seatLabel(s) + ', bomvidde ' + t + ', farve ' + c + '. Tilføj gerne klaplængde, paneler eller andre ønsker, hvis du kender dem. Ellers følger Berit op og aftaler resten.';
try { localStorage.setItem(KEY, JSON.stringify({ text: text, state: { seat: s, tree: t, color: c }, savedAt: Date.now() })); } catch(e) {}
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', seed); else seed();
[250, 900, 1800, 3500].forEach(function(ms){ window.setTimeout(seed, ms); });
document.addEventListener('click', function(e){
if (!(e.target && e.target.closest)) return;
if (e.target.closest('.cp-hybrid-option, .cp-product-config-card, button, input[type="submit"], a')) window.setTimeout(seed, 30);
}, true);
})();
/* === END CP-CONNECT-WR-SEED-CHECKOUT-NOTE-INLINE 2026-08-03 === */
/* === BEGIN CP-SADLER-STALE-CONFIG-PURGE 2026-08-03 === */
/* Global heal: removes old-format saddle-config localStorage left over from earlier
card versions (note text containing 'læderfarve', 'bomtype, paneltype' or
'bomvidde 3,') that no current card produces. Runs on every page (inline in page
HTML, never cached) so returning visitors self-heal immediately. On the checkout
page it also strips an old-format auto-filled note line from the comment field.
Product cards then re-seed the correct value. Idempotent. */
(function(){
var OLD = /læderfarve|bomtype,\s*paneltype|bomvidde\s*3,/i;
function isOld(raw){ try { var o = JSON.parse(raw); return !!(o && o.text && OLD.test(o.text)); } catch(e){ return OLD.test(raw || ''); } }
function purge(){
try {
var kill = [];
for (var i = 0; i < localStorage.length; i++) {
var k = localStorage.key(i);
if (/^cp.*Config/i.test(k) && isOld(localStorage.getItem(k))) kill.push(k);
}
kill.forEach(function(k){ localStorage.removeItem(k); });
} catch(e) {}
}
function cleanCheckout(){
var field = document.getElementById('checkout_comment');
if (!field) return;
var lines = String(field.value || '').split(/\n{2,}/);
var kept = lines.filter(function(l){ return !OLD.test(l); });
var next = kept.join('\n\n');
if (next !== field.value) {
field.value = next;
field.dispatchEvent(new Event('input', { bubbles: true }));
field.dispatchEvent(new Event('change', { bubbles: true }));
}
}
function run(){ purge(); if (/\/checkout/.test(location.pathname)) { cleanCheckout(); [300, 900, 1800].forEach(function(ms){ window.setTimeout(cleanCheckout, ms); }); } }
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', run); else run();
window.setTimeout(run, 200);
})();
/* === END CP-SADLER-STALE-CONFIG-PURGE 2026-08-03 === */