From 6ccdb189c575e5f1c539e7fed9f39d2f683b16d4 Mon Sep 17 00:00:00 2001 From: Murphy McMahon Date: Thu, 14 Jul 2011 09:35:14 -0300 Subject: Added clipboard copying to linkHints mode (default binding: 'Y') --- linkHints.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'linkHints.js') 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. -- cgit v1.2.3 From cc88295c45774bb765e3bcf5a644763c39e2a726 Mon Sep 17 00:00:00 2001 From: Murphy McMahon Date: Thu, 14 Jul 2011 09:53:35 -0300 Subject: Cleaning up comments and console output --- linkHints.js | 1 - 1 file changed, 1 deletion(-) (limited to 'linkHints.js') diff --git a/linkHints.js b/linkHints.js index 75b0fe53..e3ecacfb 100644 --- a/linkHints.js +++ b/linkHints.js @@ -234,7 +234,6 @@ var linkHints = { that.activateModeWithQueue(); }); } else if (this.shouldCopyLinkUrl) { - console.log(matchedLink); this.copyLinkUrl(matchedLink); this.deactivateMode(delay, function() { that.delayMode = false; }); } else if (this.shouldOpenInNewTab) { -- cgit v1.2.3