feat: can set whether skip ads.
This commit is contained in:
@@ -1648,6 +1648,11 @@ export const I18N = {
|
||||
en: `Enable bilingual display`,
|
||||
zh_TW: `雙語顯示`,
|
||||
},
|
||||
is_skip_ad: {
|
||||
zh: `是否快进广告`,
|
||||
en: `Should I fast forward to the ad?`,
|
||||
zh_TW: `是否快轉廣告`,
|
||||
},
|
||||
background_styles: {
|
||||
zh: `背景样式`,
|
||||
en: `DBackground Style`,
|
||||
|
||||
@@ -114,6 +114,7 @@ export const DEFAULT_SUBTITLE_SETTING = {
|
||||
// fromLang: "en",
|
||||
toLang: "zh-CN",
|
||||
isBilingual: true, // 是否双语显示
|
||||
skipAd: false, // 是否快进广告
|
||||
windowStyle: SUBTITLE_WINDOW_STYLE, // 背景样式
|
||||
originStyle: SUBTITLE_ORIGIN_STYLE, // 原文样式
|
||||
translationStyle: SUBTITLE_TRANSLATION_STYLE, // 译文样式
|
||||
|
||||
@@ -70,6 +70,8 @@ class YouTubeCaptionProvider {
|
||||
}
|
||||
|
||||
#moAds(adContainer) {
|
||||
const { skipAd = false } = this.#setting;
|
||||
|
||||
const adLayoutSelector = ".ytp-ad-player-overlay-layout";
|
||||
const skipBtnSelector =
|
||||
".ytp-skip-ad-button, .ytp-ad-skip-button, .ytp-ad-skip-button-modern";
|
||||
@@ -83,22 +85,24 @@ class YouTubeCaptionProvider {
|
||||
if (node.matches(adLayoutSelector)) {
|
||||
logger.debug("Youtube Provider: AD start playing!", node);
|
||||
// todo: 顺带把广告快速跳过
|
||||
if (videoEl) {
|
||||
if (videoEl && skipAd) {
|
||||
videoEl.playbackRate = 16;
|
||||
videoEl.currentTime = videoEl.duration;
|
||||
}
|
||||
if (this.#managerInstance) {
|
||||
this.#managerInstance.setIsAdPlaying(true);
|
||||
}
|
||||
} else if (node.matches(skipBtnSelector)) {
|
||||
} else if (node.matches(skipBtnSelector) && skipAd) {
|
||||
logger.debug("Youtube Provider: AD skip button!", node);
|
||||
node.click();
|
||||
}
|
||||
|
||||
const skipBtn = node?.querySelector(skipBtnSelector);
|
||||
if (skipBtn) {
|
||||
logger.debug("Youtube Provider: AD skip button!!", skipBtn);
|
||||
skipBtn.click();
|
||||
if (skipAd) {
|
||||
const skipBtn = node?.querySelector(skipBtnSelector);
|
||||
if (skipBtn) {
|
||||
logger.debug("Youtube Provider: AD skip button!!", skipBtn);
|
||||
skipBtn.click();
|
||||
}
|
||||
}
|
||||
});
|
||||
mutation.removedNodes.forEach((node) => {
|
||||
@@ -106,7 +110,7 @@ class YouTubeCaptionProvider {
|
||||
|
||||
if (node.matches(adLayoutSelector)) {
|
||||
logger.debug("Youtube Provider: Ad ends!");
|
||||
if (videoEl) {
|
||||
if (videoEl && skipAd) {
|
||||
videoEl.playbackRate = 1;
|
||||
}
|
||||
if (this.#managerInstance) {
|
||||
|
||||
@@ -32,6 +32,7 @@ export default function SubtitleSetting() {
|
||||
chunkLength,
|
||||
toLang,
|
||||
isBilingual,
|
||||
skipAd = false,
|
||||
windowStyle,
|
||||
originStyle,
|
||||
translationStyle,
|
||||
@@ -145,6 +146,20 @@ export default function SubtitleSetting() {
|
||||
<MenuItem value={false}>{i18n("disable")}</MenuItem>
|
||||
</TextField>
|
||||
</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>
|
||||
</Box>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user