(function() {

  var wicketsource, menu;

  menu = chrome.contextMenus.create({
    title: "Wicket Source",
    contexts: ["all"],
    onclick: function (info) {
      if (wicketsource) {
        var ajax = new XMLHttpRequest();
        var url = "http://localhost:9123/open?src=" + encodeURIComponent(wicketsource);
        ajax.open("GET", url, true);
        ajax.send();
      }
    },
    enabled: false
  });

  chrome.extension.onRequest.addListener(function (request) {
    if (request.hasOwnProperty('wicketsource')) {
      wicketsource = request.wicketsource;
      if (wicketsource != null) {
        var idx = wicketsource.indexOf(':');
        if (idx > -1) {
          wicketsource = wicketsource.substring(idx + 1);
        }
        wicketsource = wicketsource.replace(/\.java:/, ':');
        chrome.contextMenus.update(menu, {
          enabled: true,
          title: "Wicket Source - " + wicketsource
        });
      } else {
        chrome.contextMenus.update(menu, {
          enabled: false,
          title: "Wicket Source"
        });
      }
    }
  });


})();

@@ -11,38 +11,14 @@
 ) %7B%0A
-%0A
   var 
-wicketsource, menu;%0A%0A  
 menu
@@ -96,293 +96,64 @@
 s: %5B
+ 
 %22all%22
+ 
 %5D,%0A    
-onclick: function (info) %7B%0A      if (wicketsource) %7B%0A        var ajax = new XMLHttpRequest();%0A        var url = %22http://localhost:9123/open?src=%22 + encodeURIComponent(wicketsource);%0A        ajax.open(%22GET%22, url, true);%0A        ajax.send();%0A      %7D%0A    %7D,%0A    enabled: false
+enabled: false,%0A    onclick: function() %7B%7D
 %0A  %7D
@@ -274,28 +274,22 @@
 %7B%0A      
-wicketsource
+var ws
  = reque
@@ -320,33 +320,159 @@
 f (w
+s == null) %7B%0A        chrome.contextMenus.update(menu, %7B%0A          enabled: false,%0A          title: %22W
 icket
-s
+ S
 ource
- != null) %7B%0A  
+%22%0A        %7D);%0A        return;%0A      %7D%0A
     
@@ -484,27 +484,17 @@
  idx = w
-icketsource
+s
 .indexOf
@@ -496,26 +496,24 @@
 dexOf(':');%0A
-  
       if (id
@@ -534,37 +534,15 @@
     
-  wicketsource = wicketsource
+ws = ws
 .sub
@@ -564,26 +564,24 @@
 ;%0A      
-  
 %7D%0A      
   wicket
@@ -576,37 +576,15 @@
     
-  wicketsource = wicketsource
+ws = ws
 .rep
@@ -601,26 +601,24 @@
 va:/, ':');%0A
-  
       chrome
@@ -646,34 +646,32 @@
 menu, %7B%0A        
- 
- 
 enabled: true,%0A 
@@ -669,18 +669,16 @@
 : true,%0A
-  
         
@@ -710,148 +710,244 @@
  + w
-icketsource%0A        %7D);%0A      %7D else %7B%0A        chrome.contextMenus.update(menu, %7B%0A          enabled: false,%0A          title: %22Wicket Source%22
+s,%0A        onclick: function () %7B%0A          var ajax = new XMLHttpRequest();%0A          var url = %22http://localhost:9123/open?src=%22 + encodeURIComponent(request.wicketsource);%0A          ajax.open(%22GET%22, url, true);%0A          ajax.send();
 %0A   
@@ -952,26 +952,24 @@
        %7D
-);
 %0A      %7D
 %0A    %7D%0A 
@@ -956,24 +956,26 @@
    %7D%0A      %7D
+);
 %0A    %7D%0A  %7D);
@@ -979,12 +979,11 @@
 %7D);%0A
-%0A%0A
 %7D)();%0A
+%0A

Improve context menu event handling