-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
43 lines (37 loc) · 998 Bytes
/
background.js
File metadata and controls
43 lines (37 loc) · 998 Bytes
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
function setPlaybackRate(playbackRate) {
document
.querySelectorAll("video")
.forEach((v) => (v.playbackRate = playbackRate));
}
function getPlaybackRate() {
let playbackRate = prompt("동영상 배속 설정", "1.0");
if (!+playbackRate) {
alert("올바른 숫자값을 입력해 주세요");
playbackRate = 1.0;
}
return +playbackRate;
}
function onClick(tab) {
chrome.scripting
.executeScript({
target: { tabId: tab.id },
func: getPlaybackRate,
})
.then((injectionResults) => {
for (const { result: playbackRate } of injectionResults) {
chrome.scripting.executeScript({
target: { tabId: tab.id, allFrames: true },
func: setPlaybackRate,
args: [playbackRate],
});
}
});
}
chrome.action.onClicked.addListener(function (tab) {
onClick(tab);
});
chrome.commands.onCommand.addListener(function (command, tab) {
if (command === "set_playback_rate") {
onClick(tab);
}
});