var req = document.getElementById('search_form_input').value;
function ddg_spice_movie(movie) {
var result = req.replace(/^movie\s+/g,'');
// more than one result
// Default to first result incase nothing is more relevant
result = movie["movies"][0];
// Loop through abridged cast members, add to cast element
for (var i=0; i < result.abridged_cast.length; i++){
var pre = '';
if ( i == result.abridged_cast.length - 1 && result.abridged_cast.length != 1 ) pre = 'and ';
var name = result.abridged_cast[i].name;
var url = 'http://www.rottentomatoes.com/celebrity/' + result.abridged_cast[i].id + '/';
'use strict';
env.ddg_spice_quandl_home_values = function(api_result){
var result = api_result;
var recentValue = result.data[0][1];
var previousValue = result.data[1][1];
// adding in the previous date point date
var fromDate = new Date(result.data[1][0]);
var fromDateString = months[fromDate.getUTCMonth()] + " " + fromDate.getUTCDate() + ", " + fromDate.getFullYear();
// reformatting the current data point date (to_date)
var toDate = new Date(result.to_date);
var toDateString = months[toDate.getUTCMonth()] + " " + toDate.getUTCDate() + ", " + toDate.getFullYear();
'use strict';
env.ddg_spice_quandl_fundamentals = function(api_result){
var result = api_result;
var recentValue = result.data[0][1];
var previousValue = result.data[1][1];
// adding in the previous date point date
var fromDate = new Date(result.data[1][0]);
var fromDateString = months[fromDate.getUTCMonth()] + " " + fromDate.getUTCDate() + ", " + fromDate.getFullYear();
// reformatting the current data point date (to_date)
var toDate = new Date(result.to_date);
var toDateString = months[toDate.getUTCMonth()] + " " + toDate.getUTCDate() + ", " + toDate.getFullYear();
'use strict';
env.ddg_spice_quandl_world_bank = function(api_result){
var result = api_result;
var recentValue = result.data[0][1];
var previousValue = result.data[1][1];
// adding in the previous date point date
var fromDate = new Date(result.data[1][0]);
var fromDateString = months[fromDate.getUTCMonth()] + " " + fromDate.getUTCDate() + ", " + fromDate.getFullYear();
// reformatting the current data point date (to_date)
var toDate = new Date(result.to_date);
var toDateString = months[toDate.getUTCMonth()] + " " + toDate.getUTCDate() + ", " + toDate.getFullYear();
var ddg_spice_flights = {
// define some static variables for callback and helpers
// as necessary for cities with multiple airports
route: function(api_result) {
// Get the original query to continue polling for other potential airports
// and for filtering results by airline
var script = $('[src*="/js/spice/flights/route/"]')[0],
source = $(script).attr("src"),
// create all remaining source/destination pairs that have not yet been polled for
for (var srcCounter = 0; srcCounter < queriedSrcAirports.length; srcCounter++) {
for (var dstCounter = 0; dstCounter < queriedDstAirports.length; dstCounter++) {
// skip the first pair because the initial spice-to already
// obtained this result
var query = api_response.query;
var data = api_response.results;
var result;
for (var i = 0; i < data.length; i++) {
var checkRelevancy = [data[i].name, data[i].displayname, data[i].namespace].join(" ");
if (DDG.isRelevant(checkRelevancy, [], 2)) {
result = data[i];
if (!result) {
function formatName(result) {
var formatted_name = result.name;
"use strict";
env.ddg_spice_guidebox_getid = function(api_result) {
if (!api_result || !api_result.results) {
var SKIP_ARRAY = ["online","tv","episode","episodes","free","guidebox","watch","full"],
results = api_result.results.result,
relevant;
// Check which show is relevant to our query.
$.each(results, function(key, result) {
if (DDG.isRelevant(result.title, SKIP_ARRAY, 3) && !relevant) {
relevant = result;
}
var metadata = {
function ddg_spice_search_code(data) {
if(data.results.length > 0) {
var searchterm; // holds the search term
var result; // holds the main result
for (var i=0; i<data.results.length; i++) {
var tmp_result = data.results[i];
if (!DDG.isRelevant(tmp_result.name + ' ' + tmp_result.displayname + ' ' + tmp_result.namespace, '', 2)) continue;
result = tmp_result;
break;
if (!result) return;
function search_codeFormatName(result) {
var formatted_name = result.name;
"use strict";
env.ddg_spice_seasons = function(api_result){
// Make sure we have a result
if (!(api_result &&
api_result.holidays &&
api_result.holidays.length == 4)) {
return Spice.failed('seasons');
// Grab the matching search terms and figure out the season
var script = $('[src*="/js/spice/seasons/"]')[0];
var source = $(script).attr("src");
// Grab the correct season from api results and generate output data
var event = api_result.holidays[season];
var date = DDG.getDateFromString(event.date.iso);
var result = {
function ddg_spice_mass_on_time (api_result) {
if (!api_result || api_result.error) {
var details = api_result['query-details'];
// This says if we should check for relevancy or not.
var script = $('[src*="/js/spice/mass_on_time/"]')[0];
var source = $(script).attr("src");
var generate_header = function (query_details) {
var type;
//Filter results with no address
var results = [];
for(var i = api_result.results.length - 1; i >= 0; i--) {
var result = api_result.results[i];
// define some static variables for callback and helpers
var MILLIS_PER_MIN = 60000,
MILLIS_PER_HOUR = MILLIS_PER_MIN * 60,
// This is the current time at the airport (in milliseconds).
var now = new Date().getTime() + (airportOffset * MILLIS_PER_HOUR);
var deltaDepart = new Date(departureDate) - scheduledDeparture,
env.ddg_spice_airlines = function(api_result) {
// store the user's airline and city search information
var queriedAirlines = null,
// Check if we have anything returned.
if (!api_result || !api_result.flightStatuses || !api_result.appendix || !api_result.appendix.airlines) {
// Extract carrier information from query
var script = $('[src*="/js/spice/airlines/"]')[0],
var result,img,snippet,link,div;
var items = new Array();
for(var i = 0; i<movies.length; i++)
// Make title for header
var header = 'Watch ' + result.title + " ("+result.year+")";
var item = new Array();
var content = "<div><i>Starring:</i> "+result.actors+".</div>";
var streamingStr = "";
var rentalCount = 0;
for(var subtype in result.affiliates)
{
var service = result.affiliates[subtype];
var price = parseFloat(service.price);
var snippet = [[]]; // To store the results
var searchterm; // olds the search term
var result = '';
if(data.results.length > 0) {
searchterm = data.query;
result = data.results[0];
var lines = '';
for (var key in result.lines) {
key = parseInt(key);
lines = lines + code_searchFormatLineHTML(result.id, key+1 ,result.lines[key]);
YAHOO.util.Dom.addClass(div2,'zero_click_searchcode');
var out = code_searchFormatResultHTML(result,lines);
"use strict";
env.ddg_spice_travis_status = function(api_result) {
if (!api_result) {
return Spice.failed('travis_status');
var relevantDetails = {
status: api_result.status.indicator,
description: api_result.status.description,
for(var i=0,max=api_result.incidents.length; i<max; i++) {
var incident = api_result.incidents[i];
Spice.registerHelper("TravisStatus_iterateOver", function(list, block) {
var result = '';
for(var i=0,max=list.length; i<max; i++) {
env.ddg_spice_bootic = function(api_result) {
if (!api_result || $.isEmptyObject(api_result.products)) {
return Spice.failed('bootic');
var query = api_result.input_query ?
'?initial=1&q=' + encodeURIComponent(api_result.input_query) : '';
// TODO: Use sorting block for this!
var result = [];
for(var i = 0; i < api_result.sorted.length; i++) {
result.push(api_result.products[api_result.sorted[i]]);
}
name: 'Products',
data: result,
"use strict";
env.ddg_spice_uv = function(api_result){
// Validate the response (customize for your Spice)
if (!api_result || api_result.error || !api_result.length || api_result.length !== 1) {
//extract city and date from first result
var result = api_result[0];
var city = DDG.capitalizeWords(result.CITY.toLowerCase()),
state = result.STATE,
uvIndex = parseInt(result.UV_INDEX,10),
risk = "extreme",
state: state,
uvIndexName: result.UV_INDEX,
"use strict";
env.ddg_spice_bible = function(api_result) {
// Validity check
if (!api_result || !api_result.length){
var result = api_result[0];
name: 'Answer',
data: result,
// text come with a link at the end that needs to be removed
var rmlink = '<a style=\"\" target=\"_blank\" href=\"http:\/\/bible.org\/page.php?page_id=3537\">©NET<\/a>';
function getParameter(query, trigger, count){
var regex, result;
result = query.match(regex);
if(result === null) return null; //no match
result = result[1].replace(",", "."); //stores the result as string and replace commas with points
result = parseFloat(result);
return result;
result = query.match(regex);
if(result === null) return null; //no match
result = result[1].split(/\s+/); //split up the numbers
for(var i = 0, l = result.length; i < l; ++i){
result[i].replace(",", ".");
//Global Vars
var HN_Global = {};
HN_Global.result = '';
HN_Global.discussions = [];
var snippet = [];
var terms = res["request"]["q"];
var limit = (res["request"]["limit"] < res["hits"]) ? res["request"]["limit"] : res["hits"];
//At least 1 result
//Display first 3 stories results
snippet[2] = '';
var c0 = 0;
var c1 = 0;
env.ddg_spice_movie = function(api_result) {
if (!api_result || !api_result.movies || !api_result.movies.length) {
return Spice.failed('movie');
// Get original query.
var script = $('[src*="/js/spice/movie/"]')[0],
//Check if the query contains a year
var year = query.match(/\d{4}/),
singleResult = [];
///Check movie year and title against query
$.each(api_result.movies, function(key, result) {
if (!result.title.match(/\d{4}/)) { // don't run this check if the movie title contains a date
if (result.year == year && query.replace(year, '').trim() == result.title.toLowerCase()) {
singleResult.push(result);