-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
41 lines (34 loc) · 1.15 KB
/
popup.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
const speedSlider = document.getElementById("speed-slider");
const speedDisplay = document.getElementById("speed-display");
function setCurrentSpeedValue(speed) {
speedDisplay.textContent = `${parseFloat(speed).toFixed(2)}x`;
speedSlider.value = speed;
}
chrome.storage.local.get("playbackSpeed", function (data) {
if (data.playbackSpeed) {
setCurrentSpeedValue(data.playbackSpeed);
}
});
function updatePlaybackSpeed(speed) {
setCurrentSpeedValue(speed);
chrome.storage.local.set({ playbackSpeed: speed });
chrome.tabs.query({ url: "*://www.youtube.com/*" }, function (tabs) {
tabs.forEach(function (tab) {
chrome.tabs.sendMessage(tab.id, { action: "setPlaybackSpeed", speed: speed }, function (response) {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
} else {
console.log(response);
}
});
});
});
}
speedSlider.addEventListener("input", function (event) {
const speed = event.target.value;
updatePlaybackSpeed(speed);
});
speedSlider.addEventListener("mouseup", function (event) {
const speed = event.target.value;
updatePlaybackSpeed(speed);
});