diff options
| author | ilya | 2009-11-09 01:48:39 -0800 |
|---|---|---|
| committer | ilya | 2009-11-09 01:49:57 -0800 |
| commit | be17ec68f6038e176b8a72e674697861228dfb56 (patch) | |
| tree | 97ba92a1fc2a0a6ad71ece4b34b6abe5ea2b2b2f /vimiumFrontend.js | |
| parent | 961354e28460ccff349c314f689330442f217605 (diff) | |
| download | vimium-be17ec68f6038e176b8a72e674697861228dfb56.tar.bz2 | |
Implement 'gf' -- toggle view source for the current page.
Diffstat (limited to 'vimiumFrontend.js')
| -rw-r--r-- | vimiumFrontend.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index f9a42d75..11a4d701 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -1,4 +1,5 @@ var SCROLL_STEP_SIZE = 60; // Pixels +var getCurrentUrlHandlers = []; // function (url) document.addEventListener("keydown", onKeydown); document.addEventListener("focus", onFocusCapturePhase, true); @@ -22,6 +23,21 @@ function reload() { window.location.reload(); } function goBack() { history.back(); } function goForward() { history.forward(); } +function toggleViewSource() { + getCurrentUrlHandlers.push(toggleViewSourceCallback); + + var getCurrentUrlPort = chrome.extension.connect({ name: "getCurrentTabUrl" }); + getCurrentUrlPort.postMessage({}); +} + +function toggleViewSourceCallback(url) { + if (url.substr(0, 12) == "view-source:") + { + window.location.href = url.substr(12, url.length - 12); + } + else { window.location.href = "view-source:" + url; } +} + chrome.extension.onConnect.addListener(function (port, name) { if (port.name == "executePageCommand") { port.onMessage.addListener(function (args) { @@ -44,6 +60,10 @@ chrome.extension.onConnect.addListener(function (port, name) { port.onMessage.addListener(function (args) { if (args.scrollX > 0 || args.scrollY > 0) { window.scrollBy(args.scrollX, args.scrollY); } }); + } else if (port.name == "returnCurrentTabUrl") { + port.onMessage.addListener(function (args) { + if (getCurrentUrlHandlers.length > 0) { getCurrentUrlHandlers.pop()(args.url); } + }); } }); |
