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-hidden { display: none !important; }
|
||||||
.vsc-manual {
|
.vsc-manual {
|
||||||
visibility: visible !important;
|
visibility: visible !important;
|
||||||
|
28
inject.js
28
inject.js
@@ -123,7 +123,10 @@
|
|||||||
} else {
|
} else {
|
||||||
tc.settings.speeds[target.src] = tc.settings.lastSpeed;
|
tc.settings.speeds[target.src] = tc.settings.lastSpeed;
|
||||||
}
|
}
|
||||||
this.div = this.initializeControls();
|
|
||||||
|
target.playbackRate = tc.settings.speeds[target.src];
|
||||||
|
|
||||||
|
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) {
|
||||||
@@ -152,7 +155,24 @@
|
|||||||
}
|
}
|
||||||
}.bind(this));
|
}.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() {
|
tc.videoController.prototype.getSpeed = function() {
|
||||||
@@ -177,6 +197,10 @@
|
|||||||
wrapper.classList.add('vsc-controller');
|
wrapper.classList.add('vsc-controller');
|
||||||
wrapper.dataset['vscid'] = this.id;
|
wrapper.dataset['vscid'] = this.id;
|
||||||
|
|
||||||
|
if (!this.video.src) {
|
||||||
|
wrapper.classList.add('vsc-nosource');
|
||||||
|
}
|
||||||
|
|
||||||
if (tc.settings.startHidden) {
|
if (tc.settings.startHidden) {
|
||||||
wrapper.classList.add('vsc-hidden');
|
wrapper.classList.add('vsc-hidden');
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user