// ==UserScript==
// @name           Paste And Go
// @namespace      http://www.xuldev.org/
// @description    Adds 'Paste and Go' menu to the context menu in Location bar.
// @include        main
// @compatibility  Firefox 3.0, 3.5, 3.6b4
// @author         Gomita
// @version        1.1.20091203
// @homepage       http://www.xuldev.org/misc/ucjs.php
// ==/UserScript==
// @version        1.1.20091203 Now compatible with Firefox 3.0 - 3.6b4

document.getElementById("urlbar").addEventListener("popupshowing", function(event) {
	const eltID = "pasteandgo-menuitem";
	var menupopup = event.originalTarget;
	var refChild = menupopup.getElementsByAttribute("cmd", "cmd_paste")[0];
	var canPaste = refChild.getAttribute("disabled") == "true";
	var menuitem = document.getElementById(eltID);
	if (!menuitem) {
		var pasteAndGo = function(event) {
			goDoCommand("cmd_paste");
			if ("handleURLBarCommand" in window)
				// [Firefox3.0]
				handleURLBarCommand(event);
			else
				// [Firefox3.5]
				gURLBar.handleCommand(event);
			menupopup.hidePopup();
		};
		menuitem = document.createElement("menuitem");
		menuitem.id = eltID;
		menuitem.setAttribute("label", "Paste and Go");
		menuitem.setAttribute("accesskey", "G");
		menuitem.addEventListener("command", pasteAndGo, false);
		menupopup.insertBefore(menuitem, refChild.nextSibling);
	}
	menuitem.setAttribute("disabled", canPaste.toString());
}, false);
