Skip to content
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

Add yank (copy) markdown link of current tab #4240

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
3 changes: 3 additions & 0 deletions background_scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const Commands = {
"scrollToRight",
"reload",
"copyCurrentUrl",
"copyCurrentMarkdown",
"openCopiedUrlInCurrentTab",
"openCopiedUrlInNewTab",
"goUp",
Expand Down Expand Up @@ -297,6 +298,7 @@ const defaultKeyMappings = {
"u": "scrollPageUp",
"r": "reload",
"yy": "copyCurrentUrl",
"ym": "copyCurrentMarkdown",
"p": "openCopiedUrlInCurrentTab",
"P": "openCopiedUrlInNewTab",
"gi": "focusInput",
Expand Down Expand Up @@ -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 }],

Expand Down
1 change: 1 addition & 0 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}); },
Expand Down
9 changes: 9 additions & 0 deletions content_scripts/mode_normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
},
Expand Down