Skip to content

[Needs rebase] Add command for downloading links #5

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
17 changes: 10 additions & 7 deletions background_scripts/commands.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ Commands =
# be shown in the help page.
commandGroups:
pageNavigation:
["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom", "scrollToLeft",
"scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown", "reload",
"toggleViewSource", "copyCurrentUrl", "LinkHints.activateModeToCopyLinkUrl",
"openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "goToRoot", "enterInsertMode",
"focusInput", "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab",
"LinkHints.activateModeToOpenInNewForegroundTab", "LinkHints.activateModeWithQueue", "Vomnibar.activate",
["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom",
"scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp",
"scrollFullPageDown", "reload", "toggleViewSource", "copyCurrentUrl",
"LinkHints.activateModeToCopyLinkUrl", "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp",
"goToRoot", "enterInsertMode", "focusInput", "LinkHints.activateMode",
"LinkHints.activateModeToOpenInNewTab", "LinkHints.activateModeToOpenInNewForegroundTab",
"LinkHints.activateModeWithQueue", "LinkHints.activateModeToSaveLinkAs", "Vomnibar.activate",
"Vomnibar.activateInNewTab", "Vomnibar.activateTabSelection", "Vomnibar.activateBookmarks",
"Vomnibar.activateBookmarksInNewTab", "goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode",
"Vomnibar.activateEditUrl", "Vomnibar.activateEditUrlInNewTab",
Expand Down Expand Up @@ -219,7 +220,7 @@ commandDescriptions =
toggleViewSource: ["View page source"]

copyCurrentUrl: ["Copy the current URL to the clipboard"]
'LinkHints.activateModeToCopyLinkUrl': ["Copy a link URL to the clipboard"]
'LinkHints.activateModeToCopyLinkUrl': ["Copy a link's URL to the clipboard"]
openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { background: true }]
openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { background: true }]

Expand All @@ -236,6 +237,8 @@ commandDescriptions =
"LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window"]

"LinkHints.activateModeToDownloadLink": ["Download link url"]
"LinkHints.activateModeToSaveLinkAs": ["Download a link's URL using save as"]

enterFindMode: ["Enter find mode"]
performFind: ["Cycle forward to the next find match"]
performBackwardsFind: ["Cycle backward to the previous find match"]
Expand Down
11 changes: 11 additions & 0 deletions background_scripts/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ upgradeNotificationClosed = (request) ->
Settings.set("previousVersion", currentVersion)
sendRequestToAllTabs({ name: "hideUpgradeNotification" })

#
# Downloads the provided URL (request.data)
#
downloadUrl = (request) ->
urlParts = request.data.split("/")
chrome.downloads.download
url: request.data
filename: urlParts[urlParts.length - 1]
saveAs: true

#
# Copies some data (request.data) to the clipboard.
#
Expand Down Expand Up @@ -620,6 +630,7 @@ sendRequestHandlers =
upgradeNotificationClosed: upgradeNotificationClosed,
updateScrollPosition: handleUpdateScrollPosition,
copyToClipboard: copyToClipboard,
downloadUrl: downloadUrl,
isEnabledForUrl: isEnabledForUrl,
saveHelpDialogSettings: saveHelpDialogSettings,
selectSpecificTab: selectSpecificTab,
Expand Down
5 changes: 5 additions & 0 deletions content_scripts/link_hints.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ LinkHints =
activateModeWithQueue: -> @activateMode(OPEN_WITH_QUEUE)
activateModeToOpenIncognito: -> @activateMode(OPEN_INCOGNITO)
activateModeToDownloadLink: -> @activateMode(DOWNLOAD_LINK_URL)
activateModeToSaveLinkAs: -> @activateMode(DOWNLOAD_LINK_URL)

activateMode: (mode = OPEN_IN_CURRENT_TAB) ->
# we need documentElement to be ready in order to append links
Expand Down Expand Up @@ -101,6 +102,10 @@ LinkHints =
HUD.show("Copy link URL to Clipboard")
@linkActivator = (link) ->
chrome.runtime.sendMessage({handler: "copyToClipboard", data: link.href})
else if @mode is DOWNLOAD_LINK_URL
HUD.show("Download link URL")
@linkActivator = (link) ->
chrome.runtime.sendMessage {handler: "downloadUrl", data: link.href}
else if @mode is OPEN_INCOGNITO
HUD.show("Open link in incognito window")

Expand Down
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"history",
"clipboardRead",
"storage",
"<all_urls>"
"<all_urls>",
"downloads"
],
"content_scripts": [
{
Expand Down