mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-21 18:08:46 -04:00
Hide controller for videos with no source (#467)
* Check for source upon initialization * Hide controllers for videos with no source. - Create a MutationObserver for each video to watch for source changes.
This commit is contained in:

committed by
Ilya Grigorik

parent
04eaa51cda
commit
e6835f39ff
@@ -1,3 +1,4 @@
|
||||
.vsc-nosource { display: none !important; }
|
||||
.vsc-hidden { display: none !important; }
|
||||
.vsc-manual {
|
||||
visibility: visible !important;
|
||||
|
26
inject.js
26
inject.js
@@ -123,6 +123,9 @@
|
||||
} else {
|
||||
tc.settings.speeds[target.src] = tc.settings.lastSpeed;
|
||||
}
|
||||
|
||||
target.playbackRate = tc.settings.speeds[target.src];
|
||||
|
||||
this.div=this.initializeControls();
|
||||
|
||||
target.addEventListener('play', this.handlePlay = function(event) {
|
||||
@@ -152,7 +155,24 @@
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
target.playbackRate = tc.settings.speeds[target.src];
|
||||
var observer=new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'attributes' && mutation.attributeName === 'src'){
|
||||
var controller = document.querySelector(`div[data-vscid="${this.id}"]`);
|
||||
if(!controller){
|
||||
return;
|
||||
}
|
||||
if (!mutation.target.src) {
|
||||
controller.classList.add('vsc-nosource');
|
||||
} else {
|
||||
controller.classList.remove('vsc-nosource');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(target, {
|
||||
attributeFilter: ["src"]
|
||||
});
|
||||
};
|
||||
|
||||
tc.videoController.prototype.getSpeed = function() {
|
||||
@@ -177,6 +197,10 @@
|
||||
wrapper.classList.add('vsc-controller');
|
||||
wrapper.dataset['vscid'] = this.id;
|
||||
|
||||
if (!this.video.src) {
|
||||
wrapper.classList.add('vsc-nosource');
|
||||
}
|
||||
|
||||
if (tc.settings.startHidden) {
|
||||
wrapper.classList.add('vsc-hidden');
|
||||
}
|
||||
|
Reference in New Issue
Block a user