diff --git a/background_scripts/commands.js b/background_scripts/commands.js index 131c99cdd..3d1fe69d7 100644 --- a/background_scripts/commands.js +++ b/background_scripts/commands.js @@ -197,6 +197,7 @@ const Commands = { "scrollToRight", "reload", "copyCurrentUrl", + "copyCurrentMarkdown", "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", @@ -297,6 +298,7 @@ const defaultKeyMappings = { "u": "scrollPageUp", "r": "reload", "yy": "copyCurrentUrl", + "ym": "copyCurrentMarkdown", "p": "openCopiedUrlInCurrentTab", "P": "openCopiedUrlInNewTab", "gi": "focusInput", @@ -386,6 +388,7 @@ const commandDescriptions = { toggleViewSource: ["View page source", { noRepeat: true }], copyCurrentUrl: ["Copy the current URL to the clipboard", { noRepeat: true }], + copyCurrentMarkdown: ["Copy the current title and URL as markdown link to the clipboard", { noRepeat: true }], openCopiedUrlInCurrentTab: ["Open the clipboard's URL in the current tab", { noRepeat: true }], openCopiedUrlInNewTab: ["Open the clipboard's URL in a new tab", { repeatLimit: 20 }], diff --git a/background_scripts/main.js b/background_scripts/main.js index f7caf4b49..86a2733cf 100644 --- a/background_scripts/main.js +++ b/background_scripts/main.js @@ -633,6 +633,7 @@ var sendRequestHandlers = { // getCurrentTabUrl is used by the content scripts to get their full URL, because window.location cannot help // with Chrome-specific URLs like "view-source:http:..". getCurrentTabUrl({tab}) { return tab.url; }, + getCurrentTabMarkdown({tab}) { return `[${tab.title}](${tab.url})` }, openUrlInNewTab: mkRepeatCommand((request, callback) => TabOperations.openUrlInNewTab(request, callback)), openUrlInNewWindow(request) { return TabOperations.openUrlInNewWindow(request); }, openUrlInIncognito(request) { return chrome.windows.create({incognito: true, url: Utils.convertToUrl(request.url)}); }, diff --git a/content_scripts/mode_normal.js b/content_scripts/mode_normal.js index 75d331789..26ce1bf97 100644 --- a/content_scripts/mode_normal.js +++ b/content_scripts/mode_normal.js @@ -119,6 +119,15 @@ var NormalModeCommands = { }); }, + copyCurrentMarkdown() { + chrome.runtime.sendMessage({ handler: "getCurrentTabMarkdown" }, function(url) { + HUD.copyToClipboard(url); + if (28 < url.length) + url = url.slice(0, 26) + "...."; + HUD.showForDuration(`Yanked ${url}`, 2000); + }); + }, + openCopiedUrlInNewTab(count) { HUD.pasteFromClipboard(url => chrome.runtime.sendMessage({ handler: "openUrlInNewTab", url, count })); },