如何通过一次按键将Experts ID的短链接复制到剪贴板

Each comment in Question threads here at Experts Exchange has a unique Identifier (ID). The full path of the link for an ID looks like this:

Experts Exchange此处“问题”线程中的每个注释都有一个唯一的标识符( ID )。 ID链接的完整路径如下所示:

https://www.experts-exchange.com/questions/12345678/Title-of-this-question.html#a87654321

https://www.experts-exchange.com/questions/12345678/Title-of-this-question.html#a87654321

It is easy to copy that full path to the clipboard by right-clicking on it and then selecting the appropriate context menu item in your browser. For example, in Chrome, Opera, and Vivaldi, the menu item is Copy link address; in Firefox, it is Copy Link Location; in IE11, Copy shortcut. However, we often want to post a short link within a thread, rather than the full link. The short link is everything after and including the number symbol (aka hash, octothorpe, pound sign), such as:

右键单击剪贴板,然后在浏览器中选择适当的上下文菜单项,即可将完整路径复制到剪贴板。 例如,在Chrome,Opera和Vivaldi中,菜单项为复制链接地址 ; 在Firefox中,它是“ 复制链接位置” ; 在IE11中, 复制快捷方式 。 但是,我们通常希望在线程内发布短链接,而不是完整链接。 短链接是数字符号之后的所有内容,包括数字符号(又名哈希,八字形,井号),例如:

#a87654321

#a87654321

An EE member recently posted a bug report pointing out that it is difficult to get the short link. He noted that a cumbersome, manual technique is to copy non-clickable text surrounding and including it, cleaning it up, and adding the pound sign, thereby creating the short link. Another technique, also manual and cumbersome, is to copy the full path, then delete everything before the short link. This article shows an easy, automated method for obtaining the short link with a single keystroke.

一位EE成员最近发布了一个错误报告,指出很难获得短链接。 他指出,繁琐的手动技术是复制周围无处不在的文本(包括文本),将其清除并添加井号,从而创建短链接。 另一种技术(也是手动且繁琐的)是复制完整路径,然后删除短链接之前的所有内容。 本文介绍了一种简单的自动化方法,只需单击一次即可获得短链接。

The primary component that we'll need for the solution is a scripting language that supports the Windows clipboard, and sending mouse clicks and keystrokes. In this article, I'll explain how to do it with AutoHotkey, my favorite programming/scripting language these days — but pick whatever language with which you're comfortable. If you'd like to learn about AutoHotkey, this EE article will get you going:

解决方案所需的主要组件是支持Windows剪贴板并发送鼠标点击和击键的脚本语言。 在本文中,我将说明如何使用AutoHotkey (这是我近来最喜欢的编程/脚本语言)进行的操作-但请选择适合您的任何语言。 如果您想了解AutoHotkey,这篇EE文章将带您开始:

AutoHotkey - Getting Started

AutoHotkey-入门

The method offered here is to position the mouse on the ID of interest and then tap a hotkey, which can be any key or key combination that you want, such as F5, NumPad+, Alt-Ctrl-I, whatever. Here's the AutoHotkey script for use with Firefox, containing ample comments so that it's easy to understand its operation:

此处提供的方法是将鼠标放在感兴趣的ID上,然后点击一个热键,该热键可以是您想要的任何键或组合键,例如F5,NumPad +,Alt-Ctrl-I等。 这是与Firefox一起使用的AutoHotkey脚本,其中包含大量注释,因此易于理解其操作:

F5::                               ; use F5 as hotkey

Clipboard:=""                      ; empty the clipboard

MouseClick,Right                   ; right-click at current mouse location

Sleep,60                           ; wait for 60 milliseconds to make sure context menu is there

SendInput a                        ; send letter "a", the Firefox shortcut for Copy Link Location

ClipWait,2                         ; wait at most two seconds for short link to appear in clipboard

If (ErrorLevel=1)                  ; ErrorLevel set to 1 when wait period expires

{

  MsgBox,4112,Error,Attempt to copy the short link onto the clipboard failed.

  Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon

}

StringSplit,ShortLink,Clipboard,#  ; split long link into two strings, separated at pound sign

ShortLink:="#" . ShortLink2        ; add pound sign to second string, creating the short link

Clipboard:=ShortLink               ; put short link on clipboard

Return                             ; success

As you can see in the code above, if the short link does not appear on the clipboard within two seconds, the script displays this error dialog:

如您在上面的代码中看到的,如果短链接在两秒钟内没有出现在剪贴板上,则脚本将显示以下错误对话框:

The "SendInput a" in the script works because the Firefox keyboard shortcut for Copy Link Location is "a". However, in Chrome, the keyboard shortcut for Copy Link Address is "e", so that line in the script should be changed to this:

该脚本中的“ SendInput a”有效,因为“ 复制链接位置 ”的Firefox键盘快捷键为“ a”。 但是,在Chrome中,“ 复制链接地址 ”的键盘快捷键为“ e”,因此脚本中的该行应更改为此:

SendInput e                        ; send letter "e", the Chrome shortcut for Copy Link Address 

