paywall-js
Version:
Simple payment reminder - makes websites fade out when payment is overdue
3 lines (2 loc) • 3.72 kB
JavaScript
!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";function e(e){if(this.config={dueDate:null,daysDeadline:60,effect:"gradient",color:"#ff0000",gradientFrom:"#ff0000",gradientTo:"#000000",enabled:!0,...e},!this.config.dueDate)throw new Error("dueDate is required");this.init()}e.prototype.init=function(){if(!this.config.enabled){if(this.removeOverlay(),"undefined"!=typeof document){const e=document.getElementsByTagName("BODY")[0];e&&e.style&&(e.style.opacity=1)}return}const e=new Date(this.config.dueDate),t=this.config.daysDeadline,n=new Date,o=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()),i=Date.UTC(n.getFullYear(),n.getMonth(),n.getDate()),a=Math.floor((i-o)/864e5);if(a>0){let e=100*(t-a)/t/100;e=e<0?0:e,e=e>1?1:e,e>=0&&e<=1&&this.applyEffect(e)}},e.prototype.applyEffect=function(e){switch(this.config.effect){case"gradient":this.applyGradientEffect(e);break;case"solid":this.applySolidEffect(e);break;default:this.applyFadeEffect(e)}},e.prototype.applyGradientEffect=function(e){this.removeOverlay();const t=document.createElement("div");t.id="paywall-overlay",t.style.cssText=`\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: linear-gradient(135deg, ${this.config.gradientFrom} 0%, ${this.config.gradientTo} 100%);\n opacity: ${1-e};\n z-index: 999999;\n pointer-events: none;\n transition: opacity 0.3s ease-in-out;\n mix-blend-mode: multiply;\n `;const n=document.createElement("div");n.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n color: #ffffff;\n font-size: 18px;\n font-weight: bold;\n text-align: center;\n opacity: 0.1;\n pointer-events: none;\n user-select: none;\n font-family: Arial, sans-serif;\n text-shadow: 2px 2px 4px rgba(0,0,0,0.5);\n ",n.textContent="Pago Pendiente",t.appendChild(n),document.body.appendChild(t),this.overlay=t},e.prototype.applySolidEffect=function(e){this.removeOverlay();const t=document.createElement("div");t.id="paywall-overlay",t.style.cssText=`\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background-color: ${this.config.color};\n opacity: ${1-e};\n z-index: 999999;\n pointer-events: none;\n transition: opacity 0.3s ease-in-out;\n `;const n=document.createElement("div");n.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n color: #ffffff;\n font-size: 18px;\n font-weight: bold;\n text-align: center;\n opacity: 0.1;\n pointer-events: none;\n user-select: none;\n font-family: Arial, sans-serif;\n text-shadow: 2px 2px 4px rgba(0,0,0,0.5);\n ",n.textContent="Pago Pendiente",t.appendChild(n),document.body.appendChild(t),this.overlay=t},e.prototype.applyFadeEffect=function(e){this.removeOverlay(),document.getElementsByTagName("BODY")[0].style.opacity=e},e.prototype.removeOverlay=function(){this.overlay&&this.overlay.parentNode&&(this.overlay.parentNode.removeChild(this.overlay),this.overlay=null)},e.prototype.disable=function(){if(this.config.enabled=!1,this.removeOverlay(),"undefined"!=typeof document){const e=document.getElementsByTagName("BODY")[0];e&&e.style&&(e.style.opacity=1)}},e.prototype.enable=function(){this.config.enabled=!0,this.init()},e.prototype.update=function(e){this.config={...this.config,...e},this.init()},e.prototype.destroy=function(){this.disable()},"undefined"!=typeof module&&module.exports?module.exports=e:"function"==typeof define&&define.amd?define(function(){return e}):"undefined"!=typeof window&&(window.Paywall=e)});
//# sourceMappingURL=paywall.min.js.map