diff options
| author | ilya | 2010-01-03 23:27:08 -0800 |
|---|---|---|
| committer | ilya | 2010-01-03 23:27:08 -0800 |
| commit | 684715730414a26a8177d65730908acc0440158a (patch) | |
| tree | da3988bead413fe649f2ed97861f9dff60d6d731 | |
| parent | 48fadb34a0cb596d69655e6979f9292084d3a0b2 (diff) | |
| download | vimium-684715730414a26a8177d65730908acc0440158a.tar.bz2 | |
Implement 'y' -- yank (copy) the current tab's url to the clipboard.
| -rw-r--r-- | README.markdown | 1 | ||||
| -rw-r--r-- | background_page.html | 2 | ||||
| -rw-r--r-- | lib/clipboard.js | 14 | ||||
| -rw-r--r-- | manifest.json | 5 | ||||
| -rw-r--r-- | vimiumFrontend.js | 8 |
5 files changed, 29 insertions, 1 deletions
diff --git a/README.markdown b/README.markdown index 883383e4..30d4d0f4 100644 --- a/README.markdown +++ b/README.markdown @@ -36,6 +36,7 @@ Navigating the current page: n cycle forward to the next find match N cycle backward to the previous find match i enter insert mode -- all commands will be ignored until you hit esc to exit + y copy the current url to the clipboard Navigating your history: ba, H go back in history diff --git a/background_page.html b/background_page.html index 61c6cf91..1c514ed5 100644 --- a/background_page.html +++ b/background_page.html @@ -247,6 +247,8 @@ keyToCommandRegistry['n'] = 'performFind'; keyToCommandRegistry['N'] = 'performBackwardsFind'; + keyToCommandRegistry['y'] = 'copyCurrentUrl'; + keyToCommandRegistry['J'] = nextTab; keyToCommandRegistry['K'] = previousTab; keyToCommandRegistry['gt'] = nextTab; diff --git a/lib/clipboard.js b/lib/clipboard.js new file mode 100644 index 00000000..1d414892 --- /dev/null +++ b/lib/clipboard.js @@ -0,0 +1,14 @@ +var Clipboard = { + // 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; + + document.body.appendChild(textArea); + textArea.select(); + document.execCommand("Copy"); + document.body.removeChild(textArea); + } +}; diff --git a/manifest.json b/manifest.json index 17233eb8..e01bb324 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,10 @@ "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], - "js": ["vimiumFrontend.js", "linkHints.js"], + "js": ["vimiumFrontend.js", + "linkHints.js", + "lib/clipboard.js" + ], "run_at": "document_start" } ] diff --git a/vimiumFrontend.js b/vimiumFrontend.js index c055981d..ff6957bb 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -213,6 +213,14 @@ function toggleViewSource() { getCurrentUrlPort.postMessage({}); } +function copyCurrentUrl() { + getCurrentUrlHandlers.push(function (url) { Clipboard.copy(url); }); + + // TODO(ilya): Convert to sendRequest. + var getCurrentUrlPort = chrome.extension.connect({ name: "getCurrentTabUrl" }); + getCurrentUrlPort.postMessage({}); +} + function toggleViewSourceCallback(url) { if (url.substr(0, 12) == "view-source:") { |
