Browse Source

fixed a bug of counting running scripts

Signed-off-by: Gerald <[email protected]>
Gerald 11 years ago
parent
commit
800e8fbcfa
1 changed files with 5 additions and 3 deletions
  1. 5 3
      injected.js

+ 5 - 3
injected.js

@@ -43,7 +43,7 @@ function getPopup(){
 function getBadge(){
 	// XXX: only scripts run in top level window are counted
 	if(top===window)
-		chrome.runtime.sendMessage({cmd:'SetBadge',data:ids.length});
+		chrome.runtime.sendMessage({cmd:'SetBadge',data:total});
 }
 
 // Communicator
@@ -406,7 +406,7 @@ var comm={
 		});
 		run(start);comm.checkLoad();
 	},
-},menu=[],ids=[];
+},menu=[],ids=[],total=0;
 function handleC(e){
 	var o=JSON.parse(e.attrName),maps={
 		SetValue:function(o){
@@ -470,7 +470,9 @@ function initCommunicator(){
 	chrome.runtime.sendMessage({cmd:'GetInjected',data:location.href},loadScript);
 }
 function loadScript(o){
-	o.scripts.forEach(function(i){ids.push(i.id);});
+	o.scripts.forEach(function(i){
+		ids.push(i.id);if(i.enabled) total++;
+	});
 	comm.post({cmd:'LoadScript',data:o});
 }
 initCommunicator();