feat: add hn goPage bindings

This commit is contained in:
Maddison Hellstrom 2019-03-07 15:08:10 -08:00
parent b53c06cafc
commit 7a1b5bcee9
2 changed files with 35 additions and 0 deletions

View File

@ -296,6 +296,29 @@ actions.hn.collapseNextComment = () => {
}
}
actions.hn.goPage = (dist = 1) => {
let u
try {
u = new URL(util.getCurrentLocation())
} catch (e) {
return
}
let page = u.searchParams.get("p")
if (page === null || page === "") {
page = "1"
}
const cur = parseInt(page, 10)
if (Number.isNaN(cur)) {
return
}
const dest = cur + dist
if (dest < 1) {
return
}
u.searchParams.set("p", dest)
actions.openLink(u.href)()
}
// ProductHunt
// -----------
actions.ph = {}

12
keys.js
View File

@ -386,6 +386,18 @@ const maps = {
description: "Go to parent",
callback: actions.hn.goParent,
},
{
leader: "",
alias: "]]",
description: "Next page",
callback: () => actions.hn.goPage(1),
},
{
leader: "",
alias: "[[",
description: "Prev page",
callback: () => actions.hn.goPage(-1),
},
],
"producthunt.com": [