generated from JohnBra/vite-web-extension
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automatically disable closed captions #371
- Loading branch information
1 parent
81c25b2
commit 00a4870
Showing
10 changed files
with
124 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { YouTubePlayerDiv } from "@/src/types"; | ||
import { isWatchPage, waitForAllElements, waitForSpecificMessage } from "@/src/utils/utilities"; | ||
let captionsWhereEnabled = false; | ||
export async function enableAutomaticallyDisableClosedCaptions() { | ||
const { | ||
data: { | ||
options: { enable_automatically_disable_closed_captions } | ||
} | ||
} = await waitForSpecificMessage("options", "request_data", "content"); | ||
if (!enable_automatically_disable_closed_captions) return; | ||
await waitForAllElements(["div#player", "div#player-wide-container", "div#video-container", "div#player-container"]); | ||
// Get the player element | ||
const playerContainer = isWatchPage() ? document.querySelector<YouTubePlayerDiv>("div#movie_player") : null; | ||
const subtitlesButton = document.querySelector("button.ytp-subtitles-button"); | ||
// If player element is not available, return | ||
if (!playerContainer || !subtitlesButton) return; | ||
captionsWhereEnabled = subtitlesButton.getAttribute("aria-pressed") === "true"; | ||
// Disable captions | ||
playerContainer.unloadModule("captions"); | ||
} | ||
export async function disableAutomaticallyDisableClosedCaptions() { | ||
await waitForAllElements(["div#player", "div#player-wide-container", "div#video-container", "div#player-container"]); | ||
// Get the player element | ||
const playerContainer = isWatchPage() ? document.querySelector<YouTubePlayerDiv>("div#movie_player") : null; | ||
// If player element is not available, return | ||
if (!playerContainer) return; | ||
// If captions weren't enabled, return | ||
if (!captionsWhereEnabled) return; | ||
// Re-enable captions | ||
playerContainer.loadModule("captions"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters