mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
Merge pull request #1063 from Araxeus/fix-caption-selector-showing-when-unavailable
[captions-selector] fix button showing when there aren't any captions available
This commit is contained in:
@ -116,7 +116,7 @@
|
||||
"butterchurn": "^2.6.7",
|
||||
"butterchurn-presets": "^2.4.7",
|
||||
"chokidar": "^3.5.3",
|
||||
"custom-electron-prompt": "^1.5.1",
|
||||
"custom-electron-prompt": "^1.5.4",
|
||||
"custom-electron-titlebar": "^4.1.6",
|
||||
"electron-better-web-request": "^1.0.1",
|
||||
"electron-debug": "^3.2.0",
|
||||
|
||||
@ -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 ?
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@ -2425,12 +2425,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"custom-electron-prompt@npm:^1.5.1":
|
||||
version: 1.5.1
|
||||
resolution: "custom-electron-prompt@npm:1.5.1"
|
||||
"custom-electron-prompt@npm:^1.5.4":
|
||||
version: 1.5.4
|
||||
resolution: "custom-electron-prompt@npm:1.5.4"
|
||||
peerDependencies:
|
||||
electron: ">=10.0.0"
|
||||
checksum: 43a0d72a7a3471135822cb210d580285f70080d9d3a7b03f82cd4be403059fe20ea05ebdd1f9534928c386ab25a353e678f2cfb3f4ca016b41f3366bff700767
|
||||
checksum: 93995b5f0e9d14401a8c4fdd358af32d8b7585b59b111667cfa55f9505109c08914f3140953125b854e5d09e811de8c76c7fec718934c13e8a1ad09fe1b85270
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
@ -8981,7 +8981,7 @@ __metadata:
|
||||
butterchurn: ^2.6.7
|
||||
butterchurn-presets: ^2.4.7
|
||||
chokidar: ^3.5.3
|
||||
custom-electron-prompt: ^1.5.1
|
||||
custom-electron-prompt: ^1.5.4
|
||||
custom-electron-titlebar: ^4.1.6
|
||||
del-cli: ^5.0.0
|
||||
electron: ^22.0.2
|
||||
|
||||
Reference in New Issue
Block a user