add keyboard arrow navigation

master
Aevann 2024-01-15 03:42:26 +02:00
parent 6dd84b8815
commit a625268eb1
1 changed files with 16 additions and 7 deletions

View File

@ -43,15 +43,24 @@ if (fake_textarea) {
//SWIPING
//SWIPING AND KEYBOARD ARROWS
if (screen_width < 768) {
const post_ids = localStorage.getItem("post_ids").split(', ');
const current_index = post_ids.indexOf(`'${location.href}'`)
if (current_index > -1) {
const id_after = post_ids[current_index+1]
const id_before = post_ids[current_index-1]
const post_ids = localStorage.getItem("post_ids").split(', ');
const current_index = post_ids.indexOf(`'${location.href}'`)
if (current_index > -1) {
const id_after = post_ids[current_index+1]
const id_before = post_ids[current_index-1]
document.addEventListener('keydown', (e) => {
if (id_before && e.key == 'ArrowLeft') {
location.href = id_before.slice(1, -1)
}
else if (id_after && e.key == 'ArrowRight') {
location.href = id_after.slice(1, -1)
}
})
if (screen_width < 768) {
const _C = document.querySelector('.container')
const N = _C.children.length
const NF = 30