From 12b888a67867b3b01b02defff5431b9eea0cc3f9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 4 Oct 2025 18:37:18 -0300 Subject: [PATCH] tryNow --- public/tryNow.js | 157 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 public/tryNow.js diff --git a/public/tryNow.js b/public/tryNow.js new file mode 100644 index 0000000..05b1c3c --- /dev/null +++ b/public/tryNow.js @@ -0,0 +1,157 @@ +const WEBHOOK_URL = "https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c76e6b4e-af2f460d0ffc8e3"; + +function createModal() { + const modal = document.createElement("div"); + modal.id = "buyNowModal"; + modal.style.position = "fixed"; + modal.style.top = "0"; + modal.style.left = "0"; + modal.style.width = "100%"; + modal.style.height = "100%"; + modal.style.backgroundColor = "rgba(0,0,0,0.6)"; + modal.style.display = "none"; + modal.style.justifyContent = "center"; + modal.style.alignItems = "center"; + modal.style.zIndex = "1000"; + + modal.innerHTML = ` +
+ × + +

Order Details

+ +
+ + + + + + + +
+ +
+

Thank you for your submission! 🎉

+ +
+
+ `; + + document.body.appendChild(modal); + + document.getElementById("closeModal").onclick = () => { modal.style.display = "none"; }; + document.getElementById("closeConfirmation").onclick = () => { + document.getElementById("confirmation").style.display = "none"; + modal.style.display = "none"; + }; + modal.onclick = (e) => { if (e.target === modal) modal.style.display = "none"; }; + + return modal; +} + +function openModal() { + document.getElementById("buyNowModal").style.display = "flex"; +} + +function handleFormSubmit() { + const form = document.getElementById("buyForm"); + const confirmation = document.getElementById("confirmation"); + + form.addEventListener("submit", async (e) => { + e.preventDefault(); + + const data = {}; + new FormData(form).forEach((value, key) => (data[key] = value)); + + try { + const res = await fetch(WEBHOOK_URL, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(data) + }); + + if (res.ok) { + form.style.display = "none"; + confirmation.style.display = "block"; + form.reset(); + } else { + alert("Failed to submit form."); + } + } catch (err) { + console.error(err); + alert("Error submitting form."); + } + }); +} + +function attachButtons() { + const buttons = Array.from(document.querySelectorAll("button, a")); + buttons.forEach(btn => { + if (btn.textContent.trim() === "Try Now") { + btn.addEventListener("click", (e) => { + e.preventDefault(); + openModal(); + }); + } + }); +} + +document.addEventListener("DOMContentLoaded", () => { + createModal(); + handleFormSubmit(); + attachButtons(); +}); +