Created
January 22, 2010 17:21
-
-
Save dtjohnso/283936 to your computer and use it in GitHub Desktop.
Bible-Gateway Ubiquity command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// converted for the Ubiquity Parser 2 by Duncan Johnson on 1/22/2010 | |
// Response to conversation here http://bit.ly/6TO8Xg | |
noun_version_name = new CmdUtils.NounType("version", ["nkjv", "kjv", "niv"]); | |
CmdUtils.CreateCommand( | |
{ | |
names: ['bible-search'], | |
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'passage'}, | |
{role: 'format', nountype: noun_version_name, label: 'version'}], | |
//icon: "http://www.zenorsoft.com/ubiquity/Bible_Search.jpg", //looks like a copy of the Logos logo, so I commented it out because I'm not sure about licensing | |
//homepage: "http://www.zenorsoft.com", | |
homepage: "http://gist.github.com/gists/283936/edit", | |
author: { name: "Jon Zenor", email: "Jon@ZenorSoft.com" }, | |
license: "GPL", | |
description: "Search for a Bible Passage", | |
help: "Give a bible passage to look up the text. Optionally you can give a version by specifying \'in kjv\' (or niv, nkjv).", | |
preview: function(pblock, args) | |
{ | |
var versions = { | |
"niv" : "31", | |
"nkjv" : "50", | |
"kjv" : "9" | |
}; | |
var version = versions[args.format.text]; | |
if(version == "" || version == null) | |
{ | |
version = versions.nkjv; | |
} | |
var passageUrl = "http://www.biblegateway.com/passage/?search=" + args.object.text + ";&version=" + version; | |
CmdUtils.previewAjax(pblock, | |
{ | |
url: passageUrl, | |
dataType: "html", | |
success: function(data) | |
{ | |
var passageRegex = new RegExp('<div class=\\"result-text-style-normal\\">\\n.+[\\n|</div>]', 'mgi'); | |
var match = passageRegex.exec(data); | |
if(match != null) | |
{ | |
var msg = '${passage}'; | |
pblock.innerHTML = CmdUtils.renderTemplate(msg, { passage: match[0]}); | |
} | |
else | |
{ | |
pblock.innerHTML = "No match found for passage: " + args.object.text ; | |
} | |
} | |
}); | |
}, | |
execute: function(args) | |
{ | |
var versions = { | |
"niv" : "31", | |
"nkjv" : "50", | |
"kjv" : "9" | |
}; | |
var version = versions[args.format.text]; | |
if(version == "" || version == null) | |
{ | |
version = versions.nkjv; | |
} | |
Utils.openUrlInBrowser("http://www.biblegateway.com/passage/?search=" + args.object.text + ";&version=" + version); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment