|
1 | 1 | document.addEventListener('keydown', handleKeyDown); |
2 | 2 |
|
| 3 | +const allowedUrls = [ |
| 4 | + 'https://www.youtube.com/watch*', |
| 5 | + 'https://www.netflix.com/watch/*', |
| 6 | + 'https://play.hbomax.com/player/*', |
| 7 | + 'https://podcasts.google.com/*', |
| 8 | + 'https://www.paramountplus.com/shows/video/*', |
| 9 | + 'https://www.disneyplus.com/video/*', |
| 10 | + 'https://www.amazon.com/gp/video/detail/*', |
| 11 | + 'https://www.hulu.com/watch/*', |
| 12 | +]; |
| 13 | + |
| 14 | +function isUrlAllowed(allowedUrls, urlToCheck) { |
| 15 | + console.log(`urlToCheck: ${urlToCheck}`); |
| 16 | + return allowedUrls.some(url => { |
| 17 | + const regex = new RegExp("^" + url.replace("*", ".*") + "$"); |
| 18 | + return regex.test(urlToCheck); |
| 19 | + }); |
| 20 | +} |
3 | 21 |
|
4 | 22 | function handleKeyDown(event) { |
| 23 | + const currentUrl = window.location.href; |
| 24 | + |
| 25 | + console.log(`currentUrl: ${currentUrl}`); |
| 26 | + |
| 27 | + if (!isUrlAllowed(allowedUrls, currentUrl)) { |
| 28 | + console.log('URL not in the allowlist for Media Controller'); |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + console.log('Allowed'); |
| 33 | + |
5 | 34 | if ( // k, j, l, m, <, > are already defined in YouTube |
6 | | - window.location.hostname.includes('youtube.com') |
| 35 | + currentUrl.includes('youtube.com') |
7 | 36 | && ['k', 'j', 'l', 'm', '<', '>'].includes(event.key) |
8 | 37 | ) { |
9 | 38 | return; |
10 | 39 | } |
11 | 40 |
|
12 | 41 | if ( // j & l cause issues on Netflix |
13 | | - window.location.hostname.includes('netflix.com') |
| 42 | + currentUrl.includes('netflix.com') |
14 | 43 | && ['j', 'l'].includes(event.key) |
15 | 44 | ) { |
16 | 45 | return; |
|
0 commit comments