diff --git a/actions.js b/actions.js index a081d56..e76193a 100644 --- a/actions.js +++ b/actions.js @@ -93,6 +93,15 @@ actions.showSpeedReader = () => { document.body.appendChild(script) } +actions.scrollToHash = (hash = null) => { + const h = (hash || document.location.hash).replace("#", "") + const e = document.getElementById(h) || document.querySelector(`[name="${h}"]`) + if (!e) { + return + } + e.scrollIntoView({ behavior: "smooth" }) +} + // Surfingkeys-specific actions // ---------------------------- actions.createHint = (selector, action) => () => { diff --git a/keys.js b/keys.js index f6472cb..1b47424 100644 --- a/keys.js +++ b/keys.js @@ -183,6 +183,12 @@ const maps = { category: categories.tabs, description: "Close tab to right", }, + { + alias: "gh", + category: categories.clipboard, + description: "Scroll to element targeted by URL hash", + callback: actions.scrollToHash, + }, ], "amazon.com": [