Skip to content

Instantly share code, notes, and snippets.

@allenyllee
Last active November 18, 2022 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allenyllee/0c90341680459203df6453b5d60d28f2 to your computer and use it in GitHub Desktop.
Save allenyllee/0c90341680459203df6453b5d60d28f2 to your computer and use it in GitHub Desktop.
If you open an pdf url of arxiv paper, then wants to jump to its abstract page, using this javascript as bookmarklet. https://bookmarkify.it/9634
javascript:(function()%7Bvar%20str%20%3D%20location.href%3Bstr%20%3D%20str.replace(%2F%5C.pdf%2Fg%2C%20%22%22)%3Bstr%20%3D%20str.replace(%2Fpdf%2Fg%2C%20%22abs%22)%3Blocation.href%20%3D%20str%7D)()
// ===================
// arxiv-pdf-to-abstract-url.js
// ===================
// Location href Property
// https://www.w3schools.com/jsref/prop_loc_href.asp
// 透過HTML DOM 的 Location Object 的 href Property 取得目前頁面的URL
// 假設原始 arxiv pdf url 為 "https://arxiv.org/pdf/1703.09137.pdf"
var str = location.href;
// JavaScript String Methods
// https://www.w3schools.com/js/js_string_methods.asp
// 移除網址最後的.pdf 得到 "https://arxiv.org/pdf/1703.09137"
str = str.replace(/\.pdf/g, "");
// 將網址中的pdf 轉成 abs 得到 "https://arxiv.org/abs/1703.09137"
str = str.replace(/pdf/g, "abs");
// How to get the browser to navigate to URL in JavaScript - Stack Overflow
// https://stackoverflow.com/questions/1226714/how-to-get-the-browser-to-navigate-to-url-in-javascript
// 跳到abs 網址
location.href = str;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment