ahmedre (owner)

Revisions

gist: 113971 Download_button fork
public
Description:
quran ubiquity plugin
Public Clone URL: git://gist.github.com/113971.git
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
75
76
77
78
79
80
81
82
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);
});
}
})