mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-12 02:51:46 +00:00
Plugin Captions Selector - Add disable captions by default
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
const { ipcMain, dialog } = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
ipcMain.handle('captionsSelector', async (_, captionLabels, currentIndex) => {
|
||||
return await dialog.showMessageBox({
|
||||
ipcMain.handle('captionsSelector', async (_, captionLabels, currentIndex) => {
|
||||
return await dialog.showMessageBox({
|
||||
type: "question",
|
||||
buttons: captionLabels,
|
||||
defaultId: currentIndex,
|
||||
|
||||
@ -1,30 +1,44 @@
|
||||
const { ElementFromFile, templatePath } = require("../utils");
|
||||
const { ipcRenderer } = require("electron");
|
||||
|
||||
function $(selector) { return document.querySelector(selector); }
|
||||
|
||||
const captionsSettingsButton = ElementFromFile(
|
||||
templatePath(__dirname, "captionsSettingsTemplate.html")
|
||||
);
|
||||
|
||||
module.exports = () => {
|
||||
document.addEventListener('apiLoaded', setup, { once: true, passive: true });
|
||||
module.exports = (options) => {
|
||||
document.addEventListener('apiLoaded', (event) => setup(event, options), { once: true, passive: true });
|
||||
}
|
||||
|
||||
function setup(event) {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
document.querySelector('.right-controls-buttons').append(captionsSettingsButton);
|
||||
$("video").addEventListener("srcChanged", () => videoChanged(api, options));
|
||||
|
||||
$(".right-controls-buttons").append(captionsSettingsButton);
|
||||
|
||||
captionsSettingsButton.onclick = function chooseQuality() {
|
||||
api.loadModule("captions");
|
||||
|
||||
const captionTrackList = api.getOption("captions", "tracklist");
|
||||
|
||||
if (captionTrackList?.length) {
|
||||
api.pauseVideo();
|
||||
|
||||
const currentCaptionTrack = api.getOption("captions", "track");
|
||||
const currentIndex = captionTrackList.indexOf(captionTrackList.find(track => track.languageCode === currentCaptionTrack.languageCode));
|
||||
|
||||
const captionLabels = [
|
||||
...captionTrackList.map(track => track.displayName),
|
||||
...captionTrackList.map(track => track.displayName),
|
||||
'None'
|
||||
];
|
||||
|
||||
|
||||
12
plugins/captions-selector/menu.js
Normal file
12
plugins/captions-selector/menu.js
Normal file
@ -0,0 +1,12 @@
|
||||
const { setOptions } = require('../../config/plugins');
|
||||
|
||||
module.exports = (_win, options) => [
|
||||
{
|
||||
label: "No captions by default",
|
||||
type: "checkbox",
|
||||
checked: options.disabledCaptions,
|
||||
click: (item) => {
|
||||
setOptions("captions-selector", { disableCaptions: item.checked });
|
||||
},
|
||||
}
|
||||
];
|
||||
Reference in New Issue
Block a user