Skip to content

Instantly share code, notes, and snippets.

@kkew3
Last active July 27, 2018 17:57
Show Gist options
  • Save kkew3/5aaeb6ec8380045a191323c22dbfe620 to your computer and use it in GitHub Desktop.
Save kkew3/5aaeb6ec8380045a191323c22dbfe620 to your computer and use it in GitHub Desktop.
AutoHotKey script that toggles between arXiv abstract page and PDF. This script only supports Chrome for security (you won't want it to ruin other applications with possibly conflicting key bindings), but it's trivial to change.
/*
Under context of Chrome browser, and if the URL starts with "https://arxiv.org/":
"Windows + Alt + P" - Go to PDF is in abstract page, and go to abstract page if in PDF
(will not overwrite clipboard)
*/
#IfWinActive ahk_exe chrome.exe
#!p::
Send ^l
Sleep, 100
oldClipboard := Clipboard
Send ^c
Sleep, 200
if (RegExMatch(Clipboard, "^https:\/\/arxiv\.org\/") != 0)
{
if (RegExMatch(Clipboard, "O)^https:\/\/arxiv\.org\/pdf\/(\d+\.\d+(v\d+)?)\.pdf$", match) != 0)
{
arxivId := match.Value(1)
toUrl := "https://arxiv.org/abs/" . arxivId
Send % toUrl . "{Enter}"
}
else if (RegExMatch(Clipboard, "O)^https:\/\/arxiv\.org\/abs\/(\d+\.\d+(v\d+)?)$", match) != 0)
{
arxivId := match.Value(1)
toUrl := "https://arxiv.org/pdf/" . arxivId . ".pdf"
Send % toUrl . "{Enter}"
}
else
{
MsgBox % "Unrecognizable URL: " . Clipboard
Send, {Esc}
}
}
else
{
MsgBox, "#!p shortcut only functions under arXiv pages"
Send, {Esc}
}
Clipboard := oldClipboard
Return
#IfWinActive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment