console.log("Acuity intercept script loaded"); (function() { const origOpen = XMLHttpRequest.prototype.open; const origSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.open = function(method, url) { this._acuityUrl = url; return origOpen.apply(this, arguments); }; XMLHttpRequest.prototype.send = function() { this.addEventListener("load", function() { try { if (this._acuityUrl && this._acuityUrl.includes("/api/scheduling/v1/appointments")) { const response = JSON.parse(this.responseText); if (response && response.appointments && response.appointments.length > 0) { const appt = response.appointments[0]; const first = encodeURIComponent(appt.firstName || ""); const last = encodeURIComponent(appt.lastName || ""); const email = encodeURIComponent(appt.email || ""); const phone = encodeURIComponent(appt.phone || ""); const datetime = encodeURIComponent(appt.datetime || ""); const type = encodeURIComponent(appt.type || ""); const redirectUrl = "/schedule-pay-form-brisbane" + "?first=" + first + "&last=" + last + "&email=" + email + "&phone=" + phone + "&datetime=" + datetime + "&type=" + type; console.log("Redirecting with Acuity data:", redirectUrl); window.location.href = redirectUrl; } } } catch (e) { console.error("Error parsing Acuity response:", e); } }); return origSend.apply(this, arguments); }; })();