| 646 | /* ######### TM/GM Functions ############ */ |
| 647 | |
| 648 | var TM_registerMenuCommand = function(name, fn) { |
| 649 | var menuId = TM_context_id + '#' + name; |
| 650 | var onUnload = function() { |
| 651 | if (V) console.log("env: unRegisterMenuCMD due to unload " + fn.toString()); |
| 652 | chromeEmu.extension.sendMessage({method: "unRegisterMenuCmd", name: name, id: menuId}, function(response) {}); |
| 653 | }; |
| 654 | var resp = function(response) { |
| 655 | // response is send, command is unregisterd @ background page |
| 656 | window.removeEventListener('unload', onUnload, false); |
| 657 | if (response.run) { |
| 658 | if (V) console.log("env: execMenuCmd " + fn.toString()); |
| 659 | window.setTimeout(function () { fn(); }, 1); |
| 660 | // re-register for next click |
| 661 | TM_registerMenuCommand(name, fn); |
| 662 | } |
| 663 | }; |
| 664 | window.addEventListener('unload', onUnload, false); |
| 665 | if (V) console.log("env: registerMenuCmd " + fn.toString()); |
| 666 | chromeEmu.extension.sendMessage({method: "registerMenuCmd", name: name, id: TM_context_id, menuId: menuId}, resp); |
| 667 | }; |
| 668 | |
| 669 | var TM_openInTab = function(url, options) { |
| 670 | // retrieve tabId to have a chance of closing this window lateron |