Skip to content

Commit 5a8fb62

Browse files
committed
Set URL allow list
1 parent 1b3a955 commit 5a8fb62

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

content.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,45 @@
11
document.addEventListener('keydown', handleKeyDown);
22

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+
}
321

422
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+
534
if ( // k, j, l, m, <, > are already defined in YouTube
6-
window.location.hostname.includes('youtube.com')
35+
currentUrl.includes('youtube.com')
736
&& ['k', 'j', 'l', 'm', '<', '>'].includes(event.key)
837
) {
938
return;
1039
}
1140

1241
if ( // j & l cause issues on Netflix
13-
window.location.hostname.includes('netflix.com')
42+
currentUrl.includes('netflix.com')
1443
&& ['j', 'l'].includes(event.key)
1544
) {
1645
return;

0 commit comments

Comments
 (0)