Skip to content

Instantly share code, notes, and snippets.

@jaredhirsch
Last active July 7, 2017 21:33
Show Gist options
  • Save jaredhirsch/0754718a29a471133dab27e9cdf51cb9 to your computer and use it in GitHub Desktop.
Save jaredhirsch/0754718a29a471133dab27e9cdf51cb9 to your computer and use it in GitHub Desktop.
messin with firefox context menu
Cu.import('resource://gre/modules/Console.jsm');
// get a pointer to the context menu
// TODO: seems to be per-window. how to iterate and attach to all windows? :-(
menu = document.getElementById("contentAreaContextMenu");
// create a hidden menu item
xuldoc = menu.ownerDocument;
item = xuldoc.createElement('menuitem');
item.setAttribute('id', 'minvid-item');
item.setAttribute('label', 'console.log selected URL');
// TODO: wait on toggling visibility for now
// item.setAttribute('hidden', true);
item.setAttribute('oncommand', () => {
console.log('the link URL is: ', gContextMenu.linkURL);
});
// append the item
menu.appendChild(item);
menu.addEventListener('popupshowing', () => {
/* if (gContextMenu.linkURL) {
item.removeAttribute('hidden');
} else {
item.setAttribute('hidden', true);
}
*/
// TODO: doesn't work...
console.log('gContextMenu.linkURL is: ', gContextMenu.linkURL);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment