public
Last active

firefox-ubiquity command for San Francisco nextmuni arrivals

  • Download Gist
x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
noun_type_sfbus = new CmdUtils.NounType( "SFBus", ["F","J","KT","L","M","N","S","1","1AX","1BX","2","3","4","5","6","7","9","9AX","9BX","9X","10","12","14","14L","14X","16AX","16BX","17","18","19","20","21","22","23","24","26","27","28","28L","29","30","30X","31","31AX","31BX","33","35","36","37","38","38AX","38BX","38L","39","41","43","44","45","47","48","49","52","53","54","56","66","67","71","71L","74","76","80X","81X","82X","88","89","90","91","108","K OWL","L OWL","M OWL","N OWL","T OWL","59","60","61"]);
 
CmdUtils.CreateCommand({
name: "muni",
icon: "http://www.nextmuni.com/favicon.ico",
homepage: "http://www.jeremyrgordon.com/2009/02/nextmuni-for-ubiquity.html",
author: { name: "Jeremy Gordon", email: "onejgordon@gmail.com"},
description: "Lookup muni arrivals from nextmuni.com",
help: "Input line number and partial matches for cross streets, eg. 'muni 1 at Div and Cal'. Currently matches capitalized street names.",
takes: {"line": noun_type_sfbus},
modifiers: {at: noun_arb_text,
and: noun_arb_text
},
preview: function( pblock, lineText, mods ) {
var line_url = "http://www.nextmuni.com/predictor/simpleStopSelector.shtml?a=sf-muni&r=" + lineText.text;
jQuery.get(line_url,null,function(data){
links1 = jQuery(data).find("a:contains(" + mods.at.text + ")").parent();
links2 = links1.find("a:contains(" + mods.and.text + ")");
nResults = links2.size();
output = "";
if (nResults > 6) { output = "Please revise search. e.g. 'muni 1 at Div and Cal'"; } else {
for (i=0; i<nResults; i++) {
stop = links2.get(i).search;
stop_link = "http://www.nextmuni.com/predictor/simplePrediction.shtml" + stop;
jQuery.get(stop_link,null,function(data2){
arrivals = jQuery(data2).find("table[cellpadding='2']");
dir = jQuery(data2).find("font[size='3']:contains('Direction:')").parent().next();
stopname = jQuery(data2).find("font[size='3']:contains('Stop:')").parent().next();
output += "<br>" + stopname.html() + " - " + dir.html() + arrivals.html();
});
}
}
});
var template = "<i>${num} stops found on Line ${line}.</i> ${output}";
pblock.innerHTML = CmdUtils.renderTemplate(template, {"num": nResults, "line": lineText.text, "output": output});
},
execute: function(lineText, mods) {
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.