Skip to content

[Needs rebase] Add mouseover and mouseout commands #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions background_scripts/commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Commands =
"LinkHints.activateModeWithQueue",
"LinkHints.activateModeToDownloadLink",
"LinkHints.activateModeToOpenIncognito",
"LinkHints.activateModeToHover",
"LinkHints.unhoverLast",
"goPrevious",
"goNext",
"nextFrame",
Expand Down Expand Up @@ -180,6 +182,8 @@ Commands =
"Vomnibar.activateEditUrl",
"Vomnibar.activateEditUrlInNewTab",
"LinkHints.activateModeToOpenIncognito",
"LinkHints.activateModeToHover",
"LinkHints.unhoverLast",
"goNext",
"goPrevious",
"Marks.activateCreateMode",
Expand Down Expand Up @@ -315,6 +319,8 @@ commandDescriptions =
"LinkHints.activateModeWithQueue": ["Open multiple links in a new tab", { noRepeat: true }]
"LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window", { passCountToFunction: true }]
"LinkHints.activateModeToDownloadLink": ["Download link url", { passCountToFunction: true }]
"LinkHints.activateModeToHover": ["Hover over a link", { passCountToFunction: true }]
"LinkHints.unhoverLast": ["Stop hovering at last location", { noRepeat: true }]

enterFindMode: ["Enter find mode", { noRepeat: true }]
performFind: ["Cycle forward to the next find match"]
Expand Down
7 changes: 7 additions & 0 deletions content_scripts/link_hints.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ OPEN_WITH_QUEUE = name: "queue"
COPY_LINK_URL = name: "link"
OPEN_INCOGNITO = name: "incognito"
DOWNLOAD_LINK_URL = name: "download"
HOVER = name: "hover"

LinkHints =
activateMode: (count = 1, mode = OPEN_IN_CURRENT_TAB) ->
Expand All @@ -34,6 +35,8 @@ LinkHints =
activateModeWithQueue: -> @activateMode 1, OPEN_WITH_QUEUE
activateModeToOpenIncognito: (count) -> @activateMode count, OPEN_INCOGNITO
activateModeToDownloadLink: (count) -> @activateMode count, DOWNLOAD_LINK_URL
activateModeToHover: (count) -> @activateMode count, HOVER
unhoverLast: -> DomUtils.simulateUnhover()

class LinkHintsMode
hintMarkerContainingDiv: null
Expand Down Expand Up @@ -130,6 +133,10 @@ class LinkHintsMode
@hintMode.setIndicator "Download link URL."
@linkActivator = (link) ->
DomUtils.simulateClick link, altKey: true, ctrlKey: false, metaKey: false
else if @mode is HOVER
@hintMode.setIndicator "Hover over a link."
@linkActivator = (link) ->
DomUtils.simulateHover link
else # OPEN_IN_CURRENT_TAB
@hintMode.setIndicator "Open link in current tab."
@linkActivator = DomUtils.simulateClick.bind DomUtils
Expand Down
2 changes: 2 additions & 0 deletions lib/dom_utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ DomUtils =
if element.selectionStart == 0 and element.selectionEnd == 0
element.setSelectionRange element.value.length, element.value.length

simulateHover: (element, modifiers) -> @simulateMouseEvent "mouseover", element, modifiers

simulateUnhover: (element, modifiers) -> @simulateMouseEvent "mouseout", element, modifiers

simulateClick: (element, modifiers) ->
Expand Down