/*! https://github.com/robiveli/jpopup */ !function(e,n){void 0===e&&void 0!==window&&(e=window),"function"==typeof define&&define.amd?define([],function(){return e.jPopup=n()}):"object"==typeof module&&module.exports?module.exports=n():e.jPopup=n()}(this,function(){"use strict";var n,o,t=function(){var e=0\n \n
'.concat(e,"
\n ")))},s=function(e){1==e?window.location.hash=o:window.history.back()},d=function(e){27==e.keyCode&&t.prototype.close(!0)},c=function(){window.location.hash!==o&&t.prototype.close(!1)},a=function(){document.getElementsByClassName("jCloseBtn")[0].addEventListener("click",function(){t.prototype.close(!0)}),window.addEventListener("keydown",d),1==n&&window.addEventListener("hashchange",c)},u=document.querySelector("html");return t.prototype={close:function(e){u.classList.add("jPopupClosed"),1==n&&(e&&s(!1),window.removeEventListener("hashchange",c)),window.removeEventListener("keydown",d),document.getElementsByClassName("jPopup")[0].addEventListener("animationend",function(e){e.target.parentNode.removeChild(this),u.classList.remove("jPopupClosed"),u.classList.remove("jPopupOpen")})},open:function(e){t(e)}},t}); if (document.currentScript) { window.LNTIP_HOST = document.currentScript.getAttribute('lntip-host'); } LnTip = function (amount, memo, host) { this.host = host || window.LNTIP_HOST; this.amount = amount; this.memo = memo || ''; this.getInvoice(); } LnTip.prototype.loadStylesheet = function () { if (document.getElementById('lntip-style')) { return; } var head = document.getElementsByTagName('head')[0]; var css = document.createElement('link'); css.id = "lntip-style"; css.rel = "stylesheet"; css.type = "text/css"; css.href = `${this.host}/static/lntip.css`; head.appendChild(css); } LnTip.prototype.closePopup = function () { if (this.popup) { this.popup.close(); this.popup = null; } } LnTip.prototype.openPopup = function (content) { this.loadStylesheet(); this.closePopup(); this.popup = new jPopup({ content: content, shouldSetHash: false }); return this.popup; } LnTip.prototype.thanks = function () { if (window.lntipPopup) { window.lntipPopup.close(); window.lntipPopup = null; } var content = '

Thank you!

'; this.openPopup(content); setTimeout(() => { this.closePopup(); }, 3000); } LnTip.prototype.watchPayment = function () { if (this.paymentWatcher) { window.clearInterval(this.paymentWatcher) } this.paymentWatcher = window.setInterval(() => { this._request(`${this.host}/settled/${this.invoice.ImplDepID}`) .then((settled) => { if (settled) { this.invoice.settled = true; this.thanks(); this.stopWatchingPayment(); } }) }, 1000); } LnTip.prototype.stopWatchingPayment = function () { window.clearInterval(this.paymentWatcher); this.paymentWatcher = null; } LnTip.prototype.payWithWebln = function () { if (!webln.isEnabled) { webln.enable().then((weblnResponse) => { return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest }) }).catch((e) => { this.requestPayment(); }) } else { return webln.sendPayment({ paymentRequest: this.invoice.PaymentRequest }) } } LnTip.prototype.requestPayment = function () { var content = `

${this.memo}

${this.amount} satoshi

` this.openPopup(content); document.getElementById('lntip-copy').onclick = function() { navigator.clipboard.writeText(invoice.PaymentRequest); alert('Copied to clipboad'); } return Promise.resolve(); } LnTip.prototype.getInvoice = function () { var args = { method: 'POST', mode: 'cors', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ memo: this.memo, amount: this.amount }) }; return this._request( `${this.host}/invoice`, args ).then((invoice) => { this.invoice = invoice; this.watchPayment(); if (typeof webln !== 'undefined') { this.payWithWebln(); } else { this.requestPayment(); } }) } LnTip.prototype._request = function(url, args) { return fetch(url, args).then((response) => { return response.json(); }) }