// --------------------------------------------------------------------
//
// WHAT IT DOES:
// This script will fix craig's list Google Map urls and change them to
// Directions to where you want to go.
// --------------------------------------------------------------------
//
// ==UserScript==
// @name            poop
// @include         http://*.craigslist.*
// @namespace       http://ohpie.com/
// @description     process craig's list links
// ==/UserScript==
	
(function() {

    var processGmapLinks = function() {
        var xpath = "//a[starts-with(@href,'http://maps.google.com')]";
        var res = document.evaluate(xpath, document, null,
                                    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
                                    
        var linkIndex, gMapLink;
        for (linkIndex = 0; linkIndex < res.snapshotLength; linkIndex++) { 
            gMapLink = res.snapshotItem(linkIndex);
                    
					
            gMapLink.href =  gMapLink.href.replace(/q=loc%3A\+/, "saddr=");
            //gMapLink.href = gMapLink.href.replace(/\+and\+/, "+%26+");
            gMapLink.href =  gMapLink.href.replace(/\+at\+/, "+%26+");
			gMapLink.href += "&daddr=<Destination HERE>"
        }
    }
    
    window.addEventListener("load", processGmapLinks, false);
    
})();


