var address = (hasher.getURL()).replace((hasher.getBaseURL()), ''); var isEncode; address = address.replace('#/', ''); if( address ) { $.get("actions.php", { action: 'encode' }).done(function (data) { isEncode = data; if(address.indexOf("@") != -1) { createUser(address); } else { createUser(atob(address)); } }); } else { $("#generateID").fadeIn(500); $.get("actions.php", { action: 'encode' }).done(function (data) { isEncode = data; }); } var refreshRate; $.get("actions.php", { action: 'refreshRate' }).done(function( data ) { refreshRate = parseInt(data); }); var pushNotifications; $.get("actions.php", { action: 'pushNotifications' }).done(function( data ) { if(data === 'yes') { pushNotifications = true; } else { pushNotifications = false; } }); /* * Notification Function */ function notifyUser(message) { if(pushNotifications) { if (!("Notification" in window)) { document.getElementById('notifyUserSound').play(); } else if (Notification.permission === "granted") { var notification = new Notification(message); document.getElementById('notifyUserSound').play(); } else if (Notification.permission !== 'denied') { Notification.requestPermission(function(permission) { if (permission === "granted") { var notification = new Notification(message); document.getElementById('notifyUserSound').play(); } }); } else { document.getElementById('notifyUserSound').play(); } } else { document.getElementById('notifyUserSound').play(); } } /* * Show About Us */ function showAboutUs() { $("#main").fadeOut( "slow", function() { $("#aboutus").fadeIn("slow"); }); } /* * Close About Us */ function closeAboutUs() { $("#aboutus").fadeOut( "slow", function() { $("#main").fadeIn("slow"); }); } /* * Set Language */ function setLang() { var setLang = document.getElementsByName("lang")[0].value; $("#generateID").fadeOut(500); $("#createdline").fadeOut(500); $("#data").fadeOut(500); $("#search-bar-container").fadeOut(500); $(".message").fadeOut(500); if ( setLang === "hi" ) { $("#createline").html("डटे रहो! भाषा बदल रही है..."); } else if ( setLang === "fr" ) { $("#createline").html("Attendre! Changer de langue..."); } else if ( setLang === "ch" ) { $("#createline").html("不掛斷!改變語言..."); } else if ( setLang === "ar" ) { $("#createline").html("تشبث! جار تغيير اللغة ..."); } else if ( setLang === "sp" ) { $("#createline").html("¡Aférrate! Cambio de idioma..."); } else if ( setLang === "ru" ) { $("#createline").html("Подожди! Изменение языка..."); } else if ( setLang === "de" ) { $("#createline").html("Abwarten! Sprache ändern..."); } else if ( setLang === "pl" ) { $("#createline").html("Wytrzymać! Zmiana języka..."); } else { $("#createline").html("Hang on! Changing Language..."); } $("#createline").delay(500).fadeIn(500); $.get( "actions.php", { action: "changeLang", lang: setLang } ) .done(function( data ) { location.reload(); }); } /* * Set a New ID */ function setNewID() { $("#generateID").fadeOut(500); var email = document.getElementsByName("email")[0].value; var domain = document.getElementsByName("domain")[0].value; var fullEmail = email + domain; createUser(fullEmail); } /* * Generate a Random ID */ function generateRandomID() { $("#generateID").fadeOut(500); var address = (hasher.getURL()).replace((hasher.getBaseURL()), ''); address = address.replace('#/', ''); createUser(address); } /* * Create a new address for user. If address is already specified it checks if that is valid */ function createUser(address) { $.get("actions.php", { action: 'getTitle' }).done(function( data ) { $("title").html(data); }); $.get("user.php", { user: address }).done(function(data) { address = data; document.getElementById("address").innerHTML = address; if(isEncode === "yes") { var newAddress = btoa(address); hasher.setHash(newAddress); } else { hasher.setHash(address); } $("title").prepend(" - "); $("title").prepend(address); $("#createdline").delay(500).fadeIn(500); $.get("mail.php", function(data) { $("#data").html(data); $.get("actions.php", { action: 'getCount' }).done(function( data ) { counter = Number(data); if(counter > 1) { $("#search-bar-container").delay(600).fadeIn(500); } $("#data").delay(600).fadeIn(500); $(".message").delay(600).fadeIn(500); }); retriveNewMails(); }); classAddress = address.replace('@', ''); classAddress = classAddress.replace('.', ''); if (!$('.'+classAddress).length) { $(".action-list").append(''); } checkCurrentTMail(); }); } /* * Switch Email ID */ function switchEmail(address) { $("#generateID").fadeOut(500); createUser(address); } /* * Function to check if element is empty with possible only blank spaces */ function isEmpty( el ){ return !$.trim(el.html()) } /* * Checks for new emails at regular interval. setTimeout calls function every 1000 ms (1 Second) */ function retriveNewMails() { str = $("title").text(); counter = 0; if ( str.includes("nbox") ) { str = str.substring(str.indexOf("-") + 1); } $.get("actions.php", { action: 'getCount' }).done(function( data ) { $("title").text(str); counter = Number(data); if(counter > 1) { $("#search-bar-container").fadeIn(500); } $("title").prepend(" - "); $("title").prepend(")"); $("title").prepend(data); $("title").prepend("Inbox ("); }); $.get("mail.php?unseen=1", function(data) { if (data.trim() === "DIE") { location.reload(); return; } if(data) { if (!isEmpty($('.cssload-container'))) { $("#data").html(data); } else { $("#data").prepend(data); } notifyUser("You got some new EMails"); } }); $("#timer").html(refreshRate); var acc = document.getElementsByClassName("accordion"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function() { this.classList.toggle("active"); var panel = this.nextElementSibling; if (panel.style.maxHeight){ panel.style.maxHeight = null; } else { panel.style.maxHeight = panel.scrollHeight + "px"; } } } setTimeout(retriveNewMails, refreshRate*1000); } /* * Function to delete email * @param mailid - Identify the mail to delete */ function deleteMail(mailid) { $.get("actions.php", { action: 'delete', id: mailid }); var mailLocator = "#mail".concat(mailid); $(mailLocator).hide( "slow", function() { $( this ).remove(); if (isEmpty($('#data'))) { $("#data").html('