From 85b898c623ae09d5caa88041bd8ceb26d4f1defc Mon Sep 17 00:00:00 2001 From: stysebae <32852093+stysebae@users.noreply.github.com> Date: Tue, 19 Oct 2021 10:46:39 +0200 Subject: Add shortcut to jump to next unread article (issue #3393) (#3891) * Add shortcut to jump to next unread article * phpcbf Co-authored-by: Alexandre Alapetite --- p/scripts/main.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'p/scripts') diff --git a/p/scripts/main.js b/p/scripts/main.js index 1707a09b8..f44692103 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -470,6 +470,21 @@ function next_entry(skipping) { toggleContent(new_active, old_active, skipping); } +function next_unread_entry(skipping) { + const old_active = document.querySelector('.flux.current'); + let new_active = old_active; + if (new_active) { + do new_active = new_active.nextElementSibling; + while (new_active && !new_active.classList.contains('not_read')); + if (!new_active) { + next_feed(); + } + } else { + new_active = document.querySelector('.not_read'); + } + toggleContent(new_active, old_active, skipping); +} + function prev_feed() { let found = false; let adjacent = null; @@ -568,6 +583,20 @@ function next_category() { } } +function next_unread_category() { + const active_cat = document.querySelector('#aside_feed .category.active'); + if (active_cat) { + let cat = active_cat; + do cat = cat.nextElementSibling; + while (cat && cat.getAttribute('data-unread') <= 0); + if (cat) { + delayedClick(cat.querySelector('a.title')); + } + } else { + first_category(); + } +} + function first_category() { const a = document.querySelector('#aside_feed .category:not([data-unread="0"]) a.title'); delayedClick(a); @@ -831,6 +860,16 @@ function init_shortcuts() { } return false; } + if (k === s.next_unread_entry) { + if (ev.altKey) { + next_unread_category(); + } else if (ev.shiftKey) { + next_feed(); + } else { + next_unread_entry(false); + } + return false; + } if (k === s.prev_entry) { if (ev.altKey) { prev_category(); -- cgit v1.2.3