Post by Peter on Jul 28, 2006 10:02:48 GMT -8
This code will show your members when they last visited the forum. Place a span tag with the id "last_visit" where you want it displayed.
Make sure that the span tag is above the main code.
<span id="last_visit"></span>
The code can go anywhere really, as long as it is below the span tag.
<script type="text/javascript">
<!--
// Created by PopThosePringles
var last_visit = {
username: pb_username || null,
get_cookie: function(){
if(arguments[0]){
if(document.cookie.match(new RegExp("\\b" + arguments[0] + "=(\\d+);?", "i"))){
return RegExp.$1 || 0;
}
}
return 0;
},
set_cookie: function(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
date.toGMTString();
document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + date;
},
init: function(){
if(this.username && this.username != "Guest"){
if(this.get_cookie("last_active") > 0 && this.get_cookie("last_visit") > 0){
if((new Date().getTime() - this.get_cookie("last_active")) > (140000 * 24)){
this.set_cookie("last_visit", this.get_cookie("last_active"), 366);
this.set_cookie("last_active", new Date().getTime(), 366);
}
} else {
this.set_cookie("last_visit", new Date().getTime(), 366);
this.set_cookie("last_active", new Date().getTime(), 366);
}
} else {
this.set_cookie("last_visit", "", -1);
this.set_cookie("last_active", "", -1);
}
this.display();
},
work_date: function(ts, add_time){
Date.prototype.getDayYear = function(){
return ((Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()) - Date.UTC(this.getFullYear(), 0, 0)) / 86400000);
}
var day = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"];
var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = new Date();
date.setTime(ts);
var affix;
switch(date.getDate()){
case 1 :
case 21 :
case 31 :
affix = "st";
break;
case 2 :
case 22 :
affix = "nd";
break;
case 3 :
case 23 :
affix = "rd";
break
default :
affix = "th";
}
var days = day[date.getDay()]
var months = month[date.getMonth()]
var years = date.getFullYear();
var hours = date.getHours();
var mins = date.getMinutes();
var now = new Date()
mins = (mins < 10)? "0" + mins : mins;
var date_str = "";
if(now.getDayYear() == date.getDayYear()){
date_str = "<b>Today</b>, at " + hours + ":" + mins;
} else if((now.getDayYear() - 1) == date.getDayYear()){
date_str = "Yesterday, at " + hours + ":" + mins;
} else {
date_str = days + ", " + date.getDate() + "<sup>" + affix + "</sup> " + months + ", " + years;
if(add_time){
date_str += " at " + hours + ":" + mins;
}
}
return date_str;
},
display: function(){
if(document.getElementById("last_visit")){
document.getElementById("last_visit").innerHTML = "Last Visit: " + this.work_date(this.get_cookie("last_visit"), true);
}
}
};
last_visit.init();
//-->
</script>
Make sure that the span tag is above the main code.
<span id="last_visit"></span>
The code can go anywhere really, as long as it is below the span tag.
<script type="text/javascript">
<!--
// Created by PopThosePringles
var last_visit = {
username: pb_username || null,
get_cookie: function(){
if(arguments[0]){
if(document.cookie.match(new RegExp("\\b" + arguments[0] + "=(\\d+);?", "i"))){
return RegExp.$1 || 0;
}
}
return 0;
},
set_cookie: function(name, value, days){
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
date.toGMTString();
document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + date;
},
init: function(){
if(this.username && this.username != "Guest"){
if(this.get_cookie("last_active") > 0 && this.get_cookie("last_visit") > 0){
if((new Date().getTime() - this.get_cookie("last_active")) > (140000 * 24)){
this.set_cookie("last_visit", this.get_cookie("last_active"), 366);
this.set_cookie("last_active", new Date().getTime(), 366);
}
} else {
this.set_cookie("last_visit", new Date().getTime(), 366);
this.set_cookie("last_active", new Date().getTime(), 366);
}
} else {
this.set_cookie("last_visit", "", -1);
this.set_cookie("last_active", "", -1);
}
this.display();
},
work_date: function(ts, add_time){
Date.prototype.getDayYear = function(){
return ((Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()) - Date.UTC(this.getFullYear(), 0, 0)) / 86400000);
}
var day = ["Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat"];
var month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var date = new Date();
date.setTime(ts);
var affix;
switch(date.getDate()){
case 1 :
case 21 :
case 31 :
affix = "st";
break;
case 2 :
case 22 :
affix = "nd";
break;
case 3 :
case 23 :
affix = "rd";
break
default :
affix = "th";
}
var days = day[date.getDay()]
var months = month[date.getMonth()]
var years = date.getFullYear();
var hours = date.getHours();
var mins = date.getMinutes();
var now = new Date()
mins = (mins < 10)? "0" + mins : mins;
var date_str = "";
if(now.getDayYear() == date.getDayYear()){
date_str = "<b>Today</b>, at " + hours + ":" + mins;
} else if((now.getDayYear() - 1) == date.getDayYear()){
date_str = "Yesterday, at " + hours + ":" + mins;
} else {
date_str = days + ", " + date.getDate() + "<sup>" + affix + "</sup> " + months + ", " + years;
if(add_time){
date_str += " at " + hours + ":" + mins;
}
}
return date_str;
},
display: function(){
if(document.getElementById("last_visit")){
document.getElementById("last_visit").innerHTML = "Last Visit: " + this.work_date(this.get_cookie("last_visit"), true);
}
}
};
last_visit.init();
//-->
</script>