Need some basic find/replace help

Subscribe to Need some basic find/replace help 3 posts, 3 voices

 
Haxim User

I'm working on a basic script to convert the time/dates shown on a page to local time, however I seem to be having some trouble as I know virtually nothing about javascript and am horrible with regular expressions (some might call these insurmountable problems... I would probably agree). My script is missing two parts: a way to parse out the existing time/day, and a way to output the changed time/day. Any help would be appreciated.

// ==UserScript==
// @name Ikariam Time Fix
// @description Converts displayed time to local time
// @include http://s5.ikariam.org/index.php?view=merchantNavy
// ==/UserScript==

textnodes = document.evaluate(
"//text()",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i = 0; i < textnodes.snapshotLength; i++) {

//Parse out any text strings matching "<td>hh:mm Uhr dd.mm.</td>" or "<td>h:mm Uhr dd.mm.</td>" and use it to set the following ikariamDate variable

//Code would go here if I knew how...

//UTC Offset of displayed time (+1 UTC) in milliseconds
ikariamOffset = (3600000*1)

//Set ikariamDate object to values parsed from page text
ikariamDate = new Date();
ikariamDate.SetMonth =
ikariamDate.SetDate =
ikariamDate.SetHour =
ikariamDate.SetMinute =

//convert displayed date to UTC by removing offset from date
utc = ikariamDate - ikariamOffset;

//get local offset in milliseconds
localDate = new Date();
localOffset = localDate.getTimezoneOffset() * 60000;

//get local time by adding local offset to UTC time
fixedMs = utc + localOffset
fixedDate = new Date(fixedMs);

//Using the new fixedDate variable, output a replacement string in the format "<td>hh:mm On dd.mm</td>"

//Code would go here if I knew how...

}

 
Yansky Scriptwright

http://developer.mozilla.org/en/docs/Core_JavaS...

 
Matthew Hancock Scriptwright

Haxim, I just created a script to changed the date/time on the Trade Fleet and Port pages to a countdown instead of that nasty timestamp. You're welcome to use that code as an example if you want. It's called the Ikariam Transport Countdown.

http://userscripts.org/scripts/show/26090