Skip to content

Commit

Permalink
Add advance skip notice switch
Browse files Browse the repository at this point in the history
  • Loading branch information
etherfun committed Nov 23, 2024
1 parent b46212d commit b3cb1d9
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 22 deletions.
25 changes: 21 additions & 4 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,20 @@
"message": "要跳到 {0} 吗?",
"description": "Used for skipping to things (Skip to Highlight)"
},
"skipped": {
"autoSkipped": {
"message": "{0} 准备跳过",
"description": "Example: Ready Sponsor Skipped"
},
"autoMuted": {
"message": "{0} 准备静音",
"description": "Example: Ready Sponsor Muted"
},
"skipped": {
"message": "{0} 已跳过",
"description": "Example: Sponsor Skipped"
},
"muted": {
"message": "{0} 准备静音",
"message": "{0} 已静音",
"description": "Example: Sponsor Muted"
},
"skipped_to_category": {
Expand Down Expand Up @@ -468,11 +476,20 @@
"optionSectionExtensionRelated": {
"message": "插件相关选项"
},
"advanceSkipNotice": {
"message": "提前显示“空降提醒弹窗”"
},
"skipNoticeDurationBefore": {
"message": "“空降提醒弹窗”提前显示时间(秒):"
},
"skipNoticeDurationBeforeDescription": {
"message": "提前提醒您跳过片段的弹窗的提前时间。"
},
"skipNoticeDuration": {
"message": "“空降提醒弹窗”显示持续时间(秒):"
"message": "“空降提醒弹窗”跳过后或跳过提醒显示时间(秒):"
},
"skipNoticeDurationDescription": {
"message": "提醒您跳过片段的弹窗的显示时长。手动跳过片段的提醒弹窗可能会显示更久"
"message": "您跳过片段或者提醒您跳过片段的弹窗的显示时长。用于您对片段投票或跳过/取消跳过。\n手动跳过片段的提醒弹窗可能会显示更久"
},
"shortCheck": {
"message": "以下的提交短于您的最小持续时间选项。这代表它们可能已经被提交,只是由于该选项被忽略了。您确定要提交吗?"
Expand Down
25 changes: 21 additions & 4 deletions public/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,20 @@
"message": "要跳到 {0} 吗?",
"description": "Used for skipping to things (Skip to Highlight)"
},
"skipped": {
"autoSkipped": {
"message": "{0} 准备跳过",
"description": "Example: Ready Sponsor Skipped"
},
"autoMuted": {
"message": "{0} 准备静音",
"description": "Example: Ready Sponsor Muted"
},
"skipped": {
"message": "{0} 已跳过",
"description": "Example: Sponsor Skipped"
},
"muted": {
"message": "{0} 准备静音",
"message": "{0} 已静音",
"description": "Example: Sponsor Muted"
},
"skipped_to_category": {
Expand Down Expand Up @@ -468,11 +476,20 @@
"optionSectionExtensionRelated": {
"message": "插件相关选项"
},
"advanceSkipNotice": {
"message": "提前显示“空降提醒弹窗”"
},
"skipNoticeDurationBefore": {
"message": "“空降提醒弹窗”提前显示时间(秒):"
},
"skipNoticeDurationBeforeDescription": {
"message": "提前提醒您跳过片段的弹窗的提前时间。"
},
"skipNoticeDuration": {
"message": "“空降提醒弹窗”显示持续时间(秒):"
"message": "“空降提醒弹窗”跳过后或跳过提醒显示时间(秒):"
},
"skipNoticeDurationDescription": {
"message": "提醒您跳过片段的弹窗的显示时长。手动跳过片段的提醒弹窗可能会显示更久。(请注意: 设置过久可能会在某些片段密集区域堆叠大量弹窗!)"
"message": "您跳过片段或者提醒您跳过片段的弹窗的显示时长。用于您对片段投票或跳过/取消跳过。\n手动跳过片段的提醒弹窗可能会显示更久。"
},
"shortCheck": {
"message": "以下的提交短于您的最小持续时间选项。这代表它们可能已经被提交,只是由于该选项被忽略了。您确定要提交吗?"
Expand Down
25 changes: 21 additions & 4 deletions public/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,20 @@
"message": "要跳到 {0} 嗎?",
"description": "Used for skipping to things (Skip to Highlight)"
},
"skipped": {
"autoSkipped": {
"message": "{0} 準備跳過",
"description": "Example: Ready Sponsor Skipped"
},
"autoMuted": {
"message": "{0} 準備靜音",
"description": "Example: Ready Sponsor Muted"
},
"skipped": {
"message": "{0} 已跳過",
"description": "Example: Sponsor Skipped"
},
"muted": {
"message": "{0} 準備靜音",
"message": "{0} 已靜音",
"description": "Example: Sponsor Muted"
},
"skipped_to_category": {
Expand Down Expand Up @@ -468,11 +476,20 @@
"optionSectionExtensionRelated": {
"message": "插件相關選項"
},
"advanceSkipNotice": {
"message": "提前顯示跳過提醒視窗"
},
"skipNoticeDurationBefore": {
"message": "跳過提醒提前跳出視窗時間(秒):"
},
"skipNoticeDurationBeforeDescription": {
"message": "跳過提醒提前跳出視窗的提前時常。"
},
"skipNoticeDuration": {
"message": "跳過提醒跳出視窗持續時間(秒):"
"message": "跳過后或跳過提醒顯示時間(秒):"
},
"skipNoticeDurationDescription": {
"message": "跳過提醒跳出視窗的顯示時常。手動跳過的提醒可能會顯示更久。(請注意:設置過久可能會在某些片段密集區域堆疊大量彈窗!)"
"message": "您跳過片段或者跳過提醒跳出視窗的顯示時常。用於您對片段進行投票或者跳過/取消跳過。\n手動跳過的提醒可能會顯示更久。"
},
"shortCheck": {
"message": "以下的提交短於您的最小持續時間選項。這代表它們可能已經被提交,只是由於該選項被忽略了。您確定要提交嗎?"
Expand Down
25 changes: 24 additions & 1 deletion public/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,33 @@ <h3>__MSG_optionSectionSkipNotice__</h3>
<span class="optionLabel">__MSG_skipNoticeDuration__</span>
<input type="number" step="1" min="1">
</label>

<div class="small-description">__MSG_skipNoticeDurationDescription__</div>
</div>

<div data-type="toggle" data-toggle-type="switch" data-sync="advanceSkipNotice">
<div class="switch-container">
<label class="switch">
<input id="advanceSkipNotice" type="checkbox" checked>
<span class="slider round"></span>
</label>
<label class="switch-label" for="advanceSkipNotice">
__MSG_advanceSkipNotice__
</label>
</div>

<div data-type="number-change" data-sync="skipNoticeDurationBefore" data-dependent-on="advanceSkipNotice">
<br />

<label class="number-container">
<span class="optionLabel">__MSG_skipNoticeDurationBefore__</span>
<input type="number" step="1" min="1">
</label>

<div class="small-description">__MSG_skipNoticeDurationBeforeDescription__</div>
</div>
</div>

<div data-type="toggle" data-toggle-type="reverse" data-sync="dontShowNotice">
<div class="switch-container">
<label class="switch">
Expand Down
28 changes: 24 additions & 4 deletions src/components/SkipNoticeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
this.unselectedColor = Config.config.colorPalette.white;
this.lockedColor = Config.config.colorPalette.locked;

let countDown: number = 0;
if (Config.config.advanceSkipNotice) {
countDown = Number(Config.config.skipNoticeDurationBefore) + Number(Config.config.skipNoticeDuration);
} else {
countDown = Number(Config.config.skipNoticeDuration);
}
const isMuteSegment = this.segments[0].actionType === ActionType.Mute;
const maxCountdownTime = isMuteSegment
? this.getFullDurationCountdown(0)
: () => Config.config.skipNoticeDuration;
: () => countDown;

const defaultSkipButtonState = this.props.startReskip ? SkipButtonState.Redo : SkipButtonState.Undo;
const skipButtonStates = [
Expand Down Expand Up @@ -692,12 +698,26 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
const skipButtonCallbacks = this.state.skipButtonCallbacks;
skipButtonCallbacks[buttonIndex] = this.unskip.bind(this);

let countDown: number;
if (Config.config.advanceSkipNotice) {
if (this.props.segments[0].segment[0] > getVideo().currentTime) {
countDown = Number(Config.config.skipNoticeDurationBefore) + Number(Config.config.skipNoticeDuration);
} else {
if (Config.config.skipNoticeDuration < 1) {
countDown = Config.config.skipNoticeDurationBefore;
} else {
countDown = Config.config.skipNoticeDuration;
}
}
} else {
countDown = Config.config.skipNoticeDuration;
}
const newState: SkipNoticeState = {
skipButtonStates,
skipButtonCallbacks,

maxCountdownTime: () => Config.config.skipNoticeDuration,
countdownTime: Config.config.skipNoticeDuration,
maxCountdownTime: () => countDown,
countdownTime: countDown,
};

//reset countdown
Expand Down Expand Up @@ -754,7 +774,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
(sponsorTime.segment[1] - getVideo().currentTime) * (1 / getVideo().playbackRate)
);

return Math.max(duration, Config.config.skipNoticeDuration);
return Math.max(duration, Config.config.skipNoticeDurationBefore);
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ interface SBConfig {
serverAddress: string;
minDuration: number;
skipNoticeDuration: number;
skipNoticeDurationBefore: number;
advanceSkipNotice:boolean;
audioNotificationOnSkip: boolean;
checkForUnlistedVideos: boolean;
testingServer: boolean;
Expand Down Expand Up @@ -228,6 +230,8 @@ const syncDefaults = {
serverAddress: CompileConfig.serverAddress,
minDuration: 0,
skipNoticeDuration: 4,
skipNoticeDurationBefore: 4,
advanceSkipNotice:false,
audioNotificationOnSkip: false,
checkForUnlistedVideos: false,
testingServer: false,
Expand Down
18 changes: 15 additions & 3 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,12 @@ async function startSponsorSchedule(
logDebug(`Starting timeout to skip ${getVideo().currentTime} to skip at ${skipTime[0]}`);

const offset = isFirefoxOrSafari() && !isSafari() ? 600 : 150;
let advance: number = 0;
if(Config.config.advanceSkipNotice){
advance = Config.config.skipNoticeDurationBefore * 1000;
}
// Schedule for right before to be more precise than normal timeout
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - offset - Config.config.skipNoticeDuration * 1000));
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - offset - advance));
}
}
}
Expand Down Expand Up @@ -1858,7 +1862,11 @@ function skipToTime({ v, skipTime, skippingSegments, openNotice, forceAutoSkip,
//防止重复调用导致反复横跳
const Check = readySkip.readySkipCheck != skipTime[0];
readySkip.readySkipCheck = skipTime[0];
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + howLongToSkip(skipTime) >= skipTime[0])) return;
if (Config.config.advanceSkipNotice) {
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + howLongToSkip(skipTime) >= skipTime[0])) return;
} else {
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + 5 >= skipTime[0])) return;
}
clearTimeout(readySkip.readySkip);

