console.log("Loading Tridion Extension");

var callback;
var filters =
{
	url: 
	[
		//{hostSuffix:"epocms.www8.hp.com"}
		{pathContains:"ListFilters/SearchListBar.aspx"}
	]
};

// chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// 	chrome.tabs.executeScript(tab.tabId, {"code":'console.log("hello world from the other side")'}, function (){
// 		console.log("Executed Script 2");
// 	});
// }); 

// UTILS
function msg_log(str)
{
	console.info(str);
}


/*
	Listen to load of Tridion Dashboard and inject the extension
*/
callback = function(tab) {
	var details;
	console.debug('Loading Tridion Extension');

	details = {file:"jquery_3.min.js", runAt: "document_end"};
	chrome.tabs.executeScript( tab.tabId, details, msg_log("loaded jquery_3"));

	details = {file:"popup.js", runAt:"document_end"};
	chrome.tabs.executeScript( tab.tabId, details, msg_log("loaded tridion_ext"));

	chrome.tabs.sendMessage(tab.tabId, {"action": "dashboard_load"}, function (){
		console.debug("Finished load of tridion!");
	});
}
chrome.webNavigation.onCompleted.addListener(callback, filters);

/*
	Click listener for extension button
*/
chrome.browserAction.onClicked.addListener(function(tab) {
  // No tabs or host permissions needed!
  console.log('browserAction');
  chrome.tabs.executeScript({
    code: 'document.body.style.backgroundColor="red"'
  });
});
callback = null;
@@ -40,439 +40,8 @@
 );%0A%0A
-var callback;%0Avar filters =%0A%7B%0A%09url: %0A%09%5B%0A%09%09//%7BhostSuffix:%22epocms.www8.hp.com%22%7D%0A%09%09%7BpathContains:%22ListFilters/SearchListBar.aspx%22%7D%0A%09%5D%0A%7D;%0A%0A// chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) %7B%0A// %09chrome.tabs.executeScript(tab.tabId, %7B%22code%22:'console.log(%22hello world from the other side%22)'%7D, function ()%7B%0A// %09%09console.log(%22Executed Script 2%22);%0A// %09%7D);%0A// %7D); %0A%0A// UTILS%0Afunction msg_log(str)%0A%7B%0A%09console.info(str);%0A%7D%0A
 %0A%0A/*
@@ -107,26 +107,62 @@
 ion%0A*/%0Ac
-allback = 
+hrome.webNavigation.onCompleted.addListener(%0A%09
 function
@@ -162,23 +162,22 @@
 unction(
-tab) 
+)%0A%09
 %7B%0A
+%09
 %09var det
@@ -180,18 +180,45 @@
  details
+ = %7BrunAt: %22document_end%22%7D
 ;%0A
+%09
 %09console
@@ -251,32 +251,33 @@
 tension');%0A%0A
+%09
 %09details
  = %7Bfile:%22jq
@@ -264,25 +264,27 @@
 %09details
- = %7Bfile:
+%5B%22file%22%5D = 
 %22jquery_
@@ -296,34 +296,11 @@
 .js%22
-, runAt: %22document_end%22%7D
 ;%0A
+%09
 %09chr
@@ -373,24 +373,25 @@
 _3%22));%0A%0A
+%09
 %09details
  = %7Bfile
@@ -386,52 +386,32 @@
 ails
- = %7Bfile:%22popup.js%22, runAt:%22document_end%22%7D
+%5B%22file%22%5D = %22popup.js%22
 ;%0A
+%09
 %09chr
@@ -487,16 +487,17 @@
 xt%22));%0A%0A
+%09
 %09chrome.
@@ -567,16 +567,17 @@
 ion ()%7B%0A
+%09
 %09%09consol
@@ -618,77 +618,92 @@
 %22);%0A
+%09
 %09%7D);%0A
+%09
 %7D%0A
-chrome.webNavigation.onCompleted.addListener(callback, filters
+%09// URLfilter%0A%09, %7Burl:%5B%7BpathContains:%22ListFilters/SearchListBar.aspx%22%7D%5D%7D%09%09%0A
 );%0A%0A
@@ -975,20 +975,59 @@
 %7D);%0A
-callback = null;
+%0A// UTILS%0Afunction msg_log(str)%0A%7B%0A%09console.info(str);%0A%7D

Refactor background