-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
54 lines (51 loc) · 1.71 KB
/
background.js
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
chrome.commands.onCommand.addListener(function(command) {
if (command === 'increase-speed') {
increaseSpeed(); // Llama a la función para aumentar la velocidad
} else if (command === 'decrease-speed') {
decreaseSpeed(); // Llama a la función para disminuir la velocidad
} else if (command === 'reset-speed') {
resetSpeed(); // Llama a la función para restablecer la velocidad
}
});
function increaseSpeed() {
// Aumenta la velocidad en 0.1x
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: () => {
let videoElement = document.querySelector('video');
if (videoElement) {
videoElement.playbackRate = Math.min(videoElement.playbackRate + 0.1, 2.0);
}
}
});
});
}
function decreaseSpeed() {
// Disminuye la velocidad en 0.1x
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: () => {
let videoElement = document.querySelector('video');
if (videoElement) {
videoElement.playbackRate = Math.max(videoElement.playbackRate - 0.1, 0.1);
}
}
});
});
}
function resetSpeed() {
// Restablece la velocidad a 1.0x
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: () => {
let videoElement = document.querySelector('video');
if (videoElement) {
videoElement.playbackRate = 1.0;
}
}
});
});
}