-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // ==UserScript== | ||
| // @name YR Hotkeys | ||
| // @namespace http://tampermonkey.net/ | ||
| // @version 1.0 | ||
| // @description Hotkeys 'alt+l', 'alt+r', or 'alt+v' for yr.no | ||
| // @author Your Name | ||
| // @match https://www.yr.no/* | ||
| // @grant none | ||
| // ==/UserScript== | ||
|
|
||
| (function() { | ||
| 'use strict'; | ||
|
|
||
| // Add event listener for keydown events | ||
| document.addEventListener('keydown', function(event) { | ||
| if (event.altKey && (event.key === 'l' || event.key === 'r' || event.key === 'v')) { | ||
| // Get the current URL | ||
| const url = window.location.href; | ||
| const pattern = /https:\/\/(?:www\.)?yr\.no\/([a-z]{2,3})\/(.+)\/([0-9-]+)\//; | ||
| const match = url.match(pattern); | ||
| var view = ''; | ||
|
|
||
| if (match) { | ||
| console.log("Full match:", match[0]); | ||
| console.log("Language code:", match[1]); | ||
| console.log("Path:", match[2]); | ||
| console.log("ID:", match[3]); | ||
|
|
||
| if (match[1] === 'nb') { | ||
| console.log("This is the Norwegian site."); | ||
| if (event.key === 'l') { | ||
| view = `21-dagersvarsel`; | ||
| } else if (event.key === 'r') { | ||
| view = `kart/radar`; | ||
| } else if (event.key === 'v') { | ||
| view = `værvarsel/daglig-tabell`; | ||
| } | ||
| } else if (match[1] === 'en') { | ||
| console.log("This is the English site."); | ||
| if (event.key === 'l') { | ||
| view = `21-day-forecast`; | ||
| } else if (event.key === 'r') { | ||
| view = `map/radar`; | ||
| } else if (event.key === 'v') { | ||
| view = `forecast/daily-table`; | ||
| } | ||
| } else { | ||
| console.log("This is another language site."); | ||
| } | ||
|
|
||
| if (view) { | ||
| const newUrl = `https://www.yr.no/${match[1]}/${view}/${match[3]}/`; | ||
| window.location.href = newUrl; | ||
| //console.log(`Redirecting to ${newUrl}`); | ||
| } | ||
| } else { | ||
| console.log("No match found."); | ||
| } | ||
|
|
||
| //alert(`You pressed the '${event.key}' key. The url is ${url}`); | ||
| } | ||
| }); | ||
| })(); |