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 command to show link URL without opening it #3994

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
4 changes: 4 additions & 0 deletions background_scripts/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ const Commands = {
"LinkHints.activateModeToDownloadLink",
"LinkHints.activateModeToOpenIncognito",
"LinkHints.activateModeToCopyLinkUrl",
"LinkHints.activateModeToShowLinkUrl",
"goPrevious",
"goNext",
"nextFrame",
Expand Down Expand Up @@ -267,6 +268,7 @@ const Commands = {
"Vomnibar.activateEditUrlInNewTab",
"LinkHints.activateModeToOpenIncognito",
"LinkHints.activateModeToCopyLinkUrl",
"LinkHints.activateModeToShowLinkUrl",
"goNext",
"goPrevious",
"Marks.activateCreateMode",
Expand Down Expand Up @@ -315,6 +317,7 @@ const defaultKeyMappings = {
"F": "LinkHints.activateModeToOpenInNewTab",
"<a-f>": "LinkHints.activateModeWithQueue",
"yf": "LinkHints.activateModeToCopyLinkUrl",
"sf": "LinkHints.activateModeToShowLinkUrl",

// Using find
"/": "enterFindMode",
Expand Down Expand Up @@ -403,6 +406,7 @@ const commandDescriptions = {
"LinkHints.activateModeToOpenIncognito": ["Open a link in incognito window"],
"LinkHints.activateModeToDownloadLink": ["Download link url"],
"LinkHints.activateModeToCopyLinkUrl": ["Copy a link URL to the clipboard"],
"LinkHints.activateModeToShowLinkUrl": ["Show the URL of a link, without opening it"],

enterFindMode: ["Enter find mode", { noRepeat: true }],
performFind: ["Cycle forward to the next find match"],
Expand Down
19 changes: 17 additions & 2 deletions content_scripts/link_hints.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ const COPY_LINK_URL = {
}
}
};
const SHOW_LINK_URL = {
name: "link",
indicator: "Show link URL",
linkActivator(link) {
if (link.href != null) {
let url = link.href;
if (url.slice(0, 7) === "mailto:") { url = url.slice(7); }
if (28 < url.length) { url = url.slice(0, 23) + "...."; }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that it seems the HUD can't display long messages (see screenshot), and thus must truncate long URLs, which partly defeats the purpose of this feature (which is to review the link URL before you follow it). Is there a way around this?

image

HUD.showForDuration(`Link URL: ${url}`, 5000);
} else {
HUD.showForDuration("No link to show.", 2000);
}
}
};
const OPEN_INCOGNITO = {
name: "incognito",
indicator: "Open link in incognito window",
Expand Down Expand Up @@ -91,7 +105,7 @@ const FOCUS_LINK = {
};

const availableModes = [OPEN_IN_CURRENT_TAB, OPEN_IN_NEW_BG_TAB, OPEN_IN_NEW_FG_TAB, OPEN_WITH_QUEUE, COPY_LINK_URL,
OPEN_INCOGNITO, DOWNLOAD_LINK_URL, COPY_LINK_TEXT, HOVER_LINK, FOCUS_LINK];
SHOW_LINK_URL, OPEN_INCOGNITO, DOWNLOAD_LINK_URL, COPY_LINK_TEXT, HOVER_LINK, FOCUS_LINK];

const HintCoordinator = {
onExit: [],
Expand Down Expand Up @@ -134,7 +148,7 @@ const HintCoordinator = {
getHintDescriptors({modeIndex, isVimiumHelpDialog}) {
// Ensure that the document is ready and that the settings are loaded.
DomUtils.documentReady(() => { return Settings.onLoaded(() => {
const requireHref = [COPY_LINK_URL, OPEN_INCOGNITO].includes(availableModes[modeIndex]);
const requireHref = [COPY_LINK_URL, SHOW_LINK_URL, OPEN_INCOGNITO].includes(availableModes[modeIndex]);
// If link hints is launched within the help dialog, then we only offer hints from that frame. This
// improves the usability of the help dialog on the options page (particularly for selecting command
// names).
Expand Down Expand Up @@ -241,6 +255,7 @@ var LinkHints = {
activateModeToOpenInNewTab(count) { this.activateMode(count, {mode: OPEN_IN_NEW_BG_TAB}); },
activateModeToOpenInNewForegroundTab(count) { this.activateMode(count, {mode: OPEN_IN_NEW_FG_TAB}); },
activateModeToCopyLinkUrl(count) { this.activateMode(count, {mode: COPY_LINK_URL}); },
activateModeToShowLinkUrl(count) { this.activateMode(count, {mode: SHOW_LINK_URL}); },
activateModeWithQueue() { this.activateMode(1, {mode: OPEN_WITH_QUEUE}); },
activateModeToOpenIncognito(count) { this.activateMode(count, {mode: OPEN_INCOGNITO}); },
activateModeToDownloadLink(count) { this.activateMode(count, {mode: DOWNLOAD_LINK_URL}); }
Expand Down
3 changes: 2 additions & 1 deletion content_scripts/mode_normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ if (typeof LinkHints !== 'undefined') {
"LinkHints.activateModeWithQueue": LinkHints.activateModeWithQueue.bind(LinkHints),
"LinkHints.activateModeToOpenIncognito": LinkHints.activateModeToOpenIncognito.bind(LinkHints),
"LinkHints.activateModeToDownloadLink": LinkHints.activateModeToDownloadLink.bind(LinkHints),
"LinkHints.activateModeToCopyLinkUrl": LinkHints.activateModeToCopyLinkUrl.bind(LinkHints)
"LinkHints.activateModeToCopyLinkUrl": LinkHints.activateModeToCopyLinkUrl.bind(LinkHints),
"LinkHints.activateModeToShowLinkUrl": LinkHints.activateModeToShowLinkUrl.bind(LinkHints)
});
}

Expand Down