From 67db593d3398a8791bf1f0bf7fb3f175cb9efb65 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 9 Oct 2025 17:23:37 -0300 Subject: [PATCH] v --- public/buyModal.js | 1 + public/buyModal.min.js | 2 +- public/tryModal.js | 1 + public/tryModal.min.js | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/public/buyModal.js b/public/buyModal.js index afc7ce3..01f1f86 100644 --- a/public/buyModal.js +++ b/public/buyModal.js @@ -73,6 +73,7 @@ function createModal() { + diff --git a/public/buyModal.min.js b/public/buyModal.min.js index 7690326..d19201a 100644 --- a/public/buyModal.min.js +++ b/public/buyModal.min.js @@ -1 +1 @@ -const CATEGORY_CONFIG={3:{showLocation:!1,webhook:""},4:{showLocation:!0,webhook:"https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c76e6b4e-af2f-4bc3-9875-6460d0ffc8e3"},5:{showLocation:!1,webhook:"https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/fd20e194-b821-4b1f-814f-7bb93ae16046"},7:{showLocation:!1,webhook:""}};function getCookie(e){const t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):null}function setCookieIfEmpty(e,t,o=90){if(!t)return;if(getCookie(e))return;const n=new Date;n.setTime(n.getTime()+24*o*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(t)}; expires=${n.toUTCString()}; path=/; SameSite=Lax`}function addUtmFields(e){const t={utm_source:"homepage",utm_medium:"direct",utm_campaign:"none",utm_term:"",utm_content:""};["utm_source","utm_medium","utm_campaign","utm_term","utm_content"].forEach(o=>{let n=e.querySelector(`input[name="${o}"]`);n||(n=document.createElement("input"),n.type="hidden",n.name=o,e.appendChild(n)),n.value=getCookie(o)||t[o]})}function createModal(){const e=document.createElement("div");return e.id="buyNowModal",Object.assign(e.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",backgroundColor:"rgba(0,0,0,0.6)",display:"none",justifyContent:"center",alignItems:"center",zIndex:"1000"}),e.innerHTML='\n
\n ×\n

Order Details

\n

\n\n
\n \n\n \n \n \n \n
\n \n \n
\n \n \n \n \n \n\n \n
\n\n \n
\n ',document.body.appendChild(e),document.getElementById("closeModal").onclick=()=>e.style.display="none",document.getElementById("closeConfirmation").onclick=()=>{document.getElementById("confirmation").style.display="none",e.style.display="none"},e.onclick=t=>{t.target===e&&(e.style.display="none")},e}function openModal(e){const t=document.getElementById("buyNowModal"),o=t.querySelector("#buyForm"),n=t.querySelector("#confirmation");t.style.display="flex",o.style.display="flex",n.style.display="none";const i=e.split("/").filter(Boolean),[r,d,a,...p]=i,c=decodeURIComponent(p.join("/")),l=parseInt(a,10),s=CATEGORY_CONFIG[l]||{showLocation:!1,webhook:""},u=document.getElementById("locationSelect");s.showLocation?(u.style.display="block",u.setAttribute("required","true")):(u.style.display="none",u.removeAttribute("required"),u.value=""),o.querySelector('input[name="id"]').value=r||"",o.querySelector('input[name="price"]').value=d||"0",o.querySelector('input[name="category"]').value=a||"",o.querySelector('input[name="product"]').value=c||"Unknown",o.dataset.webhook=s.webhook||"",t.querySelector("#productText").textContent=`You will buy ${c} for $${d}.`,addUtmFields(o)}function handleFormSubmit(){const e=document.getElementById("buyForm"),t=document.getElementById("confirmation");e.addEventListener("submit",async o=>{o.preventDefault(),addUtmFields(e);const n=Object.fromEntries(new FormData(e).entries()),i=e.dataset.webhook;if(i)try{(await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).ok?(e.style.display="none",t.style.display="block",e.reset()):alert("Failed to submit form.")}catch(e){console.error(e),alert("Error submitting form.")}else alert("No webhook configured for this category.")})}function attachButtons(){Array.from(document.querySelectorAll("button, a")).forEach(e=>{const t=e.textContent.trim();"Buy Now"!==t&&"Book Now"!==t||e.addEventListener("click",t=>{t.preventDefault();openModal(e.getAttribute("href")||e.dataset.product||"Unknown/0/0")})})}document.addEventListener("DOMContentLoaded",()=>{createModal(),handleFormSubmit(),attachButtons()}); \ No newline at end of file +const CATEGORY_CONFIG={3:{showLocation:!1,webhook:""},4:{showLocation:!0,webhook:"https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c76e6b4e-af2f-4bc3-9875-6460d0ffc8e3"},5:{showLocation:!1,webhook:"https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/fd20e194-b821-4b1f-814f-7bb93ae16046"},7:{showLocation:!1,webhook:""}};function getCookie(e){const t=document.cookie.match(new RegExp("(^| )"+e+"=([^;]+)"));return t?decodeURIComponent(t[2]):null}function setCookieIfEmpty(e,t,o=90){if(!t)return;if(getCookie(e))return;const n=new Date;n.setTime(n.getTime()+24*o*60*60*1e3),document.cookie=`${e}=${encodeURIComponent(t)}; expires=${n.toUTCString()}; path=/; SameSite=Lax`}function addUtmFields(e){const t={utm_source:"homepage",utm_medium:"direct",utm_campaign:"none",utm_term:"",utm_content:""};["utm_source","utm_medium","utm_campaign","utm_term","utm_content"].forEach(o=>{let n=e.querySelector(`input[name="${o}"]`);n||(n=document.createElement("input"),n.type="hidden",n.name=o,e.appendChild(n)),n.value=getCookie(o)||t[o]})}function createModal(){const e=document.createElement("div");return e.id="buyNowModal",Object.assign(e.style,{position:"fixed",top:"0",left:"0",width:"100%",height:"100%",backgroundColor:"rgba(0,0,0,0.6)",display:"none",justifyContent:"center",alignItems:"center",zIndex:"1000"}),e.innerHTML='\n
\n ×\n

Order Details

\n

\n\n
\n \n\n \n \n \n \n
\n \n \n
\n \n \n \n \n \n\n \n
\n\n \n
\n ',document.body.appendChild(e),document.getElementById("closeModal").onclick=()=>e.style.display="none",document.getElementById("closeConfirmation").onclick=()=>{document.getElementById("confirmation").style.display="none",e.style.display="none"},e.onclick=t=>{t.target===e&&(e.style.display="none")},e}function openModal(e){const t=document.getElementById("buyNowModal"),o=t.querySelector("#buyForm"),n=t.querySelector("#confirmation");t.style.display="flex",o.style.display="flex",n.style.display="none";const i=e.split("/").filter(Boolean),[r,d,a,...p]=i,c=decodeURIComponent(p.join("/")),l=parseInt(a,10),s=CATEGORY_CONFIG[l]||{showLocation:!1,webhook:""},u=document.getElementById("locationSelect");s.showLocation?(u.style.display="block",u.setAttribute("required","true")):(u.style.display="none",u.removeAttribute("required"),u.value=""),o.querySelector('input[name="id"]').value=r||"",o.querySelector('input[name="price"]').value=d||"0",o.querySelector('input[name="category"]').value=a||"",o.querySelector('input[name="product"]').value=c||"Unknown",o.dataset.webhook=s.webhook||"",t.querySelector("#productText").textContent=`You will buy ${c} for $${d}.`,addUtmFields(o)}function handleFormSubmit(){const e=document.getElementById("buyForm"),t=document.getElementById("confirmation");e.addEventListener("submit",async o=>{o.preventDefault(),addUtmFields(e);const n=Object.fromEntries(new FormData(e).entries()),i=e.dataset.webhook;if(i)try{(await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)})).ok?(e.style.display="none",t.style.display="block",e.reset()):alert("Failed to submit form.")}catch(e){console.error(e),alert("Error submitting form.")}else alert("No webhook configured for this category.")})}function attachButtons(){Array.from(document.querySelectorAll("button, a")).forEach(e=>{const t=e.textContent.trim();"Buy Now"!==t&&"Book Now"!==t||e.addEventListener("click",t=>{t.preventDefault();openModal(e.getAttribute("href")||e.dataset.product||"Unknown/0/0")})})}document.addEventListener("DOMContentLoaded",()=>{createModal(),handleFormSubmit(),attachButtons()}); \ No newline at end of file diff --git a/public/tryModal.js b/public/tryModal.js index ca39914..61a7440 100644 --- a/public/tryModal.js +++ b/public/tryModal.js @@ -76,6 +76,7 @@ function tryNow_createModal() { + \n\n \n\n \n\n \n \n\n
\n

Thank you for your submission! 🎉

\n \n
\n \n ',document.body.appendChild(n);return addUtmFields(n.querySelector("#trynowForm")),document.getElementById("trynowCloseModal").onclick=()=>{n.style.display="none"},document.getElementById("trynowCloseConfirmation").onclick=()=>{document.getElementById("trynowConfirmation").style.display="none",n.style.display="none"},n.onclick=t=>{t.target===n&&(n.style.display="none")},n}function tryNow_handleFormSubmit(){const n=document.getElementById("trynowForm"),t=document.getElementById("trynowConfirmation");n.addEventListener("submit",async e=>{e.preventDefault(),addUtmFields(n);const o={};new FormData(n).forEach((n,t)=>o[t]=n);try{(await fetch(TRYNOW_WEBHOOK_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})).ok?(n.style.display="none",t.style.display="block",n.reset()):alert("Failed to submit form.")}catch(n){console.error(n),alert("Error submitting form.")}})}function tryNow_attachButtons(){Array.from(document.querySelectorAll("a, button")).forEach(n=>{n.textContent&&"Try Now"===n.textContent.trim()&&n.addEventListener("click",n=>{n.preventDefault();const t=document.getElementById("trynowModal");if(t){t.style.display="flex";const n=document.getElementById("trynowForm"),e=document.getElementById("trynowConfirmation");n&&e&&(n.style.display="flex",e.style.display="none",addUtmFields(n))}})})}document.addEventListener("DOMContentLoaded",()=>{tryNow_createModal(),tryNow_handleFormSubmit(),tryNow_attachButtons()}); \ No newline at end of file +const TRYNOW_WEBHOOK_URL="https://002-001-5dd6e535-4d1c-46bc-9bd9-42ad4bc5f082.odoo4projects.com/webhook/c25169c6-4234-4b47-8e74-612b9539da0a";function getCookie(n){const t=`; ${document.cookie}`.split(`; ${n}=`);return 2===t.length?t.pop().split(";").shift():null}function addUtmFields(n){const t={utm_source:"homepage",utm_medium:"direct",utm_campaign:"none"};["utm_source","utm_medium","utm_campaign","utm_term","utm_content"].forEach(e=>{let o=n.querySelector(`input[name="${e}"]`);o||(o=document.createElement("input"),o.type="hidden",o.name=e,n.appendChild(o));const i=getCookie(e);o.value=i||t[e]||""})}function tryNow_createModal(){const n=document.createElement("div");n.id="trynowModal",n.style.position="fixed",n.style.top="0",n.style.left="0",n.style.width="100%",n.style.height="100%",n.style.backgroundColor="rgba(0,0,0,0.6)",n.style.display="none",n.style.justifyContent="center",n.style.alignItems="center",n.style.zIndex="1000",n.innerHTML='\n
\n ×\n \n

Order Details

\n\n
\n \n\n \n\n \n\n \n
\n\n
\n

Thank you for your submission! 🎉

\n \n
\n
\n ',document.body.appendChild(n);return addUtmFields(n.querySelector("#trynowForm")),document.getElementById("trynowCloseModal").onclick=()=>{n.style.display="none"},document.getElementById("trynowCloseConfirmation").onclick=()=>{document.getElementById("trynowConfirmation").style.display="none",n.style.display="none"},n.onclick=t=>{t.target===n&&(n.style.display="none")},n}function tryNow_handleFormSubmit(){const n=document.getElementById("trynowForm"),t=document.getElementById("trynowConfirmation");n.addEventListener("submit",async e=>{e.preventDefault(),addUtmFields(n);const o={};new FormData(n).forEach((n,t)=>o[t]=n);try{(await fetch(TRYNOW_WEBHOOK_URL,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)})).ok?(n.style.display="none",t.style.display="block",n.reset()):alert("Failed to submit form.")}catch(n){console.error(n),alert("Error submitting form.")}})}function tryNow_attachButtons(){Array.from(document.querySelectorAll("a, button")).forEach(n=>{n.textContent&&"Try Now"===n.textContent.trim()&&n.addEventListener("click",n=>{n.preventDefault();const t=document.getElementById("trynowModal");if(t){t.style.display="flex";const n=document.getElementById("trynowForm"),e=document.getElementById("trynowConfirmation");n&&e&&(n.style.display="flex",e.style.display="none",addUtmFields(n))}})})}document.addEventListener("DOMContentLoaded",()=>{tryNow_createModal(),tryNow_handleFormSubmit(),tryNow_attachButtons()}); \ No newline at end of file