Post by Chris on May 22, 2007 22:53:36 GMT -8
Updates |
|
Overview: This code shows the time you have left on your account before Proboards automatically logs you out. It can come in very handy when you're writing a lengthy post only to find out that your logon has expired and you are just a guest now and unable to make the post. All that writing you just did was for naught if you are unable to recover it from your browser's history.
Preview:
Installation: The code comes in two parts, one goes in GLOBAL HEADER and the other goes in GLOBAL FOOTER. You may also edit the values in the user settings section of the global header portion if the default values are not to your liking.
<script type="text/javascript">
<!--
/* Logout Reminder - Eton Bones*/
/* This portion of the script belongs in the GLOBAL HEADER */
/********* Start User Settings ****************/
var logoutUpdateInterval=1; //set to number of seconds between updates of time display (1-60)
var criticalThreshold=60; //set to number of seconds before time display starts flashing to indicate impending logout (must be at least 5 times greater than logoutUpdateInterval)
var criticalModeOnly=false; //set to true to see countdown only when criticalThreshold is reached.
/********* End User Settings ****************/
try{
if(pb_username && pb_username!="Guest"){
var pb_logout=document.cookie.match(/logout=\d+/)
var timerID=0;
if(pb_logout){
pb_logout=pb_logout[0].split('=')[1];
var leg='<center><table width="200px" cellpadding="4" cellspacing="1" align="center" class="bordercolor" style="display:none"><tr><td class="titlebg" width="100%" align="center"><font size=2><b>'+pb_username+'</B></font></td></tr><tr><td class="windowbg" vAlign="top" align="center"><font size=2 id="logoutTime">00:00:00<\/font><\/tr><\/table><\/center>'
document.write(leg)
logoutUpdateInterval= (logoutUpdateInterval>0 && logoutUpdateInterval<61)?logoutUpdateInterval:2
criticalThreshold=(criticalThreshold>=logoutUpdateInterval*5)?criticalThreshold:60
document.getElementById('logoutTime').parentNode.parentNode.parentNode.parentNode.style.display= ((!criticalModeOnly)?"":"none")
updateLogout();
}
}
}catch(err){
}
function updateLogout(){
try{
var logout=document.getElementById('logoutTime');
if(logout && pb_logout){
if(pb_logout!="0"){
var now=new Date(); var t,s,time
var ms=pb_logout-now.getTime();
if(ms<=criticalThreshold*1000 && logout.parentNode.id!="critical" ){
logout.parentNode.parentNode.parentNode.parentNode.style.display=""
timeCritical();
}
t=Math.floor(ms/1000/60/60);ms-=t*1000*60*60
time="auto-logout: "+String(t);
t=Math.floor(ms/1000/60);ms-=t*1000*60
s=String(t);s=((s.length<2)?"0":"")+s
time+=":"+ s;
t=Math.floor(ms/1000);
s=String(t);s=((s.length<2)?"0":"")+s
time+=":"+ s;
if(time=="0:00:00" || time.match(/-\d/)){
logout.innerHTML="Not logged in"
logout.parentNode.parentNode.previousSibling.cells[0].firstChild.firstChild.innerHTML= "Guest"
clearTimeout(timerID);
logout.parentNode.className="windowbg"
logout.parentNode.parentNode.previousSibling.firstChild.className="titlebg"
return true
}
logout.innerHTML=time;
setTimeout(arguments.callee,logoutUpdateInterval*1000);
}else{
logout.innerHTML="auto-logout: never";
}
}
}catch(err){
}
}
function timeCritical(){
var logout=document.getElementById('logoutTime');
if(logout){
if(!logout.innerHTML.match(/not logged in/)){
logout.parentNode.className= ((logout.parentNode.className=="windowbg")?"titlebg":"windowbg");
logout.parentNode.parentNode.previousSibling.firstChild.className= ((logout.parentNode.className=="windowbg")?"titlebg":"windowbg");
logout.parentNode.id="critical"
timerID=setTimeout(arguments.callee,logoutUpdateInterval*250);
}
}
}
function saveLogonTime(){
var minutes=document.getElementsByName('minutes');
var now=new Date();
minutes= minutes[0].options[minutes[0].options.selectedIndex].value;
var expires=parseInt(minutes)*1000*60+now.getTime()
if(minutes=="-1")expires="0"
document.cookie="logout="+expires+";"
}
//-->
</script>
<script type="text/javascript">
<!--
/* Logout Reminder - Eton Bones */
/* This portion of the script belongs in the GLOBAL FOOTER */
if(document.loginform){
if(loginform.addEventListener){
document.addEventListener("submit",saveLogonTime,false);
}else if(loginform.attachEvent){
loginform.attachEvent("onsubmit",saveLogonTime);
}else{
loginform.onsubmit=saveLogonTime
}
}
//-->
</script>