diff --git a/yr.user.js b/yr.user.js index f6b3498..71b183c 100644 --- a/yr.user.js +++ b/yr.user.js @@ -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/* @@ -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) {