diff options
| author | Murphy McMahon | 2011-07-14 09:35:14 -0300 |
|---|---|---|
| committer | Murphy McMahon | 2011-07-14 09:35:14 -0300 |
| commit | 6ccdb189c575e5f1c539e7fed9f39d2f683b16d4 (patch) | |
| tree | 123a912e36fac9d97937fd9f5a5e8f1d0c39cafc /linkHints.js | |
| parent | 24bb9827ebb86fe8b59d2959aa1dd40f98657049 (diff) | |
| download | vimium-6ccdb189c575e5f1c539e7fed9f39d2f683b16d4.tar.bz2 | |
Added clipboard copying to linkHints mode (default binding: 'Y')
Diffstat (limited to 'linkHints.js')
| -rw-r--r-- | linkHints.js | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/linkHints.js b/linkHints.js index 9219fee6..75b0fe53 100644 --- a/linkHints.js +++ b/linkHints.js @@ -8,13 +8,14 @@ * In 'filter' mode, our link hints are numbers, and the user can narrow down the range of possibilities by * typing the text of the link itself. */ - var linkHints = { hintMarkers: [], hintMarkerContainingDiv: null, // The characters that were typed in while in "link hints" mode. shouldOpenInNewTab: false, shouldOpenWithQueue: false, + // flag for copying link instead of opening + shouldCopyLinkUrl: false, // Whether link hint's "open in current/new tab" setting is currently toggled openLinkModeToggle: false, // Whether we have added to the page the CSS needed to display link hints. @@ -48,15 +49,17 @@ var linkHints = { })(), // We need this as a top-level function because our command system doesn't yet support arguments. - activateModeToOpenInNewTab: function() { this.activateMode(true, false); }, + activateModeToOpenInNewTab: function() { this.activateMode(true, false, false); }, + + activateModeToCopyLinkUrl: function() { this.activateMode(false, false, true); }, - activateModeWithQueue: function() { this.activateMode(true, true); }, + activateModeWithQueue: function() { this.activateMode(true, true, false); }, - activateMode: function(openInNewTab, withQueue) { + activateMode: function(openInNewTab, withQueue, copyLinkUrl) { if (!this.cssAdded) addCssToPage(linkHintCss); // linkHintCss is declared by vimiumFrontend.js this.linkHintCssAdded = true; - this.setOpenLinkMode(openInNewTab, withQueue); + this.setOpenLinkMode(openInNewTab, withQueue, copyLinkUrl); this.buildLinkHints(); handlerStack.push({ // modeKeyHandler is declared by vimiumFrontend.js keydown: this.onKeyDownInMode, @@ -64,10 +67,13 @@ var linkHints = { }); }, - setOpenLinkMode: function(openInNewTab, withQueue) { + setOpenLinkMode: function(openInNewTab, withQueue, copyLinkUrl) { this.shouldOpenInNewTab = openInNewTab; this.shouldOpenWithQueue = withQueue; - if (this.shouldOpenWithQueue) { + this.shouldCopyLinkUrl = copyLinkUrl; + if (this.shouldCopyLinkUrl) { + HUD.show("Copy link URL to Clipboard"); + } else if (this.shouldOpenWithQueue) { HUD.show("Open multiple links in a new tab"); } else { if (this.shouldOpenInNewTab) @@ -174,7 +180,7 @@ var linkHints = { if (event.keyCode == keyCodes.shiftKey && !this.openLinkModeToggle) { // Toggle whether to open link in a new or current tab. - this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue); + this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue, false); this.openLinkModeToggle = true; } @@ -204,7 +210,7 @@ var linkHints = { onKeyUpInMode: function(event) { if (event.keyCode == keyCodes.shiftKey && this.openLinkModeToggle) { // Revert toggle on whether to open link in new or current tab. - this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue); + this.setOpenLinkMode(!this.shouldOpenInNewTab, this.shouldOpenWithQueue, false); this.openLinkModeToggle = false; } event.stopPropagation(); @@ -227,6 +233,10 @@ var linkHints = { that.delayMode = false; that.activateModeWithQueue(); }); + } else if (this.shouldCopyLinkUrl) { + console.log(matchedLink); + this.copyLinkUrl(matchedLink); + this.deactivateMode(delay, function() { that.delayMode = false; }); } else if (this.shouldOpenInNewTab) { this.simulateClick(matchedLink); matchedLink.focus(); @@ -250,6 +260,10 @@ var linkHints = { element.nodeName.toLowerCase() == "textarea"; }, + copyLinkUrl: function(link) { + chrome.extension.sendRequest({handler: 'copyLinkUrl', data: link.href}); + }, + simulateSelect: function(element) { element.focus(); // When focusing a textbox, put the selection caret at the end of the textbox's contents. |
