mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
fix caption selector showing when unavailable
This commit is contained in:
@ -11,28 +11,32 @@ module.exports = (options) => {
|
||||
document.addEventListener('apiLoaded', (event) => setup(event, options), { once: true, passive: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* If captions are disabled by default,
|
||||
* unload "captions" module when video changes.
|
||||
*/
|
||||
const videoChanged = (api, options) => {
|
||||
if (options.disableCaptions) {
|
||||
setTimeout(() => api.unloadModule("captions"), 100);
|
||||
}
|
||||
}
|
||||
|
||||
function setup(event, options) {
|
||||
const api = event.detail;
|
||||
|
||||
$("video").addEventListener("srcChanged", () => videoChanged(api, options));
|
||||
|
||||
$(".right-controls-buttons").append(captionsSettingsButton);
|
||||
|
||||
let captionTrackList = api.getOption("captions", "tracklist");
|
||||
|
||||
$("video").addEventListener("srcChanged", () => {
|
||||
if (options.disableCaptions) {
|
||||
setTimeout(() => api.unloadModule("captions"), 100);
|
||||
captionsSettingsButton.style.display = "none";
|
||||
return;
|
||||
}
|
||||
|
||||
api.loadModule("captions");
|
||||
|
||||
setTimeout(() => {
|
||||
captionTrackList = api.getOption("captions", "tracklist");
|
||||
|
||||
captionsSettingsButton.style.display = captionTrackList?.length
|
||||
? "inline-block"
|
||||
: "none";
|
||||
}, 250);
|
||||
});
|
||||
|
||||
captionsSettingsButton.onclick = async () => {
|
||||
api.loadModule("captions");
|
||||
|
||||
const captionTrackList = api.getOption("captions", "tracklist");
|
||||
|
||||
if (captionTrackList?.length) {
|
||||
const currentCaptionTrack = api.getOption("captions", "track");
|
||||
let currentIndex = !currentCaptionTrack ?
|
||||
|
||||
Reference in New Issue
Block a user