[src:feat] scroll to URL hash

This commit is contained in:
Maddison Hellstrom 2020-12-15 21:54:11 -08:00
parent 25b44e8f5c
commit f246b0e9ba
2 changed files with 15 additions and 0 deletions

View File

@ -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) => () => {

View File

@ -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": [