From 7a1b5bcee9fad13ca33183f9a010f6b4d782adaa Mon Sep 17 00:00:00 2001 From: Maddison Hellstrom Date: Thu, 7 Mar 2019 15:08:10 -0800 Subject: [PATCH] feat: add hn goPage bindings --- actions.js | 23 +++++++++++++++++++++++ keys.js | 12 ++++++++++++ 2 files changed, 35 insertions(+) diff --git a/actions.js b/actions.js index 63dd68d..d0979fa 100644 --- a/actions.js +++ b/actions.js @@ -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 = {} diff --git a/keys.js b/keys.js index 9a70f95..19210c3 100644 --- a/keys.js +++ b/keys.js @@ -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": [