Skip to content

Instantly share code, notes, and snippets.

@Pitel
Created August 8, 2009 16:07
Show Gist options
  • Save Pitel/164444 to your computer and use it in GitHub Desktop.
Save Pitel/164444 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
names: ["geocaching", "geocache"],
author: {name: "Jan Kaláb", email: "pitlicek@gmail.com"},
license: "MPL",
description: _("Search for geocaches"),
help: _("Type in the cache name to see its listing."),
icon: "http://www.geocaching.com/favicon.ico",
arguments: [{role: "object", nountype: noun_arb_text, label: _("Waypoint")},
{role: "location", nountype: noun_type_geolocation, label: _("Location")}],
preview: function(pblock, arguments) {
if (arguments.object.text) {
$(pblock).text(_("Fetching listing…"));
$.get("http://www.coord.info/" + arguments.object.text, function(data) {
var CacheName = $("#CacheName", data).text();
if (CacheName) {
var CacheOwner = $("#CacheOwner a", data).text();
var DateHidden = $("#DateHidden", data).text();
var Size = $("#Form1 small:first", data).text();
var Difficulty = $("#Difficulty", data).html();
var Terrain = $("#Terrain", data).html();
var LatLon = $("#LatLon", data).text();
var ShortDescription = $("#ShortDescription", data).html();
var LongDescription = $("#LongDescription", data).html();
$(pblock).html(
"<h1>" + CacheName + "</h1>"+
"<dl>"+
"<dt>" + _("Owner") + "</dt><dd>" + CacheOwner + "</dd>"+
"<dt>" + _("Hidden") + "</dt><dd>" + DateHidden + "</dd>"+
"<dt>" + _("Size") + "</dt><dd>" + Size + "</dd>"+
"<dt>" + _("Difficulty") + "</dt><dd>" + Difficulty + "</dd>"+
"<dt>" + _("Terrain") + "</dt><dd>" + Terrain + "</dd>"+
"<dt>" + _("LatLon") + "</dt><dd>" + LatLon + "</dd>"+
"</dl>"+
ShortDescription+
LongDescription
);
} else {
$(pblock).text(_("Cache not found!"));
}
}, "html");
} else {
$(pblock).text(_("Searching for geocaches near " + arguments.location.text + "…"));
$.get("http://local.yahooapis.com/MapsService/V1/geocode", {appid: "MmK8P3rV34F5tJ8UCl6588uLOk_ktWpuFd2I_FXqfVN8a05Xfvf34IksNjtKUaA-", location: arguments.location.text}, function(data) {
var location = [];
location["lat"] = $("Latitude", data).text();
location["lon"] = $("Longitude", data).text();
displayMessage(location["lat"]);
$.get("http://www.geocaching.com/seek/nearest.aspx", {lat: location["lat"], lng: location["lon"]}, function(data) {
$(pblock).html("<h1>" + _("Nearby geocaches") + "</h1><ul></ul>");
$("#ctl00_ContentBody_dlResults tr", data).each(function() {
var cache = $("td:eq(5) a", this).text()
if (cache) {
$("ul", pblock).append("<li>" + cache + "</li>");
}
});
}, "html");
}, "xml");
}
},
execute: function(arguments) {
if (arguments.object.text) {
Utils.openUrlInBrowser("http://www.coord.info/" + arguments.object.text);
} else {
$.get("http://local.yahooapis.com/MapsService/V1/geocode", {appid: "MmK8P3rV34F5tJ8UCl6588uLOk_ktWpuFd2I_FXqfVN8a05Xfvf34IksNjtKUaA-", location: arguments.location.text}, function(data) {
var location = [];
location["lat"] = $("Latitude", data).text();
location["lon"] = $("Longitude", data).text();
Utils.openUrlInBrowser("http://www.geocaching.com/seek/nearest.aspx?lat=" + location["lat"] + "&lng=" + location["lon"]);
}, "xml");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment