Compare commits

..

3 Commits

Author SHA1 Message Date
0f0a94d993 Bump ver 2025-05-15 22:31:30 -04:00
3ee61aa074 Set branch-specific URIs 2025-05-15 22:30:54 -04:00
6cc8a1a877 Rewrite 2025-05-15 22:30:46 -04:00

View File

@ -5,11 +5,11 @@
// @match *://news.ycombinator.com/* // @match *://news.ycombinator.com/*
// @icon https://gitea.amine-bouabdallaoui.fr/AmineB/ycombinator-keys/raw/branch/main/icons/48.png // @icon https://gitea.amine-bouabdallaoui.fr/AmineB/ycombinator-keys/raw/branch/main/icons/48.png
// @grant none // @grant none
// @version 4 // @version 7
// @author AmineB // @author AmineB
// @description Ycombinator keyboard nav. // @description Ycombinator keyboard nav.
// @downloadURL https://gitea.amine-bouabdallaoui.fr/AmineB/ycombinator-keys/raw/branch/main/keyboard-watcher.user.js // @downloadURL https://gitea.amine-bouabdallaoui.fr/brian6932/ycombinator-keys/raw/branch/main/keyboard-watcher.user.js
// @updateURL https://gitea.amine-bouabdallaoui.fr/AmineB/ycombinator-keys/raw/branch/main/keyboard-watcher.user.js // @updateURL https://gitea.amine-bouabdallaoui.fr/brian6932/ycombinator-keys/raw/branch/main/keyboard-watcher.user.js
// ==/UserScript== // ==/UserScript==
// jshint esversion: 11 // jshint esversion: 11
@ -18,12 +18,8 @@ globalThis.document.styleSheets[0].insertRule('tbody tr.athing>td.title>span.tit
const requery = () => globalThis.document.querySelectorAll('tbody tr.athing') const requery = () => globalThis.document.querySelectorAll('tbody tr.athing')
let let
query = requery(), query = requery(),
selected = -1, selected = -1
lastCollapsed
const const
input = new Set()
.add('INPUT')
.add('TEXTAREA'),
// This is a Firefox only option. For some reason older versions of Firefox can't set outline: none. // This is a Firefox only option. For some reason older versions of Firefox can't set outline: none.
focusInvisible = { __proto__: null, focusVisible: false }, focusInvisible = { __proto__: null, focusVisible: false },
isComment = () => query[selected].classList.contains('comtr'), isComment = () => query[selected].classList.contains('comtr'),
@ -38,28 +34,17 @@ const
query[selected].lastChild.firstChild.firstChild.focus(focusInvisible) query[selected].lastChild.firstChild.firstChild.focus(focusInvisible)
}, },
keydown = event => { keydown = event => {
if (!input.has(event.target.tagName))
switch (event.key) { switch (event.key) {
case 'j': case 'j':
const lastIndex = query.length - 1 if (selected + 1 === query.length)
if (selected === lastIndex)
return return
if (selected !== -1) if (selected !== -1)
query[selected].style.boxShadow = '' query[selected].style.boxShadow = ''
let hiddenChain = 0 while (selected < query.length && query[++selected].classList.contains('noshow'));
while (selected < lastIndex) {
const hidden = query[++selected].classList.contains('noshow')
hiddenChain = hiddenChain * hidden + hidden
if (!hidden) { if (!query[selected].classList.contains('noshow'))
lastCollapsed = query[selected].classList.contains('coll') ? selected : undefined
break
}
}
selected -= hiddenChain * (selected - hiddenChain === lastCollapsed)
highlightSelected() highlightSelected()
return return
case 'k': case 'k':
@ -67,8 +52,9 @@ const
return return
query[selected].style.boxShadow = '' query[selected].style.boxShadow = ''
while (selected >= 0 && query[--selected].classList.contains('noshow')); while (selected >= 0 && query[--selected].classList.contains('noshow'));
if (!query[selected].classList.contains('noshow'))
highlightSelected() highlightSelected()
return return
case 'h': case 'h':
@ -81,7 +67,7 @@ const
else else
query[selected].nextSibling.querySelector('a.clicky.hider')?.click() query[selected].nextSibling.querySelector('a.clicky.hider')?.click()
if (selected + 1 <= query.length) if (selected + 1 <= query.length && !query[selected].classList.contains('noshow'))
highlightSelected() highlightSelected()
return return
case 'c': case 'c':