rem: document.GM_registerMenuCommand = 
add: e.view.GM_registerMenuCommand = 
context: function CommandManager() {  var nextDocId = 1;  var docIdsInUse = [];  var docMenuCommands = {};    this.loadDoc = function(e) {    var docId;    var document = e.originalTarget;    if (!document.__gmId) {      document.__gmId = nextDocId++;    }    docMenuCommands[document.__gmId] =       window.document.createElement('menupopup');        //enclose the docId to register on.    //simplifies API, and disallows registering commands on a doc other     //than the one the script's on.    docId = document.__gmId;        document.GM_registerMenuCommand =       function(commandName, commandCallback) {         registerMenuCommand(docId, commandName, commandCallback);      };   }    this.unloadDoc = function(e) {    var doc = e.originalTarget;    if (doc.__gmId) {      delete docMenuCommands[doc.__gmId];    }  }          this.initToolsMenu = function(commandMenu) {    var doc = getActiveDocument();    if (commandMenu.firstChild == docMenuCommands[doc.__gmId]) {      return;    }    //show only the popup that's appropriate.    if (commandMenu.firstChild) {      commandMenu.removeChild(commandMenu.firstChild);    }    var commandPopup = docMenuCommands[doc.__gmId];    if (commandPopup) {      commandMenu.appendChild(commandPopup);          var menuItems = commandPopup.childNodes;      for (var i = 0; i < menuItems.length; i++) {        //couldn't just add listeners when the popup was created         //because removing the popup removes all listeners as well.        menuItems[i].addEventListener("command",           menuItems[i].__gmCommandFunc, false);      }            commandMenu.setAttribute("disabled",         commandPopup.childNodes.length == 0);    }        } //end initToolsMenus    function registerMenuCommand(docId, commandName, commandFunc) {    var menuItem;    var previousItems;        menuItem = window.document.createElement('menuitem');    menuItem.setAttribute("label", commandName);    menuItem.__gmCommandFunc = commandFunc;    //menuItem.addEventListener("command", commandFunc, false);    previousItems = docMenuCommands[docId].childNodes;        var i=0;    var nextNode=null;    while (i < previousItems.length) {      if (commandName.toLowerCase() <           previousItems[i].getAttribute('label').toLowerCase())       {        nextNode = previousItems[i];        break;      }      i++;    }    docMenuCommands[docId].insertBefore(menuItem, nextNode);  }    function getActiveDocument() {    var tabbrowser = ge("content");    return tabbrowser.selectedBrowser.contentDocument;  }}
meta: 4585	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/4585/d86a63b95a342e64216ae0c9e5a4175acf8ca9a9/greasemonkey.js/buggy/src/content/greasemonkey.js