Site Builder
Editing:
businessPromptinator.js
writable 0666
/* BusinessPromptinator – Promptinator with optional business overrides * Requires Promptinator.js to be loaded (or embed equivalent logic here). * Behaviour: * • Works exactly like Promptinator when window.businessData is undefined. * • If window.businessData exists _and_ the current URL ?ph= matches * businessData.phone (10‑digit), then during the first render it will * replace ONLY the recognised business tokens: * name, slogan, description, address, city, state, zip, phone, * website, email, C‑service‑, C‑location‑. * All other tokens / defaults remain untouched. */ export default class BusinessPromptinator { static init({ mount, defaultPrompt = '' }) { const biz = window.businessData || null; const params = new URLSearchParams(window.location.search); const phParam = params.get('ph'); const isBiz = biz && phParam && biz.phone && biz.phone === phParam; /* ---------- embed/require Promptinator core ---------- */ if (!window.__PromptinatorCoreLoaded) { console.error('Promptinator core not found. Make sure promptinator.js is imported before businessPromptinator.js'); return; } // Initialise core const core = window.__PromptinatorCoreLoaded; core.init({ mount, defaultPrompt, businessHook: overrideHook }); /* businessHook(state, meta) called once during first render */ function overrideHook(state, meta) { if (!isBiz) return; // no-op if no matching business meta.forEach((m, i) => { const lab = (m.lab || '').toLowerCase(); switch (lab) { case 'name': state[i] = biz.name; break; case 'slogan': state[i] = biz.slogan; break; case 'description': state[i] = biz.description; break; case 'address': state[i] = biz.address; break; case 'city': state[i] = biz.city; break; case 'state': state[i] = biz.state; break; case 'zip': state[i] = biz.zip; break; case 'phone': state[i] = biz.phone; break; case 'website': state[i] = biz.website; break; case 'email': state[i] = biz.email; break; default: if (m.cmd === 'C') { if (lab.startsWith('service')) { state[i] = Array.isArray(biz.tags) ? biz.tags : state[i]; } if (lab.startsWith('location')) { state[i] = Array.isArray(biz.location_tags) ? biz.location_tags : state[i]; } } } }); } } } /* ------------------------------------------------------------------ * Patch: expose a light wrapper so Promptinator core can register a * businessHook. Modify promptinator.js once to allow an optional * callback after meta + state are built but before render. * Here we monkey‑patch if Promptinator is present globally. */ (function(){ if (window.Promptinator && !window.__PromptinatorCoreLoaded) { const OriginalInit = window.Promptinator.init; window.__PromptinatorCoreLoaded = { init({ mount, defaultPrompt, businessHook }) { OriginalInit.call(window.Promptinator, { mount, defaultPrompt }); if (typeof businessHook === 'function') { /* monkey‑patch render() to inject hook only once */ const comp = mount.querySelector('.prompt-text'); if (comp && !comp.__hooked) { comp.__hooked = true; const renderFn = window.Promptinator.renderMap.get(mount); if (renderFn) { window.Promptinator.renderMap.set(mount, (state, meta) => { if (!renderFn.__hookDone) { businessHook(state, meta); renderFn.__hookDone = true; } renderFn(state, meta); }); } } } } }; } })();
Save changes
Create folder
writable 0777
Create
Cancel