-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiframe.ts
More file actions
90 lines (83 loc) · 2.5 KB
/
iframe.ts
File metadata and controls
90 lines (83 loc) · 2.5 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { fullscreenNotification, getPlayerTime, shortcutListener } from './utils/player';
import { initShark } from './utils/shark';
initShark();
let tempPlayer: any;
getPlayerTime(function (item, player) {
chrome.runtime.sendMessage({ name: 'videoTime', item });
tempPlayer = player;
});
// @ts-ignore
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === 'videoTimeSet') {
con.log('[Iframe] Set Time', msg);
if (typeof tempPlayer === 'undefined') {
con.error('[Iframe] No player Found');
return;
}
if (typeof msg.time !== 'undefined') {
tempPlayer.play();
tempPlayer.currentTime = msg.time;
return;
}
if (typeof msg.timeAdd !== 'undefined') {
tempPlayer.play();
addVideoTime(msg.timeAdd);
}
} else if (msg.action === 'content') {
switch (msg.item.action) {
case 'fullscreenNotification':
fullscreenNotification(msg.item.text);
break;
default:
}
}
});
api.settings.init().then(() => {
shortcutListener(shortcut => {
con.log('[iframe] Shortcut', shortcut);
switch (shortcut.shortcut) {
case 'introSkipFwd':
addVideoTime(true);
break;
case 'introSkipBwd':
addVideoTime(false);
break;
case 'nextEpShort':
chrome.runtime.sendMessage({
name: 'content',
item: { action: 'nextEpShort' },
});
break;
case 'correctionShort':
chrome.runtime.sendMessage({
name: 'content',
item: { action: 'correctionShort' },
});
break;
case 'syncShort':
chrome.runtime.sendMessage({
name: 'content',
item: { action: 'syncShort' },
});
break;
default:
}
});
});
async function addVideoTime(forward: boolean) {
if (typeof tempPlayer === 'undefined') {
con.error('[Iframe] No player Found');
return;
}
let time = parseInt(await api.settings.getAsync('introSkip'));
if (!forward) time = 0 - time;
const totalTime = tempPlayer.currentTime + time;
if (tempPlayer.duration && tempPlayer.duration > 15 && totalTime > tempPlayer.duration - 3) {
tempPlayer.currentTime = tempPlayer.duration - 3;
return;
}
tempPlayer.currentTime = totalTime;
}
const css =
'font-size: 20px; padding-bottom: 3px; color: white; text-shadow: -1px -1px #2e51a2, 1px -1px #2e51a2, -1px 1px #2e51a2, 1px 1px #2e51a2, 2px 2px #2e51a2, 3px 3px #2e51a2;';
console.log('%cIframe', css, window.location.host);