diff --git a/yr.user.js b/yr.user.js index 4a99d5a..e7c7b10 100644 --- a/yr.user.js +++ b/yr.user.js @@ -1,8 +1,8 @@ // ==UserScript== // @name YR.no - Hotkeys -// @namespace http://tampermonkey.net/ -// @version 1.2.2 -// @description Navigate the yr.no navbar using `Ctrl` + `←`/`→` (For MAC: `Control` + `Option` + `←`/`→`). Navigate to 21-day forecast, radar map or daily table view using `Alt` + `L`, `Alt` + `R` or `Alt` + `V`. +// @namespace https://git.ntnu.no/M365-Drift/MonkeyMagic/ +// @version 1.3.0 +// @description Navigate the yr.no navbar using `Ctrl` + `←`/`→`. Navigate to 21-day forecast, radar map or daily table view using `Alt` + `L`, `Alt` + `R` or `Alt` + `V`. Show a menu to navigate through favorite locations with `Ctrl` + `Shift` + `F`. // @author Øyvind Nilsen (on@ntnu.no) // @match https://www.yr.no/* // @grant none @@ -41,6 +41,87 @@ } }; + // Create the menu element + const menu = document.createElement('div'); + menu.style.position = 'fixed'; + menu.style.top = '50%'; + menu.style.left = '50%'; + menu.style.transform = 'translate(-50%, -50%)'; + menu.style.backgroundColor = 'white'; + menu.style.border = '1px solid black'; + menu.style.padding = '10px'; + menu.style.zIndex = '10000'; + menu.style.display = 'none'; + menu.style.transition = 'opacity 0.4s'; + document.body.appendChild(menu); + + // Function to show the menu + async function showMenu() { + // Get favourited locations from localStorage + let favourites = JSON.parse(localStorage.getItem('favouritedLocations') || '[]'); + + // Get visited locations from localStorage + let visited = JSON.parse(localStorage.getItem('visitedLocations') || '[]'); + + // Combine the two arrays + let combinedLocations = favourites.concat(visited); + + const locationPromises = combinedLocations.map(id => fetch(`https://www.yr.no/api/v0/locations/${id}?language=${lang_code}`).then(response => response.json())); + const locations = await Promise.all(locationPromises); + + menu.innerHTML = '