-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinject-playback-speed.js
37 lines (31 loc) · 1019 Bytes
/
inject-playback-speed.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
// Re-set playback speed if the setting changes
browser.storage.onChanged.addListener((settings) => {
console.info("Extension settings changed.")
console.info("Changed values")
for (key in settings) {
console.info(`\t${key}: ${settings[key]["newValue"]}`)
}
if ("playback_speed" in settings) {
setPlaybackSpeed()
}
})
// Set the playback speed
function setPlaybackSpeed() {
function onGot(val) {
let videoElementList = document.getElementsByTagName("video")
if (videoElementList.length > 0)
{
console.info(`Set playback speed. It is ${val["playback_speed"]}.`)
for(var i = 0; i < videoElementList.length; i++)
{
videoElementList[i].playbackRate=val["playback_speed"] || 1
}
}
}
function onError(err) {
console.error(`Error: ${err}`)
}
let getValue = browser.storage.sync.get("playback_speed")
getValue.then(onGot, onError)
}
setPlaybackSpeed()