Redfin Real Estate Forums
Jump to Page:   1
Show WalkScore (GreaseMonkey hack)
Options    Options  
rouftop
Visitor
Posts: 3
Registered: 01-25-2008


rouftop

Message 1 of 4

Viewed 2,663 times


Hey,
My wife and I are trying to find places in particularly walkable neighborhoods. To that end, I just whipped up this little GreaseMonkey script. It adds a "Show Walkability" link underneath the address on the "listing details" page. That link will pop the address into Walk Score in a new window, so you can see how far you have to go to find the nearest coffeeshop, bar, grocery store, etc.

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

Happy house hunting,
rouftop
Kudos!
01-25-2008 01:29 PM
 

  Reply   Reply  
Re: Show WalkScore (GreaseMonkey hack)
Options    Options  
dub
Contributor
Posts: 22
Registered: 03-24-2008


dub

Message 2 of 4

Viewed 2,369 times


Awesome script!
Would it be possible to link to yelp?

Target URL:
http://www.yelp.com/maptastic?lon=-71.17848&lat=42.37185&zoom=12

I see the lat/long in here

var g_listing = {
latitude: 42.403088,
longitude: -71.243636,
icon: "<div class='homePushpin'><img class='ico_map_for_sale' src='http://p1.rfimg.us/v4.5.3/images/clear.gif'/></div>"
};

But this fails silently after 'in showYelp'..any idea how to get it to work?

function showYelp() {

alert('in showYelp');
alert('Latitude='+ g_listing.latitude);
var loc = "http://www.yelp.com/maptastic?lon=" +g_listing.longitude+ "&lat=" +g_listing.latitude +"&zoom=14";

var div = document.createElement('div');
var anc = document.createElement('a');
anc.target = '_new';
anc.href = loc;
anc.innerHTML = "Show Walkability";
div.appendChild(anc);
var sibling = document.getElementById('address_line_2');
sibling.parentNode.insertBefore(div, sibling.nextSibling);
}

showYelp();
Kudos!
04-14-2008 09:23 PM
 

  Reply   Reply  
Re: Show WalkScore (GreaseMonkey hack)   [ Edited ]
Options    Options  
Navtej
Redfin Staff
Posts: 3
Registered: 04-15-2008


Navtej

Message 3 of 4

Viewed 2,354 times


Hi dub,

The reason your script is failing after the first alert is because Greasemonkey cannot access g_listing. Greasemonkey scripts don't actually run directly in the context of the page, but work inside a sandbox for security reasons. This O'Reilly article details some of the caveats pretty well.

That said, you can make your script work by referring to unsafeWindow.g_listing instead of just g_listing. unsafeWindow is the actual window object rather than Greasemonkey's proxy, so it contains the custom fields added by the page's script. Just take note (from the O'Reilly article):

It's called unsafeWindow for a reason: its properties and methods could be redefined by the page to do virtually anything. You should never call methods on unsafeWindow unless you completely trust the remote page not to mess with you. You should only ever use it as a parameter to call functions defined by the original page, or to watch window properties...


Also note, that you can actually see the error messages in Firefox's error console (under the Tools menu) rather than just relying on window.alert().

Message Edited by Navtej on 04-15-2008 12:59 PM
 

Navtej Sadhal
Software Developer - Search Team
Kudos!
04-15-2008 11:15 AM
 

  Reply   Reply  
Re: Show WalkScore (GreaseMonkey hack)
Options    Options  
dub
Contributor
Posts: 22
Registered: 03-24-2008


dub

Message 4 of 4

Viewed 2,337 times


Thanks Navtej - I figured it was something like that!

I uploaded the script, called it YelpFin, and blogged it.
Kudos!
04-15-2008 05:49 PM
 

  Reply   Reply  
Jump to Page:   1
Search this Forum
Search Board
Advanced
Legend
No New Messages   No New Messages
New Messages   New Messages
This is a popular thread with no new messages   Hot Thread
Read Only Thread   Read Only Thread
Replied-To Thread   Replied-To Thread

Powered By Lithium