Extra caution is recommended when installing recently uploaded/updated scripts (read more)
Be sure you trust any scripts you install

Craigslist Driving Time

Estimate the driving time and distance to each item listed on craigslist.org. DO NOT INSTALL THIS SCRIPT unless you are intending to help me finish writing it. It is UNFINISHED and NOT YET WORKING.

Although I have a lot of programming experience in general, I am very new to javascript and greasemonkey, so help would be appreciated, especially on the items listed in the comments section below.

Ideas are also welcome. It may be best to post them as comments, so that others can see what has already been suggested.

DEVELOPER'S NOTE: A perl script genstates.perl was used to generate the regex pattern that matches state names and abbreviations. It is archived at http://userscripts.org/scripts/show/25923 in case it is needed for future maintenance (e.g., if an abbreviation needs to be added).

-----------------------------------

Features planned and partially coded:

- Automatic determination of likely nearby state names, based on the craigslist site URL. This is needed because CraigsList posters usually list only the town name and omit the state.

- Automatic lookup of abbreviations relevant to the user's location. For example, on losangeles.craigslist.org "LA" probably means "Los Angeles", but on neworleans.craigslist.org it probably means "Louisiana".

- Auto update.

Some features already planned but not coded:

- Cache google driving time results to avoid performing unnecessary web requests when the same town is encountered again. In fact, if I figure out how to store data in a cookie or something it might actually be good to cache the driving time results in a cookie that will (hopefully, if the user permits it) be saved between browser sessions. This should speed up driving time lookup a lot, since users often list the same towns repeatedly in different browser sessions.

- Make it work on detail listing pages also.

-----------------------------------

Additional ideas:

- Trigger an update check if 1 day has passed AND all map requests fail AND there were at least 5 map requests.

- If 5 consecutive map requests fail then test a "known good" driving time URL. If that fails, then check for a new version, and if there is no later version, then tell the user what to do to notify the script author. (Perhaps post a comment here reporting the problem and email the author if nobody has done so already.)

- Make it work on sites other than craigslist. Does anyone have suggestions of what sites might benefit from this?

Thanks!
David Booth
david_AT_dbooth_DOT_org

--------------------

5/1/08: Got a hash object working, which will be used for caching. I wonder how much data I can store with GM_setValue? I'll probably have to limit the amount of data that I cache, which probably means keeping track of what has been most recently used and tossing the oldest.

5/2/08: CleanLocation and NeedsState functions are now working and tested. Still lots to do before the first working release.

5/11/08: I've been mocking up the UI and figuring out how the state can be determined from the craigslist URL. For the latter I'm writing a script to scrape craigslist to generate a mapping from URL prefixes (e.g., http://boston.craigslist.org/) to state (e.g., MA). Making progress, but still lots to do before the first working release. Also, I found the javascript "prompt" function, so it looks like I'll be able to use that for whatever prompting I need to do (for the user's startAddress, for example), though I haven't tested it yet.

6/12/08: I've been traveling a lot lately, and brought my XO laptop (from One Laptop Per Child)
http://www.flickr.com/photos/7825496@N03/214593...
for hacking on this script on the plane, since it is so convenient to carry and the battery lasts far longer than my regular laptop. I've got some code together for auto-updating and some other needed functions, but have not yet tested it, so still more work to do before the first release.

7/3/08: Yes, I'm still working on this as a background task. I've been working on it while watching my kids take their swimming lessons, and haven't yet transferred the new code to this machine to integrate and test. Sorry I haven't been proceeding at a stellar pace.

7/20/08: My kids have had swimming lessons more frequently now that school is out, so I've actually been making a bit more progress, though it's still slow, because it's still little snippets of time here and there. Still not ready for first release though. I still have a few different components that I have coded in isolation but have not yet integrated or tested.

8/3/08: I made a little more progress over the weekend.

8/15/08: More progress made during my kids' swimming lessons, though still a fair amount of work left before the first release.






May 4, 2008
David Booth Script's author

Anyone have any suggestions on an easy way to determine the following?

For a given city, what states are within a 2 hour drive?

I do not need to do this computation dynamically when the script is run. It can be pre-computed and saved in a table.

 
May 4, 2008
David Booth Script's author

Thanks jumper4000! I'll look into GM_setValue and GM_getValue when I get to that point. I'm not sure that the updater you mentioned will be the right one for this script, but I'll look into it in more detail when I get farther along.

BTW, jumper4000's comment was in response to my request for help on how do do the following:


1. How to save the user's startAddress in a cookie or something that will be retained, hopefully even across browser sessions.

 
Apr 27, 2008
jumper4000 Scriptwright

what you want to look at for saving variables are GM_setValue and GM_getValue. Take a look at these pages for instructions,
http://diveintogreasemonkey.org/api/gm_setvalue...
http://diveintogreasemonkey.org/api/gm_getvalue...

for auto-update, look at this script,
http://userscripts.org/scripts/show/2296

hope this helps.

You could comment on this script if you were logged in.