Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Dec 5, 2024
1 parent 493bd70 commit 565390a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
21 changes: 10 additions & 11 deletions src/components/SkipNoticeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ 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 && Config.config.skipNoticeDurationBefore > 0) {
countDown = Number(Config.config.skipNoticeDurationBefore) + Number(Config.config.skipNoticeDuration);
} else {
countDown = Number(Config.config.skipNoticeDuration);
}
const calculateCountDown = () => {
if (Config.config.advanceSkipNotice && Config.config.skipNoticeDurationBefore > 0) {
return Config.config.skipNoticeDurationBefore + Config.config.skipNoticeDuration;
} else {
return Config.config.skipNoticeDuration;
}
};
const isMuteSegment = this.segments[0].actionType === ActionType.Mute;
const maxCountdownTime = isMuteSegment
? this.getFullDurationCountdown(0)
: () => countDown;
const maxCountdownTime = isMuteSegment ? this.getFullDurationCountdown(0) : calculateCountDown;

const defaultSkipButtonState = this.props.startReskip ? SkipButtonState.Redo : SkipButtonState.Undo;
const skipButtonStates = [
Expand Down Expand Up @@ -684,7 +683,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
}

unskip(buttonIndex: number, index: number, forceSeek: boolean): void {
(this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime, forceSeek));
this.contentContainer().unskipSponsorTime(this.segments[index], this.props.unskipTime, forceSeek);

this.unskippedMode(buttonIndex, index, SkipButtonState.Redo);
}
Expand All @@ -701,7 +700,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
let countDown: number;
if (Config.config.advanceSkipNotice && Config.config.skipNoticeDurationBefore > 0) {
if (this.props.segments[0].segment[0] > getVideo().currentTime) {
countDown = Number(Config.config.skipNoticeDurationBefore) + Number(Config.config.skipNoticeDuration);
countDown = Config.config.skipNoticeDurationBefore + Config.config.skipNoticeDuration;
} else {
if (Config.config.skipNoticeDuration < 1) {
countDown = Config.config.skipNoticeDurationBefore;
Expand Down
35 changes: 21 additions & 14 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ async function startSponsorSchedule(
shouldSkip(currentSkip) ||
sponsorTimesSubmitting?.some((segment) => segment.segment === currentSkip.segment)
) {
if (forceVideoTime >= skipTime[0] - skipBuffer - Config.config.skipNoticeDuration * 1000 && forceVideoTime < skipTime[1]) {
if (
forceVideoTime >= skipTime[0] - skipBuffer - Config.config.skipNoticeDuration * 1000 &&
forceVideoTime < skipTime[1]
) {
skipToTime({
v: getVideo(),
skipTime,
Expand Down Expand Up @@ -1863,7 +1866,8 @@ function skipToTime({ v, skipTime, skippingSegments, openNotice, forceAutoSkip,
const Check = readySkip.readySkipCheck != skipTime[0];
readySkip.readySkipCheck = skipTime[0];
if (Config.config.advanceSkipNotice && Config.config.skipNoticeDurationBefore > 0) {
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + howLongToSkip(skipTime) >= skipTime[0])) return;
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + howLongToSkip(skipTime) >= skipTime[0]))
return;
} else {
if (!Check || !(getVideo().currentTime < 5 || getVideo().currentTime + 1 >= skipTime[0])) return;
}
Expand Down Expand Up @@ -1917,28 +1921,28 @@ function skipToTime({ v, skipTime, skippingSegments, openNotice, forceAutoSkip,
}
}
}
}
};

//防止在片段前暂停等
const cleanListeners = () => {
v.removeEventListener("seeked", handleSeeked);
v.removeEventListener("pause", handlePause);
v.removeEventListener("play", handlePlay);
}
};
const handlePause = () => {
clearTimeout(readySkip.readySkip);
}
};
const handlePlay = () => {
const text = document.querySelector('.sponsorSkipObject.sponsorSkipNoticeButton') as HTMLButtonElement;
if (text && text.textContent.slice(0, 4) === chrome.i18n.getMessage('unskip')) {
const text = document.querySelector(".sponsorSkipObject.sponsorSkipNoticeButton") as HTMLButtonElement;
if (text && text.textContent.slice(0, 4) === chrome.i18n.getMessage("unskip")) {
readySkip.readySkip = setTimeout(handleSkip, howLongToSkip(skipTime));
}
}
};
const handleSeeked = () => {
cleanListeners();
readySkip.readySkipCheck = null;
clearTimeout(readySkip.readySkip);
}
};
v.addEventListener("pause", handlePause);
v.addEventListener("play", handlePlay);
v.addEventListener("seeked", handleSeeked);
Expand Down Expand Up @@ -1991,7 +1995,7 @@ function createSkipNotice(
skippingSegments: SponsorTime[],
autoSkip: boolean,
unskipTime: number,
startReskip: boolean,
startReskip: boolean
) {
for (const skipNotice of skipNotices) {
if (
Expand All @@ -2008,7 +2012,7 @@ function createSkipNotice(
autoSkip,
skipNoticeContentContainer,
unskipTime,
startReskip,
startReskip
);
if (Config.config.skipKeybind == null) newSkipNotice.setShowKeybindHint(false);
skipNotices.push(newSkipNotice);
Expand All @@ -2030,7 +2034,7 @@ function unskipSponsorTime(segment: SponsorTime, unskipTime: number, forceSeek =
} else if (readySkip.readySkip) {
clearTimeout(readySkip.readySkip);
clearTimeout(readySkip.ManualSkipSetTimeOut);
} else if (readySkip.ManualSkipSetTimeOut){
} else if (readySkip.ManualSkipSetTimeOut) {
clearTimeout(readySkip.ManualSkipSetTimeOut);
} else {
//add a tiny bit of time to make sure it is not skipped again
Expand Down Expand Up @@ -2063,7 +2067,7 @@ function reskipSponsorTime(segment: SponsorTime, forceSeek = false) {
skippingSegments: [segment],
openNotice: skipInfo.openNotice,
});
} else {
} else {
const skippedTime = Math.max(segment.segment[1] - getVideo().currentTime, 0);
const segmentDuration = segment.segment[1] - segment.segment[0];
const fullSkip = skippedTime / segmentDuration > manualSkipPercentCount;
Expand All @@ -2077,7 +2081,10 @@ function reskipSponsorTime(segment: SponsorTime, forceSeek = false) {

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

0 comments on commit 565390a

Please sign in to comment.