Last active
February 26, 2023 13:11
-
-
Save mooz/61a0e95c091c94a6a4bb9695bb42218b to your computer and use it in GitHub Desktop.
Ar5iv Hash Attacher: Attach a hash to the URL to create a permanent link when elements like sections and figures are clicked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Ar5iv Hash Attacher | |
// @namespace http://mooz.github.io/ | |
// @version 0.1 | |
// @description When elements like sections and figures are clicked, attach a hash to the URL to create a permanent link | |
// @author Masafumi Oyamada | |
// @match https://ar5iv.labs.arxiv.org/html/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=arxiv.org | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
document.addEventListener("click", (ev) => { | |
if (ev.button !== 0) return; | |
const target = /^h[0-9]$/.exec(ev.target.localName) ? ev.target.parentElement : ev.target; | |
const id = target.getAttribute("id"); | |
if (id) { | |
history.replaceState(null, null, "#" + id); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment