From 3d273b68c34e5aeb9fd76d1979ee4606357a8631 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 22 Apr 2015 11:45:42 +0100 Subject: Show yanked text in HUD for "yf". --- content_scripts/link_hints.coffee | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 73af6a06..6bbe1f07 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -32,6 +32,8 @@ LinkHints = if settings.get("filterLinkHints") then filterHints else alphabetHints # lock to ensure only one instance runs at a time isActive: false + # Call this function on exit (if defined). + onExit: null # # To be called after linkHints has been generated from linkHintsBase. @@ -92,8 +94,11 @@ LinkHints = altKey: false else if @mode is COPY_LINK_URL @hintMode.setIndicator "Copy link URL to Clipboard" - @linkActivator = (link) -> + @linkActivator = (link) => chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href + url = link.href + url = url[0..25] + "...." if 28 < url.length + @onExit = -> HUD.showForDuration "Yanked #{url}", 2000 else if @mode is OPEN_INCOGNITO @hintMode.setIndicator "Open link in incognito window" @linkActivator = (link) -> @@ -341,6 +346,8 @@ LinkHints = DomUtils.removeElement LinkHints.hintMarkerContainingDiv LinkHints.hintMarkerContainingDiv = null @hintMode.exit() + @onExit?() + @onExit = null @isActive = false # we invoke the deactivate() function directly instead of using setTimeout(callback, 0) so that -- cgit v1.2.3 From 93e6a4dbac4512a7f1172c3b0c0284557ec80082 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 22 Apr 2015 11:59:01 +0100 Subject: For "yf", handle case where link.href isn't defined. Note: We probably shouldn't be offering these links at all. --- content_scripts/link_hints.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 6bbe1f07..5404d177 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -95,10 +95,13 @@ LinkHints = else if @mode is COPY_LINK_URL @hintMode.setIndicator "Copy link URL to Clipboard" @linkActivator = (link) => - chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href - url = link.href - url = url[0..25] + "...." if 28 < url.length - @onExit = -> HUD.showForDuration "Yanked #{url}", 2000 + if link.href? + chrome.runtime.sendMessage handler: "copyToClipboard", data: link.href + url = link.href + url = url[0..25] + "...." if 28 < url.length + @onExit = -> HUD.showForDuration "Yanked #{url}", 2000 + else + @onExit = -> HUD.showForDuration "No link to yank.", 2000 else if @mode is OPEN_INCOGNITO @hintMode.setIndicator "Open link in incognito window" @linkActivator = (link) -> -- cgit v1.2.3 From caca2b6e81ba6fcad9cdc406c8cde15084db7539 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 22 Apr 2015 12:24:54 +0100 Subject: Filter out non-HREF elements for "yf". If the element does not have an HREF, then we shouldn't be offering to copy it's link. --- content_scripts/link_hints.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 5404d177..650080d4 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -56,7 +56,10 @@ LinkHints = return @isActive = true - hintMarkers = (@createMarkerFor(el) for el in @getVisibleClickableElements()) + elements = @getVisibleClickableElements() + # For COPY_LINK_URL mode, we filter out those elements which don't have an HREF to copy. + elements = (el for el in elements when el.element.href?) if mode == COPY_LINK_URL + hintMarkers = (@createMarkerFor(el) for el in elements) @getMarkerMatcher().fillInMarkers(hintMarkers) @hintMode = new Mode -- cgit v1.2.3 From e7fa65430188a0b9e0b1d7f1050f452932190b6a Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 22 Apr 2015 13:18:23 +0100 Subject: Also filter for HREF in incognito mode. --- content_scripts/link_hints.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 650080d4..6bc37aaf 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -57,8 +57,9 @@ LinkHints = @isActive = true elements = @getVisibleClickableElements() - # For COPY_LINK_URL mode, we filter out those elements which don't have an HREF to copy. - elements = (el for el in elements when el.element.href?) if mode == COPY_LINK_URL + # For these modes, we filter out those elements which don't have an HREF (since there's nothing we can do + # with them). + elements = (el for el in elements when el.element.href?) if mode in [ COPY_LINK_URL, OPEN_INCOGNITO ] hintMarkers = (@createMarkerFor(el) for el in elements) @getMarkerMatcher().fillInMarkers(hintMarkers) -- cgit v1.2.3