diff options
| author | Jez Ng | 2012-01-15 15:40:49 +0800 |
|---|---|---|
| committer | Jez Ng | 2012-01-15 17:39:29 +0800 |
| commit | 3ff0518014a51f237d1d98ebc15c0ce4be24c2b5 (patch) | |
| tree | a97defdd480879cf297d22d8a23435172ca16596 | |
| parent | 4ca60a80f0e3d5c4818d05417c869bde6340d792 (diff) | |
| download | vimium-3ff0518014a51f237d1d98ebc15c0ce4be24c2b5.tar.bz2 | |
Add URL pasting functions. Closes #353.
| -rw-r--r-- | background_page.html | 8 | ||||
| -rw-r--r-- | commands.js | 10 | ||||
| -rw-r--r-- | lib/clipboard.js | 33 | ||||
| -rw-r--r-- | manifest.json | 1 |
4 files changed, 41 insertions, 11 deletions
diff --git a/background_page.html b/background_page.html index 06c48359..c62697b0 100644 --- a/background_page.html +++ b/background_page.html @@ -267,6 +267,14 @@ Clipboard.copy(request.data); } + function openCopiedUrlInCurrentTab(request) { + openUrlInCurrentTab({ url: Clipboard.paste() }); + } + + function openCopiedUrlInNewTab(request) { + openUrlInNewTab({ url: Clipboard.paste() }); + } + /* * Returns the core CSS used for link hints, along with any user-provided overrides. */ diff --git a/commands.js b/commands.js index d214d2bf..c961a901 100644 --- a/commands.js +++ b/commands.js @@ -127,6 +127,9 @@ function clearKeyMappingsAndSetDefaults() { "yy": "copyCurrentUrl", "yf": "linkHints.activateModeToCopyLinkUrl", + "p": "openCopiedUrlInCurrentTab", + "P": "openCopiedUrlInNewTab", + "K": "nextTab", "J": "previousTab", "gt": "nextTab", @@ -168,9 +171,11 @@ var commandDescriptions = { reload: ["Reload the page"], toggleViewSource: ["View page source"], - copyCurrentUrl: ["Copy the current URL to the clipboard"], + copyCurrentUrl: ["Copy the current URL to the clipboard"], 'linkHints.activateModeToCopyLinkUrl': ["Copy a link URL to the clipboard"], + openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { background: true }], + openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true }], enterInsertMode: ["Enter insert mode"], @@ -220,7 +225,8 @@ var commandGroups = { ["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom", "scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown", - "reload", "toggleViewSource", "copyCurrentUrl", "linkHints.activateModeToCopyLinkUrl", "goUp", + "reload", "toggleViewSource", "copyCurrentUrl", "linkHints.activateModeToCopyLinkUrl", + "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "enterInsertMode", "focusInput", "linkHints.activateMode", "linkHints.activateModeToOpenInNewTab", "linkHints.activateModeWithQueue", "activateBookmarkFindMode", "activateBookmarkFindModeToOpenInNewTab", diff --git a/lib/clipboard.js b/lib/clipboard.js index 1d414892..b6d3940e 100644 --- a/lib/clipboard.js +++ b/lib/clipboard.js @@ -1,14 +1,29 @@ var Clipboard = { + _createTextArea: function() { + var textArea = document.createElement("textarea"); + textArea.style.position = "absolute"; + textArea.style.left = "-100%"; + return textArea; + }, + // http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55 copy: function(data) { - var textArea = document.createElement("textarea"); - textArea.style.position = "absolute"; - textArea.style.left = "-100%"; - textArea.value = data; + var textArea = this._createTextArea(); + textArea.value = data; + + document.body.appendChild(textArea); + textArea.select(); + document.execCommand("Copy"); + document.body.removeChild(textArea); + }, - document.body.appendChild(textArea); - textArea.select(); - document.execCommand("Copy"); - document.body.removeChild(textArea); - } + paste: function() { + var textArea = this._createTextArea(); + document.body.appendChild(textArea); + textArea.focus(); + document.execCommand("Paste"); + var rv = textArea.value; + document.body.removeChild(textArea); + return rv; + } }; diff --git a/manifest.json b/manifest.json index a79fd90c..5207e1c5 100644 --- a/manifest.json +++ b/manifest.json @@ -10,6 +10,7 @@ "permissions": [ "tabs", "bookmarks", + "clipboardRead", "http://*/*", "https://*/*" ], |
