Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (75 sloc) 2.039 kb
751b29cb »
2011-03-10 Initial commit.
1 <script>
2 // This event is fired each time the user updates the text in the omnibox,
3 // as long as the extension's keyword mode is still active.
4
5 // Get all available couch dbs
6 function getDatabases() {
7 var url = "http:///localhost:5984/_all_dbs";
8
9 var req = new XMLHttpRequest();
10 req.open("GET", url, false);
11 req.send();
12 response=req.responseText;
13 console.log('getDb result: ' + response);
14 return eval(response)
15 }
16
17 chrome.omnibox.onInputChanged.addListener(
18 function() {
19 var favorite = localStorage["preferred_couchdb"];
20 if (!favorite)
21 {
22 couchurl = "localhost:5984";
23 }
24 else
25 {
26 couchurl = favorite;
27 }
28 console.log('favorite couch: ' + couchurl);
29
30 allDbs = getDatabases()
31 console.log('allDbs: ' + allDbs);
32 });
33
34
35 chrome.omnibox.onInputChanged.addListener(
36 function(text, suggest) {
37 console.log('inputChanged: ' + text);
38 suggestions = [];
39 for(var i=0,len=allDbs.length; value=allDbs[i], i<len; i++)
40 {
41 if(value.indexOf(text) != -1)
42 {
43 suggestions.push({content: value , description: "Database <match>" + value + "</match>"});
44 console.log('item is: ' + value);
45 }
46 }
47 suggest(suggestions);
48 });
49
50 function navigate(url) {
51 chrome.tabs.getSelected(null, function(tab) {
52 chrome.tabs.update(tab.id, {url: url});
53 });
54 }
55
56 function resetDefaultSuggestion() {
57 chrome.omnibox.setDefaultSuggestion({
58 description: '<url><match>couch:</match></url> Couchdb _utils or db'
59 });
60 }
61
62 resetDefaultSuggestion();
63
64 // This event is fired with the user accepts the input in the omnibox.
65 chrome.omnibox.onInputEntered.addListener(
66 function(text) {
67 console.log('inputEntered: ' + text);
68
69
70
71 if(text == '')
72 {
73 navigate("http://" + couchurl + "/_utils")
74 }
75 else
76 {
77 // Navigate to best match
78 if(suggestions.length > 0)
79 {
80 navigate("http://" + couchurl + "/_utils/database.html?" + suggestions[0].content)
81 }
82 else
83 {
84 navigate("http://" + couchurl + "/_utils")
85 }
86 }
87 });
88 </script>
Something went wrong with that request. Please try again.