Skip to content

Commit

Permalink
CTRL+Arrow now wraps if you goes right from the last item or left fro…
Browse files Browse the repository at this point in the history
…m the first item
  • Loading branch information
on committed Aug 21, 2024
1 parent fee4424 commit fe9e436
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions yr.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name YR.no - Hotkeys
// @namespace http://tampermonkey.net/
// @version 1.2.0
// @version 1.2.1
// @description Navigate the yr.no navbar using Ctrl + Left Arrow and Ctrl + Right Arrow. Navigate to 21-day forecast, radar map or daily table view using Alt + L, Alt + R or Alt + V.
// @author on@ntnu.no
// @match https://www.yr.no/*
Expand All @@ -22,10 +22,10 @@
const activeItem = navbar.querySelector('.location-header__menu-item a[aria-current="page"]');
let currentIndex = Array.from(items).indexOf(activeItem.parentElement);

if (direction === 'left' && currentIndex > 0) {
currentIndex--;
} else if (direction === 'right' && currentIndex < items.length - 1) {
currentIndex++;
if (direction === 'left') {
currentIndex = (currentIndex > 0) ? currentIndex - 1 : items.length - 1;
} else if (direction === 'right') {
currentIndex = (currentIndex < items.length - 1) ? currentIndex + 1 : 0;
}

if (currentIndex >= 0 && currentIndex < items.length) {
Expand Down

0 comments on commit fe9e436

Please sign in to comment.