public
Last active

Bible-Gateway Ubiquity command

  • Download Gist
bible-gateway-ubiquity.js
JavaScript
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
// 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);
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.