Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[captions-selector] fix button showing when there aren't any captions available #1063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 19 additions & 15 deletions plugins/captions-selector/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

captionsSettingsButton.onclick = async () => {
api.loadModule("captions");
let captionTrackList = api.getOption("captions", "tracklist");

const 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 () => {
if (captionTrackList?.length) {
const currentCaptionTrack = api.getOption("captions", "track");
let currentIndex = !currentCaptionTrack ?
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down