2012-08-11 08:00:15 +00:00
|
|
|
var ANDROID_COOKIE_NAME = "mobile_checked_android";
|
|
|
|
var OTHER_COOKIE_NAME = "mobile_checked_other";
|
2014-02-02 08:01:00 +00:00
|
|
|
var MOBILE_SITE_HOSTNAME = "m.what.cd";
|
2012-08-11 08:00:15 +00:00
|
|
|
var MOBILE_SITE_URL = "https://m.what.cd/";
|
2013-09-09 08:00:52 +00:00
|
|
|
var ANDROID_APP_URL = "http://bit.ly/whatandroid";
|
2012-08-11 08:00:15 +00:00
|
|
|
|
|
|
|
var isMobile = {
|
2013-04-19 08:00:55 +00:00
|
|
|
Android: function() {
|
|
|
|
return navigator.userAgent.match(/Android/i) ? true : false;
|
|
|
|
},
|
|
|
|
BlackBerry: function() {
|
|
|
|
return navigator.userAgent.match(/BlackBerry/i) ? true : false;
|
|
|
|
},
|
|
|
|
iOS: function() {
|
|
|
|
return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
|
|
|
|
},
|
|
|
|
Windows: function() {
|
|
|
|
return navigator.userAgent.match(/IEMobile/i) ? true : false;
|
|
|
|
},
|
|
|
|
Any: function() {
|
|
|
|
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
|
|
|
|
},
|
|
|
|
NotAndroid: function() {
|
2012-08-11 08:00:15 +00:00
|
|
|
return (isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
|
2013-04-19 08:00:55 +00:00
|
|
|
}
|
2012-08-11 08:00:15 +00:00
|
|
|
};
|
|
|
|
|
2014-02-02 08:01:00 +00:00
|
|
|
if (window.location.hostname == MOBILE_SITE_HOSTNAME) {
|
|
|
|
setCookie(OTHER_COOKIE_NAME, true, 365);
|
|
|
|
} else {
|
|
|
|
if (isMobile.Android()) {
|
|
|
|
if (!hasCookie(ANDROID_COOKIE_NAME)) {
|
|
|
|
setCookie(ANDROID_COOKIE_NAME, true, 365);
|
|
|
|
var result = confirm("An Android app is available for What.CD. Would you like to download it?");
|
|
|
|
if (result == true) {
|
|
|
|
window.location = ANDROID_APP_URL;
|
|
|
|
}
|
2013-04-19 08:00:55 +00:00
|
|
|
}
|
2014-02-02 08:01:00 +00:00
|
|
|
} else if (isMobile.NotAndroid()) {
|
|
|
|
if (!hasCookie(OTHER_COOKIE_NAME)) {
|
|
|
|
setCookie(OTHER_COOKIE_NAME, true, 365);
|
|
|
|
var result = confirm("A mobile version of What.CD is available. Would you like to use it?");
|
|
|
|
if (result == true) {
|
|
|
|
window.location = MOBILE_SITE_URL;
|
|
|
|
}
|
2013-04-19 08:00:55 +00:00
|
|
|
}
|
2012-08-11 08:00:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-02 08:01:00 +00:00
|
|
|
function setCookie(c_name, value, exdays) {
|
2013-04-19 08:00:55 +00:00
|
|
|
var exdate = new Date();
|
|
|
|
exdate.setDate(exdate.getDate() + exdays);
|
|
|
|
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
|
|
|
|
document.cookie = c_name + "=" + c_value;
|
2012-08-11 08:00:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
function getCookie(c_name) {
|
2014-02-02 08:01:00 +00:00
|
|
|
var i, x, y, ARRcookies = document.cookie.split(";");
|
2013-04-19 08:00:55 +00:00
|
|
|
for (i = 0; i < ARRcookies.length; i++) {
|
|
|
|
x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
|
2014-02-02 08:01:00 +00:00
|
|
|
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
|
2013-04-19 08:00:55 +00:00
|
|
|
x = x.replace(/^\s+|\s+$/g,"");
|
|
|
|
if (x == c_name) {
|
|
|
|
return unescape(y);
|
|
|
|
}
|
|
|
|
}
|
2012-08-11 08:00:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 08:00:55 +00:00
|
|
|
function hasCookie(c_name) {
|
2014-02-02 08:01:00 +00:00
|
|
|
var checked = getCookie(c_name);
|
2013-04-19 08:00:55 +00:00
|
|
|
if (checked != null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-08-11 08:00:15 +00:00
|
|
|
}
|