mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 18:41:47 +00:00
Merge pull request #1079 from Araxeus/option-to-load-captions-selector-on-every-song
[captions-selector] add `autoload` option
This commit is contained in:
3
plugins/captions-selector/config.js
Normal file
3
plugins/captions-selector/config.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const { PluginConfig } = require("../../config/dynamic");
|
||||||
|
const config = new PluginConfig("captions-selector", { enableFront: true });
|
||||||
|
module.exports = { ...config };
|
||||||
@ -1,25 +1,25 @@
|
|||||||
const { ElementFromFile, templatePath } = require("../utils");
|
const { ElementFromFile, templatePath } = require("../utils");
|
||||||
const { ipcRenderer } = require("electron");
|
const { ipcRenderer } = require("electron");
|
||||||
|
|
||||||
|
const config = require("./config");
|
||||||
|
|
||||||
function $(selector) { return document.querySelector(selector); }
|
function $(selector) { return document.querySelector(selector); }
|
||||||
|
|
||||||
const captionsSettingsButton = ElementFromFile(
|
const captionsSettingsButton = ElementFromFile(
|
||||||
templatePath(__dirname, "captions-settings-template.html")
|
templatePath(__dirname, "captions-settings-template.html")
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = (options) => {
|
module.exports = () => {
|
||||||
document.addEventListener('apiLoaded', (event) => setup(event, options), { once: true, passive: true });
|
document.addEventListener('apiLoaded', (event) => setup(event.detail), { once: true, passive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup(event, options) {
|
function setup(api) {
|
||||||
const api = event.detail;
|
|
||||||
|
|
||||||
$(".right-controls-buttons").append(captionsSettingsButton);
|
$(".right-controls-buttons").append(captionsSettingsButton);
|
||||||
|
|
||||||
let captionTrackList = api.getOption("captions", "tracklist");
|
let captionTrackList = api.getOption("captions", "tracklist");
|
||||||
|
|
||||||
$("video").addEventListener("srcChanged", () => {
|
$("video").addEventListener("srcChanged", async () => {
|
||||||
if (options.disableCaptions) {
|
if (await config.get('disableCaptions')) {
|
||||||
setTimeout(() => api.unloadModule("captions"), 100);
|
setTimeout(() => api.unloadModule("captions"), 100);
|
||||||
captionsSettingsButton.style.display = "none";
|
captionsSettingsButton.style.display = "none";
|
||||||
return;
|
return;
|
||||||
@ -27,9 +27,15 @@ function setup(event, options) {
|
|||||||
|
|
||||||
api.loadModule("captions");
|
api.loadModule("captions");
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(async () => {
|
||||||
captionTrackList = api.getOption("captions", "tracklist");
|
captionTrackList = api.getOption("captions", "tracklist");
|
||||||
|
|
||||||
|
if (await config.get("autoload") && await config.get("lastCaptionsCode")) {
|
||||||
|
api.setOption("captions", "track", {
|
||||||
|
languageCode: await config.get("lastCaptionsCode"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
captionsSettingsButton.style.display = captionTrackList?.length
|
captionsSettingsButton.style.display = captionTrackList?.length
|
||||||
? "inline-block"
|
? "inline-block"
|
||||||
: "none";
|
: "none";
|
||||||
@ -52,6 +58,7 @@ function setup(event, options) {
|
|||||||
if (currentIndex === null) return;
|
if (currentIndex === null) return;
|
||||||
|
|
||||||
const newCaptions = captionTrackList[currentIndex];
|
const newCaptions = captionTrackList[currentIndex];
|
||||||
|
config.set('lastCaptionsCode', newCaptions?.languageCode);
|
||||||
if (newCaptions) {
|
if (newCaptions) {
|
||||||
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
|
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,12 +1,20 @@
|
|||||||
const { setOptions } = require('../../config/plugins');
|
const config = require("./config");
|
||||||
|
|
||||||
module.exports = (_win, options) => [
|
module.exports = () => [
|
||||||
|
{
|
||||||
|
label: "Automatically select last used caption",
|
||||||
|
type: "checkbox",
|
||||||
|
checked: config.get("autoload"),
|
||||||
|
click: (item) => {
|
||||||
|
config.set('autoload', item.checked);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "No captions by default",
|
label: "No captions by default",
|
||||||
type: "checkbox",
|
type: "checkbox",
|
||||||
checked: options.disabledCaptions,
|
checked: config.get("disabledCaptions"),
|
||||||
click: (item) => {
|
click: (item) => {
|
||||||
setOptions("captions-selector", { disableCaptions: item.checked });
|
config.set('disableCaptions', item.checked);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user