forked from AmineB/ycombinator-keys
Compare commits
3 Commits
e04ab7aacc
...
27e1c54451
Author | SHA1 | Date | |
---|---|---|---|
27e1c54451
|
|||
3e431c552b
|
|||
86026e4839
|
@ -5,7 +5,7 @@
|
|||||||
// @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 10
|
// @version 11
|
||||||
// @author AmineB
|
// @author AmineB
|
||||||
// @description Ycombinator keyboard nav.
|
// @description Ycombinator keyboard nav.
|
||||||
// @downloadURL https://gitea.amine-bouabdallaoui.fr/brian6932/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
|
||||||
@ -38,75 +38,74 @@ const
|
|||||||
query[selected].lastChild.firstChild.firstChild.focus(focusInvisible)
|
query[selected].lastChild.firstChild.firstChild.focus(focusInvisible)
|
||||||
},
|
},
|
||||||
keydown = event => {
|
keydown = event => {
|
||||||
if (input.has(globalThis.document.activeElement.tagName))
|
if (!input.has(event.target.tagName))
|
||||||
return
|
switch (event.key) {
|
||||||
switch (event.key) {
|
case 'j':
|
||||||
case 'j':
|
const lastIndex = query.length - 1
|
||||||
const lastIndex = query.length - 1
|
if (selected === lastIndex)
|
||||||
if (selected === lastIndex)
|
return
|
||||||
return
|
|
||||||
|
|
||||||
if (selected !== -1)
|
if (selected !== -1)
|
||||||
query[selected].style.boxShadow = ''
|
query[selected].style.boxShadow = ''
|
||||||
|
|
||||||
let hiddenChain = 0
|
let hiddenChain = 0
|
||||||
while (selected < lastIndex) {
|
while (selected < lastIndex) {
|
||||||
const hidden = query[++selected].classList.contains('noshow')
|
const hidden = query[++selected].classList.contains('noshow')
|
||||||
hiddenChain = hiddenChain * hidden + hidden
|
hiddenChain = hiddenChain * hidden + hidden
|
||||||
|
|
||||||
if (!hidden) {
|
if (!hidden) {
|
||||||
lastCollapsed = query[selected].classList.contains('coll') ? selected : undefined
|
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'));
|
|
||||||
highlightSelected()
|
|
||||||
return
|
|
||||||
case 'h':
|
|
||||||
if (globalThis.location.pathname === '/hidden')
|
|
||||||
for (const selector of query[selected].nextSibling.querySelectorAll('a'))
|
|
||||||
if (selector.innerText === 'un-hide') {
|
|
||||||
selector.click()
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
query[selected].nextSibling.querySelector('a.clicky.hider')?.click()
|
|
||||||
|
|
||||||
if (selected + 1 <= query.length)
|
selected -= hiddenChain * (selected - hiddenChain === lastCollapsed)
|
||||||
highlightSelected()
|
highlightSelected()
|
||||||
return
|
|
||||||
case 'c':
|
|
||||||
globalThis.open('https://news.ycombinator.com/item?id=' + query[selected].id, '_self')
|
|
||||||
return
|
|
||||||
case 'C':
|
|
||||||
globalThis.open('https://news.ycombinator.com/item?id=' + query[selected].id)
|
|
||||||
return
|
|
||||||
case 'r':
|
|
||||||
if (!isComment())
|
|
||||||
return
|
return
|
||||||
globalThis.open(query[selected].querySelector('div.reply a').href, '_self')
|
case 'k':
|
||||||
return
|
if (selected <= 0)
|
||||||
case 'R':
|
return
|
||||||
if (!isComment())
|
|
||||||
|
query[selected].style.boxShadow = ''
|
||||||
|
|
||||||
|
while (selected >= 0 && query[--selected].classList.contains('noshow'));
|
||||||
|
highlightSelected()
|
||||||
return
|
return
|
||||||
globalThis.open(query[selected].querySelector('div.reply a').href)
|
case 'h':
|
||||||
return
|
if (globalThis.location.pathname === '/hidden')
|
||||||
case 'u':
|
for (const selector of query[selected].nextSibling.querySelectorAll('a'))
|
||||||
globalThis.open((isComment() ? query[selected] : query[selected].nextSibling).querySelector('a.hnuser').href, '_self')
|
if (selector.innerText === 'un-hide') {
|
||||||
return
|
selector.click()
|
||||||
case 'U':
|
break
|
||||||
globalThis.open((isComment() ? query[selected] : query[selected].nextSibling).querySelector('a.hnuser').href)
|
}
|
||||||
}
|
else
|
||||||
|
query[selected].nextSibling.querySelector('a.clicky.hider')?.click()
|
||||||
|
|
||||||
|
if (selected + 1 <= query.length)
|
||||||
|
highlightSelected()
|
||||||
|
return
|
||||||
|
case 'c':
|
||||||
|
globalThis.open('https://news.ycombinator.com/item?id=' + query[selected].id, '_self')
|
||||||
|
return
|
||||||
|
case 'C':
|
||||||
|
globalThis.open('https://news.ycombinator.com/item?id=' + query[selected].id)
|
||||||
|
return
|
||||||
|
case 'r':
|
||||||
|
if (!isComment())
|
||||||
|
return
|
||||||
|
globalThis.open(query[selected].querySelector('div.reply a').href, '_self')
|
||||||
|
return
|
||||||
|
case 'R':
|
||||||
|
if (!isComment())
|
||||||
|
return
|
||||||
|
globalThis.open(query[selected].querySelector('div.reply a').href)
|
||||||
|
return
|
||||||
|
case 'u':
|
||||||
|
globalThis.open((isComment() ? query[selected] : query[selected].nextSibling).querySelector('a.hnuser').href, '_self')
|
||||||
|
return
|
||||||
|
case 'U':
|
||||||
|
globalThis.open((isComment() ? query[selected] : query[selected].nextSibling).querySelector('a.hnuser').href)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
listen = () => globalThis.document.addEventListener('keydown', keydown)
|
listen = () => globalThis.document.addEventListener('keydown', keydown)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user