Commits

Rich Manalang [Atlassian] committed 98f3d55

v1.2 added OmniBox support. Now you can search eac from Chrome's OmniBox using the 'eac' keyword

Comments (0)

Files changed (4)

eac_activitystream.crx

Binary file modified.

src/background.html

+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
+<script src="js/omnibox.js" type="text/javascript" charset="utf-8"></script>

src/js/omnibox.js

+var currentRequest = null;
+
+chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
+//  if (currentRequest != null) {
+//    currentRequest.onreadystatechange = null;
+//    currentRequest.abort();
+//    currentRequest = null;
+//  }
+
+//	updateDefaultSuggestion(text);
+
+	currentRequest = search(text, function(json) {
+		var results = [];
+    var data = JSON.parse(json);
+
+
+    var types = data.contentNameMatches;
+    for (var i = 0, type; i < types.length && (type = types[i]); i++) {
+      var entries = type;
+      for (var j = 0, entry; j < entries.length && (entry = entries[j]); j++) {
+        if (entry.className === 'search-for') continue;
+        var className = entry.className.split('-').splice(-1);
+        var description = '<dim>[' + className + ']</dim> <match>' + entry.name + '</match> <url>https://extranet.atlassian.com' + entry.href + '</url>';
+        var content = "https://extranet.atlassian.com" + entry.href;
+
+        results.push({
+          content: content,
+          description: description
+        });
+      }
+    }
+
+    suggest(results);
+	});
+});
+
+function resetDefaultSuggestion() {
+  chrome.omnibox.setDefaultSuggestion({
+    description: '<dim>Search EAC with [query]</dim>'
+  });
+}
+
+resetDefaultSuggestion();
+
+function updateDefaultSuggestion(text) {
+  chrome.omnibox.setDefaultSuggestion({
+    description: '<dim>Search EAC with:</dim><match>%s</match>'
+  });
+}
+
+chrome.omnibox.onInputStarted.addListener(function() {
+  updateDefaultSuggestion('');
+});
+
+chrome.omnibox.onInputCancelled.addListener(function() {
+  resetDefaultSuggestion();
+});
+
+function search(query, callback) {
+  if (query.length < 3) return;
+	var url = "https://extranet.atlassian.com/json/contentnamesearch.action?query=" + query;
+  url = encodeURI(url);
+
+
+	var req = new XMLHttpRequest();
+	req.open("GET", url, true);
+	req.setRequestHeader("Accept", "application/json");
+	req.onreadystatechange = function() {
+		if (req.readyState == 4) {
+			callback(req.response);
+		}
+	}
+	req.send(null);
+	return req;
+}
+
+function navigate(url) {
+  if (!/^http/.test(url)) {
+    url = encodeURI("https://extranet.atlassian.com/dosearchsite.action?queryString=" + url);
+  }
+
+	chrome.tabs.getSelected(null, function(tab) {
+		chrome.tabs.update(tab.id, {
+			url: url
+		});
+	});
+}
+
+chrome.omnibox.onInputEntered.addListener(navigate);
+

src/manifest.json

 {
-   "browser_action": {
-      "default_icon": "images/icon16.png",
-      "default_popup": "popup.html",
-      "default_title": "EAC Activity Stream"
-   },
-   "description": "Easily view the EAC Activity Stream through a Chrome Extension",
-   "icons": {
-      "128": "images/icon128.png",
-      "16": "images/icon16.png",
-      "48": "images/icon48.png"
-   },
-   "name": "EAC Activity Stream",
-   "permissions": [ "https://extranet.atlassian.com/*", "tabs"],
-   "version": "1.1"
+	"browser_action": {
+		"default_icon": "images/icon16.png",
+		"default_popup": "popup.html",
+		"default_title": "EAC Activity Stream"
+	},
+	"description": "Easily view the EAC Activity Stream through a Chrome Extension",
+	"icons": {
+		"128": "images/icon128.png",
+		"16": "images/icon16.png",
+		"48": "images/icon48.png"
+	},
+	"name": "EAC Bling!",
+	"background_page": "background.html",
+	"omnibox": {
+		"keyword": "eac"
+	},
+	"permissions": ["https://extranet.atlassian.com/*", "tabs"],
+	"homepage_url": "https://extranet.atlassian.com/display/~rmanalang/2011/09/11/EAC+Activity+Stream+Chrome+Extension",
+	"version": "1.2"
 }