- Tor onion: mc6wfeaqc7oijgdcudrr5zsotmwok3jzk3tu2uezzyjisn7nzzjjizyd.onion - Onion link in footer and README - PDF "BEZAHLT" block shows TX hash + date in second line - Address placeholder 8... (encourages subaddress usage)
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
(function(){"use strict";const St="/api/rates.php",It=/^[48][1-9A-HJ-NP-Za-km-z]{94}$/,_t=/^4[1-9A-HJ-NP-Za-km-z]{105}$/;let y=null,lt=0,_=null,B=!1,T=null;const i=e=>document.querySelector(e),u=i("#addr"),L=i("#amount"),w=i("#currency"),H=i("#desc"),F=i("#timerCustom"),M=i("#deadlineBadges");let f=0;const tt=i("#generate"),U=i("#result"),v=i("#qr"),et=i("#uri"),dt=i("#openWallet"),Tt=i("#copyAddr"),S=i("#countdown"),h=i("#fiatHint"),nt=i("#toast"),q=i("#shareLink"),Ft=i("#copyShareLink"),Et=i("#newRequest"),Rt=i("#homeLink"),bt=i("#proofToggle"),N=i("#proofPanel"),E=i("#txHash"),O=i("#txKey"),R=i("#verifyProof"),m=i("#proofResult"),W=i("#paymentStatus"),ut=i("#paymentSummary"),Pt=i("#downloadPdf");let ft=!1,kt=!1,g=null;xt(),qt()||Bt(),Ut(),I18n.onChange(function(){var e=v.querySelector(".qr-hint");e&&(e.textContent=I18n.t("qr_hint"));var t=v.querySelector(".paid-stamp");if(t&&(t.textContent=I18n.t("status_paid")),g&&rt(g),U.classList.contains("visible")){var n=ot(),a=H.value.trim();pt(n,a,f),ht(n,a)}}),u.addEventListener("input",at),L.addEventListener("input",G),w.addEventListener("change",G),tt.addEventListener("click",mt),Tt.addEventListener("click",()=>gt(u.value.trim())),Ft.addEventListener("click",()=>gt(q.value)),v.addEventListener("click",At),Et.addEventListener("click",vt),Rt.addEventListener("click",function(e){e.preventDefault(),vt()}),M.querySelectorAll(".badge").forEach(function(e){e.addEventListener("click",function(){const t=parseInt(e.getAttribute("data-days"));e.classList.contains("active")?(e.classList.remove("active"),f=0,F.value=""):(M.querySelectorAll(".badge").forEach(function(n){n.classList.remove("active")}),e.classList.add("active"),f=t,F.value="")})}),F.addEventListener("input",function(){M.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),f=parseInt(F.value)||0}),Pt.addEventListener("click",Wt),bt.addEventListener("click",Gt),E.addEventListener("input",Ct),O.addEventListener("input",Ct),R.addEventListener("click",Yt);function vt(){u.value="",L.value="",w.value="EUR",H.value="",f=0,F.value="",M.querySelectorAll(".badge").forEach(function(e){e.classList.remove("active")}),h.textContent="",h.classList.remove("error"),u.classList.remove("valid","invalid"),tt.disabled=!0,U.classList.remove("visible"),_&&clearInterval(_),v.innerHTML="",et.textContent="",q.value="",T=null,N.classList.remove("open"),E.value="",O.value="",R.disabled=!0,m.innerHTML="",m.className="proof-result",W.innerHTML="",W.className="payment-status",ut.innerHTML="",document.title="xmrpay.link \u2014 Monero Invoice Generator",history.replaceState(null,"",location.pathname),window.scrollTo({top:0,behavior:"smooth"}),u.focus()}function A(e){return It.test(e)||_t.test(e)}function at(){const e=u.value.trim();u.classList.remove("valid","invalid"),e.length!==0&&(A(e)?u.classList.add("valid"):e.length>=10&&u.classList.add("invalid"),Xt())}function Xt(){const e=u.value.trim();tt.disabled=!A(e)}function G(){const e=parseFloat(L.value),t=w.value;if(!e||e<=0){h.textContent="",h.classList.remove("error");return}if(t!=="XMR"&&!y){h.textContent=B?I18n.t("rates_offline"):"",h.classList.toggle("error",B);return}if(h.classList.remove("error"),t==="XMR")if(y){const n=(e*y.eur).toFixed(2);h.textContent="\u2248 "+n+" EUR"}else h.textContent="";else{const n=y[t.toLowerCase()];if(n&&n>0){const a=(e/n).toFixed(8);h.textContent="\u2248 "+a+" XMR"}}}function ot(){const e=parseFloat(L.value),t=w.value;if(!e||e<=0)return null;if(t==="XMR")return e;if(y){const n=y[t.toLowerCase()];if(n&&n>0)return e/n}return null}function Dt(e,t,n){let a="monero:"+e;const o=[];return t&&o.push("tx_amount="+t.toFixed(12)),n&&o.push("tx_description="+encodeURIComponent(n)),o.length&&(a+="?"+o.join("&")),a}function Ht(e,t,n,a){const o=new URLSearchParams;return o.set("a",e),t&&o.set("x",t.toFixed(12)),n&&o.set("d",n),a&&o.set("t",a),o.toString()}async function Mt(e){try{const t=await fetch("/api/shorten.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({hash:e})});if(!t.ok)throw new Error("HTTP "+t.status);const n=await t.json();return T||(T=n.code),location.origin+"/s/"+n.code}catch(t){return console.warn("Short URL failed:",t),null}}function mt(){const e=u.value.trim();if(!A(e))return;const t=ot(),n=H.value.trim(),a=f,o=Dt(e,t,n);U.classList.add("visible"),et.textContent=o,dt.onclick=function(){window.location.href=o},pt(t,n,a),ht(t,n);const c=Ht(e,t,n,a);q.value=location.origin+"/#"+c,Mt(c).then(function(l){l&&(q.value=l)}),v.innerHTML="",new QRCode(v,{text:o,width:256,height:256,colorDark:"#000000",colorLight:"#ffffff",correctLevel:QRCode.CorrectLevel.M});const d=document.createElement("div");d.className="qr-hint",d.textContent=I18n.t("qr_hint"),v.appendChild(d),Nt(),zt(e),U.scrollIntoView({behavior:"smooth",block:"start"})}function qt(){const e=location.hash.substring(1);if(!e)return!1;const t=new URLSearchParams(e),n=t.get("a");if(!n||!A(n))return!1;u.value=n,at();const a=t.get("x");a&&(L.value=parseFloat(a),w.value="XMR");const o=t.get("d");o&&(H.value=o);const c=t.get("t");if(c&&parseInt(c)>0){f=parseInt(c);const l=M.querySelector('.badge[data-days="'+f+'"]');l?l.classList.add("active"):F.value=f}const d=t.get("c");return d&&(T=d,setTimeout(function(){Jt(d)},200)),setTimeout(mt,100),!0}function pt(e,t,n){var a="";if(e){a+='<div class="summary-amount">'+e.toFixed(8)+" XMR</div>";var o=parseFloat(L.value),c=w.value;c!=="XMR"&&o&&(a+='<div class="summary-fiat">\u2248 '+o.toFixed(2)+" "+c+"</div>")}t&&(a+='<div class="summary-desc">'+t.replace(/</g,"<")+"</div>"),ut.innerHTML=a}function ht(e,t){var n=[];e&&n.push(e.toFixed(4)+" XMR"),t&&n.push(t),n.length&&(document.title=n.join(" \u2014 ")+" | xmrpay.link")}function Nt(){if(_&&clearInterval(_),S.textContent="",S.className="countdown",!f||f<=0)return;const e=Date.now()+f*864e5;S.classList.add("active");function t(){const n=e-Date.now();if(n<=0){clearInterval(_),S.textContent=I18n.t("countdown_expired"),S.className="countdown expired";return}const a=Math.floor(n/864e5),o=Math.floor(n%864e5/36e5),c=Math.floor(n%36e5/6e4);a>0?S.textContent=I18n.t("countdown_remaining_days").replace("{d}",a).replace("{h}",o):S.textContent=I18n.t("countdown_remaining_hours").replace("{h}",yt(o)).replace("{m}",yt(c))}t(),_=setInterval(t,6e4)}function yt(e){return e<10?"0"+e:""+e}function At(){const e=v.querySelector("canvas");if(!e)return;const t=document.createElement("a");t.download="xmrpay-qr.png",t.href=e.toDataURL("image/png"),t.click()}function gt(e){navigator.clipboard.writeText(e).then(()=>{jt(I18n.t("toast_copied"))})}function jt(e){nt.textContent=e,nt.classList.add("show"),setTimeout(()=>nt.classList.remove("show"),2e3)}function zt(e){try{localStorage.setItem("xmrpay_addr",e)}catch{}}function Bt(){try{const e=localStorage.getItem("xmrpay_addr");e&&(u.value=e,at())}catch{}}async function xt(){if(!(y&&Date.now()-lt<6e4))try{const e=await fetch(St);if(!e.ok)throw new Error("HTTP "+e.status);y=(await e.json()).monero,lt=Date.now(),B=!1,G()}catch(e){console.warn("Kurse konnten nicht geladen werden:",e),B=!0,G(),setTimeout(xt,1e4)}}function Ut(){"serviceWorker"in navigator&&navigator.serviceWorker.register("sw.js").catch(function(){})}function Ot(){return new Promise(function(e,t){if(window.jspdf){e();return}var n=document.createElement("script");n.src="lib/jspdf.min.js",n.onload=function(){kt=!0,e()},n.onerror=function(){t(new Error("Failed to load jsPDF"))},document.head.appendChild(n)})}async function Wt(){await Ot();var e=window.jspdf.jsPDF,t=new e({orientation:"portrait",unit:"mm",format:"a4"}),n=u.value.trim(),a=ot(),o=H.value.trim(),c=parseFloat(L.value),d=w.value,l=t.internal.pageSize.getWidth(),s=20,x=l-s*2,r=s;t.setFillColor(242,104,33),t.rect(0,0,l,8,"F"),r=22,t.setFont("helvetica","bold"),t.setFontSize(22),t.setTextColor(242,104,33),t.text(I18n.t("pdf_title"),s,r),t.setFont("helvetica","normal"),t.setFontSize(10),t.setTextColor(120,120,120);var it=new Date().toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});t.text(I18n.t("pdf_date")+": "+it,l-s,r,{align:"right"}),r+=6,t.setDrawColor(220,220,220),t.setLineWidth(.3),t.line(s,r,l-s,r);var Y=v.querySelector("canvas"),C=50,b=l-s-C,j=r+6;if(Y){var J=Y.toDataURL("image/png");t.addImage(J,"PNG",b,j,C,C),t.setFontSize(7),t.setTextColor(150,150,150),t.text(I18n.t("pdf_scan_qr"),b+C/2,j+C+4,{align:"center"})}var P=s,V=b-s-10;r+=14;function k($t,Qt){t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text($t,P,r),r+=5,t.setFont("helvetica","bold"),t.setFontSize(11),t.setTextColor(40,40,40);var wt=t.splitTextToSize(Qt,V);t.text(wt,P,r),r+=wt.length*5+4}if(a){var p=a.toFixed(8)+" XMR";d!=="XMR"&&c&&(p+=" (~ "+c.toFixed(2)+" "+d+")"),k(I18n.t("pdf_amount"),p)}if(o&&k(I18n.t("pdf_desc"),o),f>0){var I=new Date(Date.now()+f*864e5),$=I.toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"});k(I18n.t("pdf_deadline"),$+" ("+I18n.t("pdf_deadline_days").replace("{d}",f)+")")}r=Math.max(r,j+C+12),t.setFont("helvetica","normal"),t.setFontSize(9),t.setTextColor(150,150,150),t.text(I18n.t("pdf_address"),s,r),r+=5,t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,x,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(8),t.setTextColor(60,60,60),t.text(n,s+3,r+2.5),r+=14;var Q=et.textContent;if(Q){t.setFillColor(245,245,245),t.roundedRect(s,r-3.5,x,10,2,2,"F"),t.setFont("courier","normal"),t.setFontSize(6.5),t.setTextColor(100,100,100);var Z=t.splitTextToSize(Q,x-6);t.text(Z,s+3,r+2),r+=Z.length*3+10}if(g){r+=4;var z="";if(g.verified_at){var st=new Date(g.verified_at*1e3);z=st.toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"})}var ct=g.amount.toFixed(6)+" XMR \u2014 TX "+g.tx_hash.substring(0,8)+"..."+(z?" \u2014 "+z:"");t.setFillColor(76,175,80),t.roundedRect(s,r-4,x,16,2,2,"F"),t.setFont("helvetica","bold"),t.setFontSize(12),t.setTextColor(255,255,255),t.text(I18n.t("status_paid").toUpperCase(),s+x/2,r+1,{align:"center"}),t.setFont("helvetica","normal"),t.setFontSize(7.5),t.text(ct,s+x/2,r+7,{align:"center"}),r+=22}t.setDrawColor(220,220,220),t.setLineWidth(.3);var X=t.internal.pageSize.getHeight()-15;t.line(s,X,l-s,X),t.setFont("helvetica","normal"),t.setFontSize(7),t.setTextColor(180,180,180),t.text(I18n.t("pdf_footer"),l/2,X+5,{align:"center"});var D=q.value;D&&t.text(D,l/2,X+9,{align:"center"});var Lt="xmrpay-"+(o?o.replace(/[^a-zA-Z0-9]/g,"-").substring(0,30):"invoice")+".pdf";t.save(Lt)}function Gt(){if(N.classList.contains("open")){N.classList.remove("open");return}if(!ft&&!window.XmrCrypto){Kt().then(function(){ft=!0,N.classList.add("open"),E.focus()});return}N.classList.add("open"),E.focus()}function Kt(){return new Promise(function(e,t){if(window.XmrCrypto){e();return}const n=document.createElement("script");n.src="lib/xmr-crypto.bundle.js",n.onload=e,n.onerror=function(){t(new Error("Failed to load crypto module"))},document.head.appendChild(n)})}function K(e){return/^[0-9a-fA-F]{64}$/.test(e)}function Ct(){const e=E.value.trim(),t=O.value.trim();R.disabled=!(K(e)&&K(t))}async function Yt(){const e=E.value.trim(),t=O.value.trim(),n=u.value.trim();if(!(!K(e)||!K(t)||!A(n))){R.disabled=!0,m.className="proof-result active",m.textContent=I18n.t("proof_verifying");try{var a=await fetch("/api/node.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({method:"gettransactions",params:{txs_hashes:[e],decode_as_json:!0}})}),o=await a.json(),c=o.txs||[];if(c.length===0){m.className="proof-result active error",m.textContent=I18n.t("proof_tx_not_found"),R.disabled=!1;return}for(var d=c[0],l=JSON.parse(d.as_json),s=XmrCrypto.getKeysFromAddress(n),x=s.publicViewKey,r=s.publicSpendKey,it=XmrCrypto.bytesToScalar(XmrCrypto.hexToBytes(t)),Y=XmrCrypto.Point.fromHex(x),C=Y.multiply(it).multiply(8n),b=C.toBytes(),j=XmrCrypto.Point.fromHex(r),J=l.vout||[],P=l.rct_signatures&&l.rct_signatures.ecdhInfo||[],V=0n,k=!1,p=0;p<J.length;p++){var I=J[p],$=I.target&&I.target.tagged_key?I.target.tagged_key.key:I.target&&I.target.key;if($){var Q=XmrCrypto.encodeVarint(p),Z=XmrCrypto.hashToScalar(XmrCrypto.concat(b,Q)),z=XmrCrypto.bytesToScalar(Z),st=XmrCrypto.Point.BASE.multiply(z).add(j),ct=XmrCrypto.bytesToHex(st.toBytes());if(ct===$&&(k=!0,P[p]&&P[p].amount)){var X=XmrCrypto.decodeRctAmount(P[p].amount,b,p);V+=X}}}if(k){var D=Number(V)/1e12;m.className="proof-result active success",m.textContent=I18n.t("proof_verified").replace("{amount}",D.toFixed(6)),T&&await fetch("/api/verify.php",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:T,tx_hash:e,amount:D,confirmations:d.confirmations||0})}),rt({amount:D,tx_hash:e})}else m.className="proof-result active error",m.textContent=I18n.t("proof_no_match")}catch{m.className="proof-result active error",m.textContent=I18n.t("proof_error")}R.disabled=!1}}function Jt(e){fetch("/api/verify.php?code="+encodeURIComponent(e)).then(function(t){return t.json()}).then(function(t){t.verified&&rt(t)}).catch(function(){})}function rt(e){W.className="payment-status paid",v.classList.add("paid");var t=v.querySelector(".paid-stamp");if(t)t.textContent=I18n.t("status_paid");else{var n=document.createElement("div");n.className="paid-stamp",n.textContent=I18n.t("status_paid"),v.appendChild(n)}var a=v.querySelector(".qr-hint");if(a){var o="";if(e.verified_at){var c=new Date(e.verified_at*1e3);o=" \u2014 "+c.toLocaleDateString(I18n.getLang()==="de"?"de-CH":"en-US",{year:"numeric",month:"long",day:"numeric"})}a.textContent=e.amount.toFixed(6)+" XMR \u2014 TX "+e.tx_hash.substring(0,8)+"..."+o,a.className="qr-hint paid-info"}W.innerHTML="",g=e,dt.style.display="none",document.getElementById("copyAddr").style.display="none";var d=document.getElementById("proofSection");d&&(d.style.display="none"),Vt()}function Vt(){var e=document.createElement("canvas");e.width=32,e.height=32;var t=e.getContext("2d"),n=new Image;n.onload=function(){t.drawImage(n,0,0,32,32),t.beginPath(),t.arc(25,25,7,0,Math.PI*2),t.fillStyle="#fff",t.fill(),t.beginPath(),t.arc(25,25,5.5,0,Math.PI*2),t.fillStyle="#4caf50",t.fill();var a=document.getElementById("favicon");a.href=e.toDataURL("image/png")},n.src="favicon.svg"}})();
|