From 53cfcad7e57314082263543edfe486d5d4a90d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Andreas=20Nilsen?= Date: Wed, 28 Aug 2024 13:02:52 +0200 Subject: [PATCH] Clicks outside the favorite menu will now close it --- yr.user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/yr.user.js b/yr.user.js index cb2c0d3..e268b52 100644 --- a/yr.user.js +++ b/yr.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name YR.no - Hotkeys // @namespace https://git.ntnu.no/M365-Drift/MonkeyMagic/ -// @version 1.3.1 +// @version 1.3.2 // @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/* @@ -43,6 +43,7 @@ // Create the menu element const menu = document.createElement('div'); + menu.id = 'location-favo-menu'; menu.style.position = 'fixed'; menu.style.top = '50%'; menu.style.left = '50%'; @@ -179,4 +180,12 @@ } } }); + + // Add event listener to close the menu when clicking outside of it + document.addEventListener('click', function(event) { + const menu = document.querySelector('#location-favo-menu'); // Replace with your actual menu selector + if (menu && !menu.contains(event.target)) { + hideMenu(); + } + }); })(); \ No newline at end of file