class Toasty { constructor (element, xOffset=100, yOffset=100, expireSec=5, opacity=100, color='#acadac', bgColor='#322332', borderColor='#bfcfbf') { this.div = element; this.xOffset = xOffset; this.yOffset = yOffset; this.expireSec = expireSec; this.opacity = opacity; this.color = color; this.bgColor = bgColor; this.borderColor = borderColor; this.init(); } init () { this.div.style.position = 'fixed'; this.div.style.top = this.yOffset; this.div.style.left = this.xOffset; this.div.id = 'toastDiv'; document.body.appendChild(this.div); } addToast(message) { this.div.style.top = this.yOffset; this.div.style.left = this.xOffset; let toastDiv = document.createElement('div'); this.div.appendChild(toastDiv); let toastSpan = document.createElement('span'); const toastId = 'toast-' + Date.now().toString(); toastDiv.id = toastId; toastSpan.style.color = this.color; toastDiv.style.border = 'solid ' + this.borderColor + ' 2px'; toastDiv.style.borderRadius = '8px'; toastDiv.style.backgroundColor = this.bgColor; toastSpan.style.backgroundColor = this.bgColor; toastSpan.innerHTML = message; toastDiv.appendChild(toastSpan); setTimeout(function () { document.getElementById(toastId).remove(); }, this.expireSec * 1000); } }