mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 10:11:46 +00:00
[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 { ipcRenderer } = require("electron");
|
||||
|
||||
const config = require("./config");
|
||||
|
||||
function $(selector) { return document.querySelector(selector); }
|
||||
|
||||
const captionsSettingsButton = ElementFromFile(
|
||||
templatePath(__dirname, "captions-settings-template.html")
|
||||
);
|
||||
|
||||
module.exports = (options) => {
|
||||
document.addEventListener('apiLoaded', (event) => setup(event, options), { once: true, passive: true });
|
||||
module.exports = () => {
|
||||
document.addEventListener('apiLoaded', (event) => setup(event.detail), { once: true, passive: true });
|
||||
}
|
||||
|
||||
function setup(event, options) {
|
||||
const api = event.detail;
|
||||
|
||||
function setup(api) {
|
||||
$(".right-controls-buttons").append(captionsSettingsButton);
|
||||
|
||||
let captionTrackList = api.getOption("captions", "tracklist");
|
||||
|
||||
$("video").addEventListener("srcChanged", () => {
|
||||
if (options.disableCaptions) {
|
||||
$("video").addEventListener("srcChanged", async () => {
|
||||
if (await config.get('disableCaptions')) {
|
||||
setTimeout(() => api.unloadModule("captions"), 100);
|
||||
captionsSettingsButton.style.display = "none";
|
||||
return;
|
||||
@ -27,9 +27,15 @@ function setup(event, options) {
|
||||
|
||||
api.loadModule("captions");
|
||||
|
||||
setTimeout(() => {
|
||||
setTimeout(async () => {
|
||||
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
|
||||
? "inline-block"
|
||||
: "none";
|
||||
@ -52,6 +58,7 @@ function setup(event, options) {
|
||||
if (currentIndex === null) return;
|
||||
|
||||
const newCaptions = captionTrackList[currentIndex];
|
||||
config.set('lastCaptionsCode', newCaptions?.languageCode);
|
||||
if (newCaptions) {
|
||||
api.setOption("captions", "track", { languageCode: newCaptions.languageCode });
|
||||
} 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",
|
||||
type: "checkbox",
|
||||
checked: options.disabledCaptions,
|
||||
checked: config.get("disabledCaptions"),
|
||||
click: (item) => {
|
||||
setOptions("captions-selector", { disableCaptions: item.checked });
|
||||
config.set('disableCaptions', item.checked);
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user