var gaAccount = 'UA-XXXXXXXX-X';

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = 'https://ssl.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

var _gaq = _gaq || [];
_gaq.push(['_setAccount', gaAccount]);
_gaq.push(['_trackPageview']);

searchJira = function(word){
  var query = word.selectionText;
  var baseUrl =  localStorage['baseUrl'] || '/options.html?'; //redirect to options if not provided
  var searchSuffix = localStorage['searchSuffix'];
  console.log(baseUrl+searchSuffix);
  chrome.tabs.create({url: baseUrl + searchSuffix + query});
  _gaq.push(['_trackEvent','searchJira','success']);  
};
chrome.runtime.onInstalled.addListener(function() {
  	chrome.contextMenus.create({
		id:"jirasearch",
		title: "Search JIRA",
		contexts:["selection"],
		onclick: searchJira
    });
});


//redirection
 
var getQueryString = function ( field, url ) {
    var href = url ? url : window.location.href;
    var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
    var string = reg.exec(href);
    return string ? string[1] : null;
};

function redirect(){
	var jira = getQueryString('jira');
	if(jira){
		try{
			chrome.storage.sync.get('baseUrl', function(items) {
			var baseurl, browseurl;
			baseurl = items['baseUrl'] || chrome.extension.getURL("options.html")+"?";
			  browseurl = baseurl+'browse/';
			_gaq.push(['_trackEvent','clickLinkToJira','success']);  
			_gaq.push(function(){ 
				window.location.href = browseurl+jira;
				});
			});
		} catch(ex) {
			_gaq.push(['_trackEvent','clickLinkToJira','failure']);  	
		}
	}else{
			_gaq.push(['_trackEvent','backgroundInitialized','success']);  	
	}
}
document.addEventListener('DOMContentLoaded', redirect);

@@ -435,24 +435,96 @@
 tionText;%0A  
+chrome.storage.sync.get(%5B'baseUrl', 'searchSuffix'%5D, function(items) %7B%0A%09
 var baseUrl 
@@ -526,28 +526,21 @@
 eUrl =  
-localStorage
+items
 %5B'baseUr
@@ -602,18 +602,17 @@
 rovided%0A
-  
+%09
 var sear
@@ -626,20 +626,13 @@
 x = 
-localStorage
+items
 %5B'se
@@ -645,18 +645,17 @@
 ffix'%5D;%0A
-  
+%09
 console.
@@ -681,18 +681,17 @@
 uffix);%0A
-  
+%09
 chrome.t
@@ -741,16 +741,22 @@
 uery%7D);%0A
+  %7D);%0A
   _gaq.p

fix inconsistent use of localstorage to chrome.storage