Use .currentSrc instead of .src to correctly identify video (#529)

This commit is contained in:
Timothy Lim
2019-10-06 07:54:11 +08:00
committed by Ilya Grigorik
parent 5641369385
commit 49e9f4b78d

View File

@@ -122,28 +122,28 @@
this.speed = 1.0; this.speed = 1.0;
if (!tc.settings.rememberSpeed) { if (!tc.settings.rememberSpeed) {
if (!tc.settings.speeds[target.src]) { if (!tc.settings.speeds[target.currentSrc]) {
tc.settings.speeds[target.src] = this.speed; tc.settings.speeds[target.currentSrc] = this.speed;
} }
setKeyBindings("reset", getKeyBindings("fast")); // resetSpeed = fastSpeed setKeyBindings("reset", getKeyBindings("fast")); // resetSpeed = fastSpeed
} else { } else {
tc.settings.speeds[target.src] = tc.settings.lastSpeed; tc.settings.speeds[target.currentSrc] = tc.settings.lastSpeed;
} }
target.playbackRate = tc.settings.speeds[target.src]; target.playbackRate = tc.settings.speeds[target.currentSrc];
this.div=this.initializeControls(); this.div=this.initializeControls();
target.addEventListener('play', this.handlePlay = function(event) { target.addEventListener('play', this.handlePlay = function(event) {
if (!tc.settings.rememberSpeed) { if (!tc.settings.rememberSpeed) {
if (!tc.settings.speeds[target.src]) { if (!tc.settings.speeds[target.currentSrc]) {
tc.settings.speeds[target.src] = this.speed; tc.settings.speeds[target.currentSrc] = this.speed;
} }
setKeyBindings("reset", getKeyBindings("fast")); // resetSpeed = fastSpeed setKeyBindings("reset", getKeyBindings("fast")); // resetSpeed = fastSpeed
} else { } else {
tc.settings.speeds[target.src] = tc.settings.lastSpeed; tc.settings.speeds[target.currentSrc] = tc.settings.lastSpeed;
} }
target.playbackRate = tc.settings.speeds[target.src]; target.playbackRate = tc.settings.speeds[target.currentSrc];
}.bind(this)); }.bind(this));
target.addEventListener('ratechange', this.handleRatechange = function(event) { target.addEventListener('ratechange', this.handleRatechange = function(event) {
@@ -152,7 +152,7 @@
if (event.target.readyState > 0) { if (event.target.readyState > 0) {
var speed = this.getSpeed(); var speed = this.getSpeed();
this.speedIndicator.textContent = speed; this.speedIndicator.textContent = speed;
tc.settings.speeds[this.video.src] = speed; tc.settings.speeds[this.video.currentSrc] = speed;
tc.settings.lastSpeed = speed; tc.settings.lastSpeed = speed;
this.speed = speed; this.speed = speed;
chrome.storage.sync.set({'lastSpeed': speed}, function() { chrome.storage.sync.set({'lastSpeed': speed}, function() {
@@ -163,12 +163,12 @@
var observer=new MutationObserver((mutations) => { var observer=new MutationObserver((mutations) => {
mutations.forEach((mutation) => { mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'src'){ if (mutation.type === 'attributes' && (mutation.attributeName === 'src' || mutation.attributeName === 'currentSrc')){
var controller = document.querySelector(`div[data-vscid="${this.id}"]`); var controller = document.querySelector(`div[data-vscid="${this.id}"]`);
if(!controller){ if(!controller){
return; return;
} }
if (!mutation.target.src) { if (!mutation.target.currentSrc) {
controller.classList.add('vsc-nosource'); controller.classList.add('vsc-nosource');
} else { } else {
controller.classList.remove('vsc-nosource'); controller.classList.remove('vsc-nosource');
@@ -177,7 +177,7 @@
}); });
}); });
observer.observe(target, { observer.observe(target, {
attributeFilter: ["src"] attributeFilter: ["src", "currentSrc"]
}); });
}; };
@@ -195,7 +195,7 @@
tc.videoController.prototype.initializeControls = function() { tc.videoController.prototype.initializeControls = function() {
var document = this.document; var document = this.document;
var speed = parseFloat(tc.settings.speeds[this.video.src]).toFixed(2), var speed = parseFloat(tc.settings.speeds[this.video.currentSrc]).toFixed(2),
top = Math.max(this.video.offsetTop, 0) + "px", top = Math.max(this.video.offsetTop, 0) + "px",
left = Math.max(this.video.offsetLeft, 0) + "px"; left = Math.max(this.video.offsetLeft, 0) + "px";
@@ -203,7 +203,7 @@
wrapper.classList.add('vsc-controller'); wrapper.classList.add('vsc-controller');
wrapper.dataset['vscid'] = this.id; wrapper.dataset['vscid'] = this.id;
if (!this.video.src) { if (!this.video.currentSrc) {
wrapper.classList.add('vsc-nosource'); wrapper.classList.add('vsc-nosource');
} }