Update main.js

This commit is contained in:
Kyle
2018-12-23 11:47:11 -08:00
parent 6fb4f9ec49
commit 752352f6fb

View File

@@ -1014,37 +1014,35 @@ console.log("The main.js file has finished loading.")
//============================================// //============================================//
// Cookies! // // Cookies! //
//============================================// //============================================//
function setCookie(cname, cvalue, exdays) { function setCookie(cookieName, cookieValue) {
var d = new Date(); var tempDate = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); tempDate.setTime(tempDate.getTime() + (31 * 24 * 60 * 60 * 1000)); //days*hours*minutes*seconds*milliseconds
var expires = "expires="+d.toUTCString(); var expires = "expires=" + tempDate.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
} }
function getCookie(cookieName) {
function getCookie(cname) { var name = cookieName + "=";
var name = cname + "="; var cookieArray = document.cookie.split(";");
var ca = document.cookie.split(';'); for(var i = 0; i < cookieArray.length; i++) {
for(var i = 0; i < ca.length; i++) { var tempCookie = cookieArray[i];
var c = ca[i]; while (tempCookie.charAt(0) == " ") {
while (c.charAt(0) == ' ') { tempCookie = tempCookie.substring(1);
c = c.substring(1);
} }
if (c.indexOf(name) == 0) { if (tempCookie.indexOf(name) == 0) {
return c.substring(name.length, c.length); return tempCookie.substring(name.length, tempCookie.length);
} }
} }
return ""; return "";
} }
function checkCookies() {
function checkCookie() { if (getCookie("visited") != true) {
var user = getCookie("username"); setCookie("visited", "true")
if (user != "") { if (isMobile == true) {
alert("Welcome again " + user); alert("Thanks for using Card Conjurer! Unfortunately some users have been experiencing difficulty on mobile devices when uploading pictures they took on that mobile device. An easy solution is to quickly edit that picture by cropping it slightly. Otherwise, images from URLs and other sources should work normally.")
} else {
user = prompt("(don't worry, this is for testing purposes and will be removed shortly) Please enter your name:", "");
if (user != "" && user != null) {
setCookie("username", user, 365);
} }
} else {
console.log("Welcome back to Card Conjurer!")
} }
} }
checkCookie()
checkCookies()