Index: chrome/background.js |
=================================================================== |
--- a/chrome/background.js |
+++ b/chrome/background.js |
@@ -370,10 +370,12 @@ |
handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged |
}; |
+ var contextMenuItems = []; |
+ var isContextMenuHidden = true; |
ext.contextMenus = { |
- create: function(title, contexts, onclick) |
+ addMenuItem: function(title, contexts, onclick) |
{ |
- chrome.contextMenus.create({ |
+ contextMenuItems.push({ |
title: title, |
contexts: contexts, |
onclick: function(info, tab) |
@@ -381,10 +383,39 @@ |
onclick(info.srcUrl, new Tab(tab)); |
} |
}); |
+ this.showMenuItems(); |
}, |
- removeAll: function(callback) |
+ removeMenuItems: function() |
{ |
- chrome.contextMenus.removeAll(callback); |
+ contextMenuItems = []; |
+ this.hideMenuItems(); |
+ }, |
+ showMenuItems: function() |
+ { |
+ if (!isContextMenuHidden) |
+ return; |
+ |
+ chrome.contextMenus.removeAll(function() |
+ { |
+ for (var i = 0; i < contextMenuItems.length; i++) |
+ { |
+ var item = contextMenuItems[i]; |
+ chrome.contextMenus.create({ |
+ title: item.title, |
+ contexts: item.contexts, |
+ onclick: item.onclick |
+ }); |
+ } |
+ }); |
+ isContextMenuHidden = false; |
+ }, |
+ hideMenuItems: function() |
+ { |
+ if (isContextMenuHidden) |
+ return; |
+ |
+ chrome.contextMenus.removeAll(); |
+ isContextMenuHidden = true; |
} |
}; |
})(); |