fix: subtitle
This commit is contained in:
@@ -45,15 +45,18 @@ class YouTubeCaptionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document.body.addEventListener("yt-navigate-finish", () => {
|
window.addEventListener("yt-navigate-finish", () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.#toggleButton) {
|
if (this.#toggleButton) {
|
||||||
this.#toggleButton.style.opacity = "0.5";
|
this.#toggleButton.style.opacity = "0.5";
|
||||||
}
|
}
|
||||||
|
this.#destroyManager();
|
||||||
this.#doubleClick();
|
this.#doubleClick();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
this.#waitForElement(CONTORLS_SELECT, () => this.#injectToggleButton());
|
this.#waitForElement(CONTORLS_SELECT, (ytControls) =>
|
||||||
|
this.#injectToggleButton(ytControls)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#waitForElement(selector, callback) {
|
#waitForElement(selector, callback) {
|
||||||
@@ -89,12 +92,8 @@ class YouTubeCaptionProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#injectToggleButton() {
|
#injectToggleButton(ytControls) {
|
||||||
this.#ytControls = document.querySelector(CONTORLS_SELECT);
|
this.#ytControls = ytControls;
|
||||||
if (!this.#ytControls) {
|
|
||||||
logger.warn("Youtube Provider: Could not find YouTube player controls.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const kissControls = document.createElement("div");
|
const kissControls = document.createElement("div");
|
||||||
kissControls.className = "kiss-bilingual-subtitle-controls";
|
kissControls.className = "kiss-bilingual-subtitle-controls";
|
||||||
@@ -392,8 +391,8 @@ class YouTubeCaptionProvider {
|
|||||||
this.#toggleButton.style.opacity = subtitles.length ? "1" : "0.5";
|
this.#toggleButton.style.opacity = subtitles.length ? "1" : "0.5";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#destroyManager();
|
||||||
if (this.#enabled) {
|
if (this.#enabled) {
|
||||||
this.#destroyManager();
|
|
||||||
this.#startManager();
|
this.#startManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,12 +402,6 @@ class YouTubeCaptionProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoEl = document.querySelector(VIDEO_SELECT);
|
|
||||||
if (!videoEl) {
|
|
||||||
logger.warn("Youtube Provider: No video element found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const videoId = this.#getVideoId();
|
const videoId = this.#getVideoId();
|
||||||
if (!this.#subtitles?.length || this.#videoId !== videoId) {
|
if (!this.#subtitles?.length || this.#videoId !== videoId) {
|
||||||
logger.info("Youtube Provider: No subtitles");
|
logger.info("Youtube Provider: No subtitles");
|
||||||
@@ -417,6 +410,12 @@ class YouTubeCaptionProvider {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const videoEl = document.querySelector(VIDEO_SELECT);
|
||||||
|
if (!videoEl) {
|
||||||
|
logger.warn("Youtube Provider: No video element found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Youtube Provider: Starting manager...");
|
logger.info("Youtube Provider: Starting manager...");
|
||||||
|
|
||||||
this.#managerInstance = new BilingualSubtitleManager({
|
this.#managerInstance = new BilingualSubtitleManager({
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { injectExternalJs } from "../libs/injector.js";
|
|||||||
import { logger } from "../libs/log.js";
|
import { logger } from "../libs/log.js";
|
||||||
|
|
||||||
const providers = [
|
const providers = [
|
||||||
{ pattern: "https://www.youtube.com/", start: YouTubeInitializer },
|
{ pattern: "https://www.youtube.com", start: YouTubeInitializer },
|
||||||
];
|
];
|
||||||
|
|
||||||
export function runSubtitle({ href, setting }) {
|
export function runSubtitle({ href, setting }) {
|
||||||
|
|||||||
Reference in New Issue
Block a user