Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Copy Url add-on

  • Loading branch information...
commit ee482d27cbc3aa4b0470bd127ce5213363e3ff2b 0 parents
@Mardak authored
Showing with 54 additions and 0 deletions.
  1. +45 −0 lib/main.js
  2. +9 −0 package.json
45 lib/main.js
@@ -0,0 +1,45 @@
+// Add key event listeners to main browser windows
+const {WindowTracker} = require("window-utils");
+new WindowTracker({
+ onTrack: function({document, gURLBar}) {
+ if (document.documentElement.getAttribute("windowtype") != "navigator:browser")
+ return;
+
+ gURLBar.addEventListener("keydown", handleKey, true);
+ },
+
+ onUntrack: function({document, gURLBar}) {
+ if (document.documentElement.getAttribute("windowtype") != "navigator:browser")
+ return;
+ gURLBar.removeEventListener("keydown", handleKey, true);
+ }
+});
+
+// Detect cmd/ctrl-enter to do stuff
+function handleKey(event) {
+ switch (event.keyCode) {
+ case event.DOM_VK_ENTER:
+ case event.DOM_VK_RETURN:
+ if (event.metaKey || event.ctrlKey) {
+ let gURLBar = event.target;
+ if (gURLBar.popupOpen && gURLBar.popup.selectedIndex >= 0) {
+ event.preventDefault();
+
+ // Copy the selected url
+ let url = gURLBar.controller.getValueAt(gURLBar.popup.selectedIndex);
+ url = url.replace(/^moz-action:[^,]+,/, "");
+ require("clipboard").set(url);
+
+ // Close the popup and restore the url
+ gURLBar.closePopup();
+ gURLBar.controller.handleEscape();
+
+ // Refocus the page and paste the url
+ let window = gURLBar.ownerDocument.defaultView;
+ window.gBrowser.selectedBrowser.focus();
+ window.document.getElementById("cmd_paste").doCommand();
+ }
+ }
+ break;
+ }
+}
9 package.json
@@ -0,0 +1,9 @@
+{
+ "description": "Press ctrl/cmd-enter on a selected location bar result to copy and paste it into the page.",
+ "license": "MPL 2.0",
+ "author": "Edward Lee (Mardak)",
+ "version": "1",
+ "fullName": "Copy Selected",
+ "id": "jid1-aiZkBwoQfhZOBQ",
+ "name": "copyselected"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.