| Forum Home | ||||
| PC World Chat | ||||
| Thread ID: 93637 | 2008-09-25 10:46:00 | The clock is fixed (kinda)!!! | Erayd (23) | PC World Chat |
| Post ID | Timestamp | Content | User | ||
| 707715 | 2008-09-25 10:46:00 | The clock has bugged me for the last time.... as the folks at FFBM don't seem inclined to fix is, here's a bit of javascript that will correct the time by whatever the current server lag is, anywhere it appears on the page. This can be applied directly with opera, or using (I assume) something like greasemonkey under Firefox. [Edit: This code does seem to break some of the menus on the site, and may not work perfectly - watch this space for when I get it debugged.] //wait until the page has finished loading function waitForTimeFixer() { if(window.alreadyfixed === true) return; function waitContinue() { setTimeout(function(){waitForTimeFixer();}, 200); } if(document.body) { if(document.body.innerHTML.match(/The time now is </m)) { timeFixer(); } else waitContinue(); } else waitContinue(); } //correct the times displayed on PressF1 function timeFixer() { //put loose time in spans var tx = new RegExp(/([0-9]{1,2}):([0-9]{1,2}) ([AP]M)/gi); document.body.innerHTML = (document.body.innerHTML.replace(tx, '<span class="erayd-time">$1:$2 $3</span>')); //put time spans in an array var now = new Date(); var arr = document.getElementsByTagName('span'); var arrTime = new Array(); for(i = 0; i < arr.length; i++) { if(arr[i].getAttribute('class') == 'time' || arr[i].getAttribute('class') == 'erayd-time') { arrTime.push(arr[i]); } } //find time difference based on local system time var f1_now = strToTime(arrTime[arrTime.length - 1].innerHTML); if(now.getTime() < f1_now.getTime()) f1_now.setTime(f1_now.getTime() - 86400000); //fix day var diff = now.getTime() - f1_now.getTime(); //correct the times for(i = 0; i < arrTime.length; i++) { var t = strToTime(arrTime[i].innerHTML); t.setTime(t.getTime() + diff); var ap = t.getHours() < 12 ? 'AM' : 'PM'; var hours = t.getHours() < 12 ? t.getHours() : t.getHours() - 12; if(hours == 0) hours = 12; var minutes = t.getMinutes().toString().length == 1 ? '0' + t.getMinutes() : t.getMinutes(); hours = hours.toString().length == 1 ? '0' + hours : hours; arrTime[i].innerHTML = hours + ':' + minutes + ' ' + ap; arrTime[i].style.color = '#0F0'; } //make sure we don't do it multiple times window.alreadyfixed = true; } //turn a string into a Date object function strToTime(s) { var tx = new RegExp(/([0-9]{1,2}):([0-9]{1,2}) ([AP]M)/gi); var arr = tx.exec(s); var d = new Date(); if(arr[3] == 'PM') arr[1] = parseInt(arr[1]) + 12; if(arr[3] == 'AM' && arr[1] == 12) arr[1] = 0; d.setHours(arr[1]); d.setMinutes(arr[2]); return d; } waitForTimeFixer(); |
Erayd (23) | ||
| 707716 | 2008-09-25 11:01:00 | Testing Testing, Posted at 10:35PM EDIT: It works! Thanks a million Erayd. |
Sherman (9181) | ||
| 707717 | 2008-09-25 11:03:00 | Looks pretty good to me - but your original post is now showing "Today, 1:20PM" - when I first tested it, it showed 10:20PM, and Sherman's post time is correct... | johcar (6283) | ||
| 707718 | 2008-09-25 11:04:00 | As is mine at 10:37. But the text of the post remains in the Quick Reply box after submission... EDIT: at least until I refresh the page. (Had to turn Greasemonkey off to do this edit) |
johcar (6283) | ||
| 707719 | 2008-09-25 13:04:00 | Yes.... it needs a little debugging I think. I'll put an updated copy in this thread once I've resolved the issue. | Erayd (23) | ||
| 707720 | 2008-09-25 20:04:00 | All done with iSmoke and E-mirrors. | R2x1 (4628) | ||
| 707721 | 2008-09-26 21:33:00 | Thanks for posting that Erayd, it is fantastic. You are an absolute genius. :cool: | CI Sue (14168) | ||
| 707722 | 2008-09-28 07:11:00 | Thanks for posting that Erayd, it is fantastic. You are an absolute genius. :cool: Pity there isn't a similar genius at FFBM who could fix the ORIGINAL problem !!! |
decibel (11645) | ||
| 1 | |||||