forked from AmineB/ycombinator-keys
Compare commits
3 Commits
0f0a94d993
...
c1fcffa943
Author | SHA1 | Date | |
---|---|---|---|
c1fcffa943 | |||
f7bd78189a | |||
ffc97281ad |
@ -5,7 +5,7 @@
|
||||
// @match *://news.ycombinator.com/*
|
||||
// @icon https://gitea.amine-bouabdallaoui.fr/AmineB/ycombinator-keys/raw/branch/main/icons/48.png
|
||||
// @grant none
|
||||
// @version 7
|
||||
// @version 8
|
||||
// @author AmineB
|
||||
// @description Ycombinator keyboard nav.
|
||||
// @downloadURL https://gitea.amine-bouabdallaoui.fr/brian6932/ycombinator-keys/raw/branch/main/keyboard-watcher.user.js
|
||||
@ -18,7 +18,8 @@ globalThis.document.styleSheets[0].insertRule('tbody tr.athing>td.title>span.tit
|
||||
const requery = () => globalThis.document.querySelectorAll('tbody tr.athing')
|
||||
let
|
||||
query = requery(),
|
||||
selected = -1
|
||||
selected = -1,
|
||||
lastCollapsed
|
||||
const
|
||||
// This is a Firefox only option. For some reason older versions of Firefox can't set outline: none.
|
||||
focusInvisible = { __proto__: null, focusVisible: false },
|
||||
@ -36,26 +37,35 @@ const
|
||||
keydown = event => {
|
||||
switch (event.key) {
|
||||
case 'j':
|
||||
if (selected + 1 === query.length)
|
||||
const lastIndex = query.length - 1
|
||||
if (selected === lastIndex)
|
||||
return
|
||||
|
||||
if (selected !== -1)
|
||||
query[selected].style.boxShadow = ''
|
||||
|
||||
while (selected < query.length && query[++selected].classList.contains('noshow'));
|
||||
let hiddenChain = 0
|
||||
while (selected < lastIndex) {
|
||||
const hidden = query[++selected].classList.contains('noshow')
|
||||
hiddenChain = hiddenChain * hidden + hidden
|
||||
|
||||
if (!query[selected].classList.contains('noshow'))
|
||||
highlightSelected()
|
||||
if (!hidden) {
|
||||
lastCollapsed = query[selected].classList.contains('coll') ? selected : undefined
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
selected -= hiddenChain * (selected - hiddenChain === lastCollapsed)
|
||||
highlightSelected()
|
||||
return
|
||||
case 'k':
|
||||
if (selected <= 0)
|
||||
return
|
||||
|
||||
query[selected].style.boxShadow = ''
|
||||
while (selected >= 0 && query[--selected].classList.contains('noshow'));
|
||||
|
||||
if (!query[selected].classList.contains('noshow'))
|
||||
highlightSelected()
|
||||
while (selected >= 0 && query[--selected].classList.contains('noshow'));
|
||||
highlightSelected()
|
||||
return
|
||||
case 'h':
|
||||
if (globalThis.location.pathname === '/hidden')
|
||||
@ -67,7 +77,7 @@ const
|
||||
else
|
||||
query[selected].nextSibling.querySelector('a.clicky.hider')?.click()
|
||||
|
||||
if (selected + 1 <= query.length && !query[selected].classList.contains('noshow'))
|
||||
if (selected + 1 <= query?.length)
|
||||
highlightSelected()
|
||||
return
|
||||
case 'c':
|
||||
|
Loading…
x
Reference in New Issue
Block a user