-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.ts
45 lines (45 loc) · 1.75 KB
/
content.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { PlasmoCSConfig } from 'plasmo';
import { Storage } from '@plasmohq/storage';
export const config: PlasmoCSConfig = {
matches: [
'https://www.youtube.com/*'
]
};
const storage = new Storage();
setInterval(async () => {
const url = window.location.href;
let checked = await storage.get<boolean>('checked');
let extension = await storage.get<boolean>('extension');
let shortcut = await storage.get('shortcut');
if (checked == null) {
await storage.set('checked', false);
checked = false;
}
if (extension == null) {
await storage.set('extension', true);
extension = true;
}
if (shortcut == null) {
await storage.set('shortcut', 'ALT + Q');
shortcut = 'ALT + Q';
}
if (url && url.startsWith('https://www.youtube.com/')) {
const split = url.split('/')[4];
const isChannel = url.split('/')[3].startsWith('@');
if (url.includes('/shorts') && !isChannel) {
if (checked && extension) {
window.location.replace(`https://www.youtube.com/watch?v=${split}`);
}
else if (!checked && extension) {
if (!isChannel) {
window.addEventListener('keydown', async (e) => {
e.preventDefault();
if ((e.altKey && shortcut.split('+')[0].trim() == 'ALT' || e.ctrlKey && shortcut.split('+')[0].trim() == 'CONTROL' || e.shiftKey && shortcut.split('+')[0].trim() == 'SHIFT') && e.key.toUpperCase() == shortcut.split('+')[1].trim()) {
window.location.replace(`https://www.youtube.com/watch?v=${split}`);
}
});
}
}
}
}
}, 1000);