Skip to content

Instantly share code, notes, and snippets.

@mooz
Last active February 26, 2023 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooz/61a0e95c091c94a6a4bb9695bb42218b to your computer and use it in GitHub Desktop.
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
// ==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