const handleSkip = () => {
Expand Down Expand Up @@ -2068,7 +2076,11 @@ function reskipSponsorTime(segment: SponsorTime, forceSeek = false) {
}

function howLongToSkip(skipTime: number[]) {
return Math.min(Config.config.skipNoticeDuration * 1000 / getVideo().playbackRate, (skipTime[0] - getVideo().currentTime) * 1000 / getVideo().playbackRate)
if (Config.config.advanceSkipNotice) {
return Math.min(Config.config.skipNoticeDurationBefore * 1000 / getVideo().playbackRate, (skipTime[0] - getVideo().currentTime) * 1000 / getVideo().playbackRate);
} else {
return 0;
}
}

function shouldAutoSkip(segment: SponsorTime): boolean {
Expand Down
13 changes: 11 additions & 2 deletions src/utils/categoryUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActionType, Category, SponsorTime } from "../types";
import Config from "../config";

export function getSkippingText(segments: SponsorTime[], autoSkip: boolean): string {
const categoryName =
Expand All @@ -9,10 +10,18 @@ export function getSkippingText(segments: SponsorTime[], autoSkip: boolean): str
let messageId = "";
switch (segments[0].actionType) {
case ActionType.Skip:
messageId = "skipped";
if(Config.config.advanceSkipNotice){
messageId = "autoSkipped";
}else{
messageId = "skipped";
}
break;
case ActionType.Mute:
messageId = "muted";
if(Config.config.advanceSkipNotice){
messageId = "autoMuted";
}else{
messageId = "muted";
}
break;
case ActionType.Poi:
messageId = "skipped_to_category";
Expand Down

0 comments on commit b3cb1d9

Please sign in to comment.