Moved logic in rate change event listener into its own function to be triggered by setSpeed()

This commit is contained in:
Chad Bailey
2020-03-05 19:08:30 -06:00
parent dde52368a2
commit 00781ceaa3

View File

@@ -171,16 +171,7 @@ function defineVideoController() {
// Ignore ratechange events on unitialized videos.
// 0 == No information is available about the media resource.
if (event.target.readyState > 0) {
var speed = this.getSpeed();
this.speedIndicator.textContent = speed;
tc.settings.speeds[this.video.currentSrc] = speed;
tc.settings.lastSpeed = speed;
this.speed = speed;
chrome.storage.sync.set({ lastSpeed: speed }, function() {
console.log("Speed setting saved: " + speed);
});
// show the controller for 1000ms if it's hidden.
runAction("blink", document, null, null);
rateChanged(this);
}
}.bind(this))
);
@@ -586,6 +577,19 @@ function setSpeed(controller, video, speed) {
refreshCoolDown();
}
function rateChanged(controller) {
var speed = parseFloat(controller.video.playbackRate).toFixed(2);
controller.speedIndicator.textContent = speed;
tc.settings.speeds[controller.video.currentSrc] = speed;
tc.settings.lastSpeed = speed;
controller.speed = speed;
chrome.storage.sync.set({ lastSpeed: speed }, function() {
console.log("Speed setting saved: " + speed);
});
// show the controller for 1000ms if it's hidden.
runAction("blink", document, null, null);
}
function runAction(action, document, value, e) {
if (tc.settings.audioBoolean) {
var mediaTags = getShadow(document.body).filter(x => {