Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
quran ubiquity plugin
CmdUtils.CreateCommand({
name: "search-quran",
homepage: "http://whatstheplot.com",
icon: "http://alpha.quranicrealm.com/images/favicon.ico",
takes: {"query": noun_arb_text},
preview: function( pblock, query ) {
if (query.text.length < 1){
pblock.innerHTML = "will search the quran for the specified text";
return;
}
var baseUrl = "http://alpha.api.searchquran.net/v1/search";
var params = {q: query.text};
jQuery.getJSON(baseUrl, params, function(data){
var matches = 0;
var resultText = "";
jQuery.each(data.results, function(i, item){
matches++;
if (matches < 4){
resultText += "<b>" + item.sura + ":" + item.ayah + "</b> - ";
resultText += "<div style=\"direction:rtl\">" +
item.arabic + "</div>";
resultText += "<br>" + item.match + "<br><br>";
}
});
if (matches == 0)
pblock.innerHTML = "no results found.";
else pblock.innerHTML = resultText;
});
},
execute: function( query ) {
var url = "http://alpha.searchquran.net/search?q={QUERY}";
url = url.replace("{QUERY}", query.text);
Utils.openUrlInBrowser(url);
}
})
var quran_type_link = new CmdUtils.NounType("language",
["arabic", "arabic [no tashkeel]", "english - yusuf ali", "english - muhsin khan",
"english - pickthal", "english - sahih international", "english - dr. ghali",
"english - shakir", "transliteration"]
);
CmdUtils.CreateCommand({
name: "get-ayah",
homepage: "http://whatstheplot.com",
icon: "http://alpha.quranicrealm.com/images/favicon.ico",
takes: {"sura:ayah": /[0-9]+:[0-9]+/},
modifiers: {"in": quran_type_link},
preview: "will insert the specified ayah into the selection",
execute: function( number, modifiers ) {
var url = "http://alpha.api.searchquran.net/v1/sura/";
parts = number.text.split(':');
url = url + parts[0] + '/' + parts[1];
resultText = '';
lang = 2;
if (modifiers.in){
translation = modifiers.in.text.toLowerCase();
// this isn't good - need to fix the api
if (translation.indexOf('no tashkeel')!=-1){ lang = 4; }
else if (translation.indexOf('arabic')!=-1){ lang = 2; }
else if (translation.indexOf('muhsin')!=-1){ lang = 8; }
else if (translation.indexOf('yusuf')!=-1){ lang = 16; }
else if (translation.indexOf('pickthal')!=-1){ lang = 32; }
else if (translation.indexOf('shakir')!=-1){ lang = 64; }
else if (translation.indexOf('sahih')!=-1){ lang = 256; }
else if (translation.indexOf('ghali')!=-1){ lang = 512; }
else if (translation.indexOf('transliteration')!=-1){ lang = 128; }
}
var params = {langs: lang};
jQuery.getJSON(url, params, function(data){
jQuery.each(data.verses, function(i, item){
resultText += item[lang];
});
CmdUtils.setSelection(resultText);
});
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment