From 95d2c29e7d912c8e60a709372cb19943975dc436 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 23 Oct 2025 11:43:54 -0300 Subject: [PATCH] affiliate Modeal --- public/affiliateModal.js | 96 ++++++++++++++++++++++++++++++++++++ public/affiliateModal.min.js | 1 + public/minify | 1 + 3 files changed, 98 insertions(+) create mode 100644 public/affiliateModal.js create mode 100644 public/affiliateModal.min.js diff --git a/public/affiliateModal.js b/public/affiliateModal.js new file mode 100644 index 0000000..24cfc7a --- /dev/null +++ b/public/affiliateModal.js @@ -0,0 +1,96 @@ +// --- Create Affiliate Modal --- +function createAffiliateModal() { + const modal = document.createElement("div"); + modal.id = "affiliateBuilder"; + Object.assign(modal.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" + }); + + modal.innerHTML = ` +
+ × +

Affiliate Builder

+ +
+ + +
+
+ + +
+ +
+ + +
+
+ `; + + document.body.appendChild(modal); + + // Close modal + document.getElementById("closeAffiliateModal").onclick = () => modal.style.display = "none"; + modal.onclick = e => { if (e.target === modal) modal.style.display = "none"; }; + + // Build link when inputs change + const codeInput = document.getElementById("affiliateCode"); + const campaignInput = document.getElementById("affiliateCampaign"); + const linkInput = document.getElementById("affiliateLink"); + [codeInput, campaignInput].forEach(input => { + input.addEventListener("input", () => { + const code = codeInput.value.trim() || "affiliate"; + const campaign = campaignInput.value.trim() || "default"; + linkInput.value = `https://ODOO4projects.com?utm_source=${encodeURIComponent(code)}&utm_campaign=${encodeURIComponent(campaign)}`; + }); + }); + + // Copy to clipboard + document.getElementById("copyAffiliateLink").addEventListener("click", () => { + linkInput.select(); + document.execCommand("copy"); + alert("Affiliate link copied!"); + }); + + return modal; +} + +// --- Open Affiliate Modal --- +function openAffiliateModal() { + const modal = document.getElementById("affiliateBuilder"); + modal.style.display = "flex"; + // Reset fields + document.getElementById("affiliateCode").value = ""; + document.getElementById("affiliateCampaign").value = ""; + document.getElementById("affiliateLink").value = ""; +} + +// --- Attach Affiliate Builder Buttons --- +function attachAffiliateButtons() { + const buttons = Array.from(document.querySelectorAll("button, a")); + buttons.forEach(btn => { + const text = btn.textContent.trim(); + if (text === "Start Selling") { + btn.addEventListener("click", (e) => { + e.preventDefault(); + openAffiliateModal(); + }); + } + }); +} + +// --- Initialize Affiliate Builder --- +document.addEventListener("DOMContentLoaded", () => { + createAffiliateModal(); + attachAffiliateButtons(); +}); + diff --git a/public/affiliateModal.min.js b/public/affiliateModal.min.js new file mode 100644 index 0000000..47ab2fe --- /dev/null +++ b/public/affiliateModal.min.js @@ -0,0 +1 @@ +function createAffiliateModal(){const e=document.createElement("div");e.id="affiliateBuilder",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

Affiliate Builder

\n \n
\n \n \n
\n
\n \n \n
\n\n
\n \n \n
\n
\n ',document.body.appendChild(e),document.getElementById("closeAffiliateModal").onclick=()=>e.style.display="none",e.onclick=t=>{t.target===e&&(e.style.display="none")};const t=document.getElementById("affiliateCode"),i=document.getElementById("affiliateCampaign"),n=document.getElementById("affiliateLink");return[t,i].forEach(e=>{e.addEventListener("input",()=>{const e=t.value.trim()||"affiliate",o=i.value.trim()||"default";n.value=`https://ODOO4projects.com?utm_source=${encodeURIComponent(e)}&utm_campaign=${encodeURIComponent(o)}`})}),document.getElementById("copyAffiliateLink").addEventListener("click",()=>{n.select(),document.execCommand("copy"),alert("Affiliate link copied!")}),e}function openAffiliateModal(){document.getElementById("affiliateBuilder").style.display="flex",document.getElementById("affiliateCode").value="",document.getElementById("affiliateCampaign").value="",document.getElementById("affiliateLink").value=""}function attachAffiliateButtons(){Array.from(document.querySelectorAll("button, a")).forEach(e=>{"Start Selling"===e.textContent.trim()&&e.addEventListener("click",e=>{e.preventDefault(),openAffiliateModal()})})}document.addEventListener("DOMContentLoaded",()=>{createAffiliateModal(),attachAffiliateButtons()}); \ No newline at end of file diff --git a/public/minify b/public/minify index f9d3cf5..f4d72ea 100755 --- a/public/minify +++ b/public/minify @@ -4,3 +4,4 @@ npm install -g terser terser buyModal.js -o buyModal.min.js -c -m terser tryModal.js -o tryModal.min.js -c -m terser setCookie.js -o setCookie.min.js -c -m +terser affiliateModal.js -o affiliateModal.min.js -c -m