Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Jan 23, 2011 22:15:16 GMT -8
Browser Tested: Internet Explorer, Firefox, Chrome and Safari (Global Footer): <script> /* @name Local Time in Profile - Eton */ var tz_storage = 'location' //where in profile to store data tz_errorColor = 'red' //field index where time should be inserted (-0=above displayname, 0=below displayname, -1=above rank, 1=below rank, etc...) (999=below storage field) tz_index = 999 pb_bias=1 //compensate for proboards date drift (1=enable, 0=disable)
var tz_re=/\[\xb1(\d)([+-][\d.]+)\]/, tz_re3=/(\w+\s\d{1,2},\s\d{4},\s\d+:\d+[ap]m)/ var a,b,c,d,mTD,i,dt=new Date() if(document.modifyForm){ a=document.modifyForm[tz_storage], b=document.modifyForm['timezone'], c=document.modifyForm['summertime'] if(a&&b&&c){ function tzedit(ev){ try{ if(document.getElementById('showlocaltime').selectedIndex<1)return true var d = arguments.callee.prototype.tzb.options[arguments.callee.prototype.tzb.selectedIndex].value; d=(d>=1)?'+'+d:d d='[\xb1'+arguments.callee.prototype.tzc.options[arguments.callee.prototype.tzc.selectedIndex].value+d+']' arguments.callee.prototype.tza.value+=d; }catch(e){return true} } mTD=c.offsetParent.parentNode.cloneNode(1) mTD.firstChild.lastChild.innerHTML='Show Local Time:' mTD.firstChild.nextSibling.lastChild.lastChild.name= mTD.firstChild.nextSibling.lastChild.lastChild.id= 'showlocaltime' mTD.lastChild.lastChild.innerHTML='Do you want your local time displayed in your profile?' c.offsetParent.parentNode.parentNode.appendChild(mTD) a.value=a.value.replace(tz_re,''); i=document.getElementById('showlocaltime') if(tz_re.test(RegExp['$_']))i.selectedIndex=1; else i.selectedIndex=0 if(a.maxLength<(a.value.length+9)){ i.style.outline=a.style.outline=tz_errorColor+" solid medium"; mTD.lastChild.lastChild.innerHTML +='<font color="'+tz_errorColor+'">(Not enough room in '+tz_storage+' field to use this feature! Please make room and refresh this page)</font>' i.selectedIndex=0; i.disabled=true; } tzedit.prototype.tza=a; tzedit.prototype.tzb=b;tzedit.prototype.tzc=c; i.onchange=function(){ var t=document.getElementById('showlocaltime') if(!t)return true if(t.selectedIndex>0){ if(document.modifyForm.addEventListener){ document.modifyForm.addEventListener('submit',tzedit,0); }else if(document.modifyForm.attachEvent){ document.modifyForm.attachEvent('onsubmit',tzedit) }else{ document.modifyForm.onsubmit=tzedit} }else{ if(document.modifyForm.removeEventListener){ document.modifyForm.removeEventListener('submit',tzedit,0); }else if(document.modifyForm.detachEvent){ document.modifyForm.detachEvent('onsubmit',tzedit) }else{ document.modifyForm.onsubmit=null} } } i.onchange() } } function pbDateOffset(index,bT){ if(arguments.callee.prototype.pbdiff) return arguments.callee.prototype.pbdiff; else arguments.callee.prototype.pbdiff=[0,''] index=isNaN(index)?2:index; var b= 'The detected difference between your computer time and this Proboards forum ' var a=document.getElementsByTagName('td')[index].innerHTML.match(tz_re3) if(a&&a.length){ a= (bT&&pb_username!='Guest')?new Date(a[0].replace(/([ap]m)$/,' $1')):dt; if(!isNaN(a)){ arguments.callee.prototype.pbdiff= [dt-a,b+'is approximately '+String((dt-a)/1000/60).replace(/(\.\d{2})\d+/,'$1')+' minutes'] return arguments.callee.prototype.pbdiff } } return [0,b+'could not be determined'] } if(location.href.match(/action=(display|goto|(?:user)?recent|search2|(pm)?viewp?)/i)|| (location.href.split(/\//).pop().match(/index.cgi\??/) && (document.body.innerHTML.match(/b>\d+\sresults found<\/b/i)|| document.title.match(/-\sPreview/)))){ mTD=document.getElementsByTagName('td'); pb_bias=pbDateOffset(2,pb_bias)[0] for(i=0;i<mTD.length;i++){ if(((mTD[i].width=="20%" && mTD[i].className.match(/windowbg2?/) && mTD[i].innerHTML.match(/Posts:/)) || (mTD[i].previousSibling && mTD[i].previousSibling.width=="25%")) && mTD[i].innerHTML.match(tz_re) ){ if(mTD[i].innerHTML.match(/Posts:/)){ b=mTD[i].innerHTML.split(/<br\s*\/?>/i) while(b[b.length-1]=='')b.pop(); for(c=0;c<b.length;c++){ if(b[c].match(tz_re)){ b[c]= b[c].replace(tz_re,function(m,p1,p2,p3){ var lt=dt.getTime(),lo=dt.getTimezoneOffset() * 60000,utc=lt+lo, ti=tz_index,rt; utc=utc + (3600000*(parseInt(p2)+parseInt(p1))) - pb_bias utc=(new Date(utc))//.toLocaleString() rt= "Local Time: "+(pbDateOffset.prototype.pbdiff[0]?"<a href='javascript:alert(pbDateOffset()[1])'>":"")+ (['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][utc.getDay()]+',')+' '+utc.toLocaleTimeString()+(pbDateOffset.prototype.pbdiff[0]?'</a>':'') if(ti!=999){ ti=ti%b.length if(ti>-1){b[ti]=(b[ti].length?b[ti]+'<br>':'')+rt;}else{ti=0-ti; b[ti]=rt+(b[ti].length?'<br>'+b[ti]:'')} return '' }else{return ((b[c].length?'<br>':'')+rt)} }); break; } } mTD[i].innerHTML=b.join('<br>') }else mTD[i].innerHTML=mTD[i].innerHTML.replace(tz_re,'') } } } </script>
Forgot to mention this was a request but it's implemented as an opt-in feature to get around the privacy issue. User has to modify their profile and set the show local time option to yes. That option should be found under the date/time section (where you select daylight saving time, etc.) Edit:
The toLocale_x methods of the date object is suppose to query then use the format chosen by the user from the platform they're using (OS). On macs however it appears some browsers cheat and instead use the format in the native build of the browser itself (e.g en-US[mm-dd-yyyy], en-GB[dd-mm=yy], etc.) or the prominent language chosen in the language preference in the browser's options. The same also holds true for time formats. Because of this chaos on the mac platform (ironic since PC is always said to be the chaotic one) the code has been modified to use hard-coded day-of-week, the time format however is still left up to the whim of the browser. This however means internationalization is lost, so all you non-english locales will now find yourselves looking at english-only displays ...
|
|