If the browser that you are using doesn't have a keyboard shortcut for the menu pick that copies the link to the clipboard (such as "a" and "e" in the examples above), then you can navigate through the context menu with the down arrow as many times as needed to get to that item, and then send the Enter key. For example, in Chrome, it takes five down-arrows to get to the Copy Link Address menu pick. So you would replace "SendInput e" in the script with this:

如果您使用的浏览器没有用于将链接复制到剪贴板的菜单选择的键盘快捷键(例如上述示例中的“ a”和“ e”),则可以使用向下箭头,直到到达该项目所需的次数,然后发送Enter键。 例如,在Chrome中,需要五个向下箭头才能到达“ 复制链接地址”菜单选项。 因此,您可以使用以下命令替换脚本中的“ SendInput e”:

SendInput {Down 5}{Enter}          ; send five down arrows then the Enter key 

Many users stick to a single browser, but if you use multiple browsers, an enhanced version of the script will support them. For example, here's a script that detects whether Chrome, Firefox, IE, or Opera is running and sends the correct keystroke(s) for each:

许多用户只使用一个浏览器,但是如果您使用多个浏览器,则脚本的增强版本将支持它们。 例如,以下脚本可检测Chrome,Firefox,IE或Opera是否正在运行,并为每个脚本发送正确的击键:

F5:: WinGetTitle,ActiveTitle,A                 ; get title of active window IfInString,ActiveTitle,Mozilla Firefox    ; check if active window is Firefox   ShortcutKey:="a"                        ; send letter "a", Firefox shortcut for Copy Link Location Else                                      ; it is not Firefox IfInString,ActiveTitle,Google Chrome      ; check if active window is Chrome   ShortcutKey:="e"                        ; send letter "e", Chrome shortcut for Copy Link Address Else                                      ; it is not Chrome IfInString,ActiveTitle,Internet Explorer  ; check if active window is IE   ShortcutKey:="t{Enter}"                 ; send letter "t", IE shortcut for Copy Shortcut, but also needs Enter Else                                      ; it is not IE IfInString,ActiveTitle,Opera              ; check if active window is Opera   ShortcutKey:="e"                        ; send letter "e", Opera shortcut for Copy Link Address Else                                      ; it is not Opera {   MsgBox,4112,Error,Active window is not a supported browser.   Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon } Clipboard:=""                             ; empty the clipboard MouseClick,Right                          ; right-click at current mouse location Sleep,60                                  ; wait for 60 milliseconds to make sure context menu is there SendInput,%ShortcutKey%                   ; send shortcut to copy link ClipWait,2                                ; wait at most 2 seconds for short link to appear in clipboard If (ErrorLevel=1)                         ; ErrorLevel set to 1 when wait period expires {   MsgBox,4112,Error,Attempt to copy the short link onto the clipboard failed.   Return ; 4112 above means put dialog on top and give it the red X (error/stop) icon } StringSplit,ShortLink,Clipboard,#         ; split long link into two strings, separated at pound sign ShortLink:="#" . ShortLink2               ; add back pound sign to short link Clipboard:=ShortLink                      ; put short link on clipboard Return                                    ; success

This script works by looking at the title bar of the active window to see if it contains Mozilla Firefox, Google Chrome, Internet Explorer, or Opera. If it doesn't find one of those, it displays this error dialog:

该脚本通过查看活动窗口的标题栏来工作,以查看其是否包含Mozilla FirefoxGoogle ChromeInternet ExplorerOpera 。 如果找不到其中之一,则会显示此错误对话框:

There are two issues with the approach used in this script. First, a window title could contain one of those strings even if that browser is not running, e.g., if you are viewing a file called Mozilla Firefox ReadMe.txt in Notepad. Second, some browsers do not put the browser name in the window title, such as Vivaldi. To solve those issues, the script could use the ahk_exe parameter on the WinGetTitle statement, which identifies a window belonging to any process with the specified name or path, such as chrome.exe, firefox.exe, iexplore.exe, opera.exe, vivaldi.exe. I'll leave the creation of such a script to motivated readers. :)

此脚本中使用的方法存在两个问题。 首先,即使该浏览器未运行,窗口标题也可能包含这些字符串之一,例如,如果您正在记事本中查看名为Mozilla Firefox ReadMe.txt的文件。 其次,某些浏览器没有将浏览器名称放在窗口标题中,例如Vivaldi。 为了解决这些问题,脚本可以在WinGetTitle语句上使用ahk_exe参数,该参数标识具有指定名称或路径的任何进程的窗口,例如chrome.exefirefox.exeiexplore.exeOpera.exevivaldi.exe 。 我将这种脚本的创建留给有动机的读者。 :)

In conclusion, after positioning the mouse on an EE comment ID and hitting the hotkey that you have defined, you will have the short link on the clipboard — simply do a Ctrl-V/Paste to put it wherever you want!

总之,将鼠标放在EE注释ID上并按下定义的热键后,剪贴板上将具有短链接- 只需执行Ctrl-V /粘贴操作即可将其放置在所需的位置!

If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

如果您发现本文有帮助,请单击下面的大拇指图标。 这使我知道什么对EE成员有价值,并为以后的文章提供了指导。 非常感谢! 问候乔

翻译自: https://www.experts-exchange.com/articles/29416/How-to-copy-the-short-link-of-an-ID-at-Experts-Exchange-to-the-clipboard-with-a-single-keystroke.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值