diff options
| -rw-r--r-- | CREDITS | 1 | ||||
| -rw-r--r-- | README.markdown | 1 | ||||
| -rw-r--r-- | commands.js | 4 | ||||
| -rw-r--r-- | linkHints.js | 50 |
4 files changed, 40 insertions, 16 deletions
@@ -16,5 +16,6 @@ Contributors: rodimius Tim Morgan <tim@timmorgan.org> (github: seven1m) tsigo + Werner Laurensse (github: ab3) Feel free to add real names in addition to GitHub usernames. diff --git a/README.markdown b/README.markdown index b470da2a..668f0c2b 100644 --- a/README.markdown +++ b/README.markdown @@ -36,6 +36,7 @@ Navigating the current page: <c-b> scroll up a full page f activate link hints mode to open in current tab F activate link hints mode to open in new tab + q activate link hints mode to open multiple links in a new tab r reload gs view source zi zoom in diff --git a/commands.js b/commands.js index 635c5350..a952ae91 100644 --- a/commands.js +++ b/commands.js @@ -112,6 +112,7 @@ function clearKeyMappingsAndSetDefaults() { mapKeyToCommand('f', 'activateLinkHintsMode'); mapKeyToCommand('F', 'activateLinkHintsModeToOpenInNewTab'); + mapKeyToCommand('q', 'activeteLinkHintsModeWithQueue'); mapKeyToCommand('/', 'enterFindMode'); mapKeyToCommand('n', 'performFind'); @@ -158,6 +159,7 @@ addCommand('focusInput', 'Focus the first (or n-th) text box on the pag addCommand('activateLinkHintsMode', 'Enter link hints mode to open links in current tab'); addCommand('activateLinkHintsModeToOpenInNewTab', 'Enter link hints mode to open links in new tab'); +addCommand('activeteLinkHintsModeWithQueue', 'Enter link hints mode to open multiple links in a new tab'); addCommand('enterFindMode', 'Enter find mode'); addCommand('performFind', 'Cycle forward to the next find match'); @@ -189,7 +191,7 @@ var commandGroups = { "scrollPageUp", "scrollFullPageDown", "reload", "toggleViewSource", "zoomIn", "zoomOut", "copyCurrentUrl", "goUp", "enterInsertMode", "focusInput", - "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab", + "activateLinkHintsMode", "activateLinkHintsModeToOpenInNewTab", "activeteLinkHintsModeWithQueue", "enterFindMode", "performFind", "performBackwardsFind", "nextFrame"], historyNavigation: ["goBack", "goForward"], diff --git a/linkHints.js b/linkHints.js index fcaa832b..c470dfe0 100644 --- a/linkHints.js +++ b/linkHints.js @@ -13,6 +13,7 @@ var hintMarkerContainingDiv = null; var hintKeystrokeQueue = []; var linkHintsModeActivated = false; var shouldOpenLinkHintInNewTab = false; +var shouldOpenLinkHintWithQueue = false; // Whether link hint's "open in current/new tab" setting is currently toggled var openLinkModeToggle = false; // Whether we have added to the page the CSS needed to display link hints. @@ -32,25 +33,32 @@ var clickableElementsXPath = (function() { })(); // We need this as a top-level function because our command system doesn't yet support arguments. -function activateLinkHintsModeToOpenInNewTab() { activateLinkHintsMode(true); } +function activateLinkHintsModeToOpenInNewTab() { activateLinkHintsMode(true, false); } -function activateLinkHintsMode(openInNewTab) { +function activeteLinkHintsModeWithQueue() { activateLinkHintsMode(true, true); } + +function activateLinkHintsMode(openInNewTab, withQueue) { if (!linkHintsCssAdded) addCssToPage(linkHintCss); // linkHintCss is declared by vimiumFrontend.js linkHintCssAdded = true; linkHintsModeActivated = true; - setOpenLinkMode(openInNewTab); + setOpenLinkMode(openInNewTab, withQueue); buildLinkHints(); document.addEventListener("keydown", onKeyDownInLinkHintsMode, true); document.addEventListener("keyup", onKeyUpInLinkHintsMode, true); } -function setOpenLinkMode(openInNewTab) { +function setOpenLinkMode(openInNewTab, withQueue) { shouldOpenLinkHintInNewTab = openInNewTab; - if (shouldOpenLinkHintInNewTab) - HUD.show("Open link in new tab"); - else - HUD.show("Open link in current tab"); + shouldOpenLinkHintWithQueue = withQueue + if (shouldOpenLinkHintWithQueue) { + HUD.show("Open multiple links in a new tab"); + } else { + if (shouldOpenLinkHintInNewTab) + HUD.show("Open link in new tab"); + else + HUD.show("Open link in current tab"); + } } /* @@ -143,9 +151,10 @@ function isVisible(element, clientRect) { } function onKeyDownInLinkHintsMode(event) { + console.log("Key Down"); if (event.keyCode == keyCodes.shiftKey && !openLinkModeToggle) { // Toggle whether to open link in a new or current tab. - setOpenLinkMode(!shouldOpenLinkHintInNewTab); + setOpenLinkMode(!shouldOpenLinkHintInNewTab, shouldOpenLinkHintWithQueue); openLinkModeToggle = true; } @@ -177,7 +186,7 @@ function onKeyDownInLinkHintsMode(event) { function onKeyUpInLinkHintsMode(event) { if (event.keyCode == keyCodes.shiftKey && openLinkModeToggle) { // Revert toggle on whether to open link in new or current tab. - setOpenLinkMode(!shouldOpenLinkHintInNewTab); + setOpenLinkMode(!shouldOpenLinkHintInNewTab, shouldOpenLinkHintWithQueue); openLinkModeToggle = false; } event.stopPropagation(); @@ -202,13 +211,19 @@ function updateLinkHints() { } else { // When we're opening the link in the current tab, don't navigate to the selected link immediately; // we want to give the user some feedback depicting which link they've selected by focusing it. - if (!shouldOpenLinkHintInNewTab) - setTimeout(function() { simulateClick(matchedLink); }, 400); - else + if (shouldOpenLinkHintWithQueue) { simulateClick(matchedLink); - matchedLink.focus(); + resetLinkHintsMode(); + } else if (shouldOpenLinkHintInNewTab) { + simulateClick(matchedLink); + matchedLink.focus(); + deactivateLinkHintsMode(); + } else { + setTimeout(function() { simulateClick(matchedLink); }, 400); + matchedLink.focus(); + deactivateLinkHintsMode(); + } } - deactivateLinkHintsMode(); } } @@ -289,6 +304,11 @@ function deactivateLinkHintsMode() { HUD.hide(); } +function resetLinkHintsMode() { + deactivateLinkHintsMode(); + activeteLinkHintsModeWithQueue(); +} + /* * Creates a link marker for the given link. */ |
