feat: can set whether skip ads.

This commit is contained in:
Gabe
2025-10-30 00:31:17 +08:00
parent 172dce2867
commit 5322555eba
4 changed files with 32 additions and 7 deletions

View File

@@ -1648,6 +1648,11 @@ export const I18N = {
en: `Enable bilingual display`, en: `Enable bilingual display`,
zh_TW: `雙語顯示`, zh_TW: `雙語顯示`,
}, },
is_skip_ad: {
zh: `是否快进广告`,
en: `Should I fast forward to the ad?`,
zh_TW: `是否快轉廣告`,
},
background_styles: { background_styles: {
zh: `背景样式`, zh: `背景样式`,
en: `DBackground Style`, en: `DBackground Style`,

View File

@@ -114,6 +114,7 @@ export const DEFAULT_SUBTITLE_SETTING = {
// fromLang: "en", // fromLang: "en",
toLang: "zh-CN", toLang: "zh-CN",
isBilingual: true, // 是否双语显示 isBilingual: true, // 是否双语显示
skipAd: false, // 是否快进广告
windowStyle: SUBTITLE_WINDOW_STYLE, // 背景样式 windowStyle: SUBTITLE_WINDOW_STYLE, // 背景样式
originStyle: SUBTITLE_ORIGIN_STYLE, // 原文样式 originStyle: SUBTITLE_ORIGIN_STYLE, // 原文样式
translationStyle: SUBTITLE_TRANSLATION_STYLE, // 译文样式 translationStyle: SUBTITLE_TRANSLATION_STYLE, // 译文样式

View File

@@ -70,6 +70,8 @@ class YouTubeCaptionProvider {
} }
#moAds(adContainer) { #moAds(adContainer) {
const { skipAd = false } = this.#setting;
const adLayoutSelector = ".ytp-ad-player-overlay-layout"; const adLayoutSelector = ".ytp-ad-player-overlay-layout";
const skipBtnSelector = const skipBtnSelector =
".ytp-skip-ad-button, .ytp-ad-skip-button, .ytp-ad-skip-button-modern"; ".ytp-skip-ad-button, .ytp-ad-skip-button, .ytp-ad-skip-button-modern";
@@ -83,22 +85,24 @@ class YouTubeCaptionProvider {
if (node.matches(adLayoutSelector)) { if (node.matches(adLayoutSelector)) {
logger.debug("Youtube Provider: AD start playing!", node); logger.debug("Youtube Provider: AD start playing!", node);
// todo: 顺带把广告快速跳过 // todo: 顺带把广告快速跳过
if (videoEl) { if (videoEl && skipAd) {
videoEl.playbackRate = 16; videoEl.playbackRate = 16;
videoEl.currentTime = videoEl.duration; videoEl.currentTime = videoEl.duration;
} }
if (this.#managerInstance) { if (this.#managerInstance) {
this.#managerInstance.setIsAdPlaying(true); this.#managerInstance.setIsAdPlaying(true);
} }
} else if (node.matches(skipBtnSelector)) { } else if (node.matches(skipBtnSelector) && skipAd) {
logger.debug("Youtube Provider: AD skip button!", node); logger.debug("Youtube Provider: AD skip button!", node);
node.click(); node.click();
} }
const skipBtn = node?.querySelector(skipBtnSelector); if (skipAd) {
if (skipBtn) { const skipBtn = node?.querySelector(skipBtnSelector);
logger.debug("Youtube Provider: AD skip button!!", skipBtn); if (skipBtn) {
skipBtn.click(); logger.debug("Youtube Provider: AD skip button!!", skipBtn);
skipBtn.click();
}
} }
}); });
mutation.removedNodes.forEach((node) => { mutation.removedNodes.forEach((node) => {
@@ -106,7 +110,7 @@ class YouTubeCaptionProvider {
if (node.matches(adLayoutSelector)) { if (node.matches(adLayoutSelector)) {
logger.debug("Youtube Provider: Ad ends!"); logger.debug("Youtube Provider: Ad ends!");
if (videoEl) { if (videoEl && skipAd) {
videoEl.playbackRate = 1; videoEl.playbackRate = 1;
} }
if (this.#managerInstance) { if (this.#managerInstance) {

View File

@@ -32,6 +32,7 @@ export default function SubtitleSetting() {
chunkLength, chunkLength,
toLang, toLang,
isBilingual, isBilingual,
skipAd = false,
windowStyle, windowStyle,
originStyle, originStyle,
translationStyle, translationStyle,
@@ -145,6 +146,20 @@ export default function SubtitleSetting() {
<MenuItem value={false}>{i18n("disable")}</MenuItem> <MenuItem value={false}>{i18n("disable")}</MenuItem>
</TextField> </TextField>
</Grid> </Grid>
<Grid item xs={12} sm={12} md={6} lg={3}>
<TextField
fullWidth
select
size="small"
name="skipAd"
value={skipAd}
label={i18n("is_skip_ad")}
onChange={handleChange}
>
<MenuItem value={true}>{i18n("enable")}</MenuItem>
<MenuItem value={false}>{i18n("disable")}</MenuItem>
</TextField>
</Grid>
</Grid> </Grid>
</Box> </Box>