mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-05-13 03:16:21 +02:00
Fixed chapter skip notices not working + fixed typo
Fixed chapter skip notices not working + fixed typo Fixed chapter skip notices not working + fixed typo Fixed chapter skip notices not working + fixed typo A skip notice is now shown upon voting if one isn't already on screen minor fixes fixed commit error
This commit is contained in:
parent
66876283b4
commit
5a7e16b51c
6 changed files with 50 additions and 37 deletions
|
@ -1,12 +1,12 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as CompileConfig from "../../config.json";
|
import * as CompileConfig from "../../config.json";
|
||||||
import Config from "../config"
|
import Config from "../config"
|
||||||
import { Category, ContentContainer, SponsorTime, NoticeVisbilityMode, ActionType, SponsorSourceType, SegmentUUID } from "../types";
|
import { Category, ContentContainer, SponsorTime, NoticeVisibilityMode, ActionType, SponsorSourceType, SegmentUUID } from "../types";
|
||||||
import NoticeComponent from "./NoticeComponent";
|
import NoticeComponent from "./NoticeComponent";
|
||||||
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
import NoticeTextSelectionComponent from "./NoticeTextSectionComponent";
|
||||||
import Utils from "../utils";
|
import Utils from "../utils";
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
import { getSkippingText, getUpcomingText } from "../utils/categoryUtils";
|
import { getSkippingText, getUpcomingText, getVoteText } from "../utils/categoryUtils";
|
||||||
|
|
||||||
import ThumbsUpSvg from "../svg-icons/thumbs_up_svg";
|
import ThumbsUpSvg from "../svg-icons/thumbs_up_svg";
|
||||||
import ThumbsDownSvg from "../svg-icons/thumbs_down_svg";
|
import ThumbsDownSvg from "../svg-icons/thumbs_down_svg";
|
||||||
|
@ -29,6 +29,7 @@ export interface SkipNoticeProps {
|
||||||
autoSkip: boolean;
|
autoSkip: boolean;
|
||||||
startReskip?: boolean;
|
startReskip?: boolean;
|
||||||
upcomingNotice?: boolean;
|
upcomingNotice?: boolean;
|
||||||
|
voteNotice?: boolean;
|
||||||
// Contains functions and variables from the content script needed by the skip notice
|
// Contains functions and variables from the content script needed by the skip notice
|
||||||
contentContainer: ContentContainer;
|
contentContainer: ContentContainer;
|
||||||
|
|
||||||
|
@ -102,7 +103,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
this.autoSkip = props.autoSkip;
|
this.autoSkip = props.autoSkip;
|
||||||
this.contentContainer = props.contentContainer;
|
this.contentContainer = props.contentContainer;
|
||||||
|
|
||||||
const noticeTitle = !this.props.upcomingNotice ? getSkippingText(this.segments, this.props.autoSkip) : getUpcomingText(this.segments);
|
const noticeTitle = this.props.voteNotice ? getVoteText(this.segments) : !this.props.upcomingNotice ? getSkippingText(this.segments, this.props.autoSkip) : getUpcomingText(this.segments);
|
||||||
|
|
||||||
const previousSkipNotices = document.querySelectorAll(".sponsorSkipNoticeParent:not(.sponsorSkipUpcomingNotice)");
|
const previousSkipNotices = document.querySelectorAll(".sponsorSkipNoticeParent:not(.sponsorSkipUpcomingNotice)");
|
||||||
this.amountOfPreviousNotices = previousSkipNotices.length;
|
this.amountOfPreviousNotices = previousSkipNotices.length;
|
||||||
|
@ -186,8 +187,8 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
idSuffix={this.idSuffix}
|
idSuffix={this.idSuffix}
|
||||||
fadeIn={this.props.fadeIn}
|
fadeIn={this.props.fadeIn}
|
||||||
fadeOut={!this.props.upcomingNotice}
|
fadeOut={!this.props.upcomingNotice}
|
||||||
startFaded={Config.config.noticeVisibilityMode >= NoticeVisbilityMode.FadedForAll
|
startFaded={Config.config.noticeVisibilityMode >= NoticeVisibilityMode.FadedForAll
|
||||||
|| (Config.config.noticeVisibilityMode >= NoticeVisbilityMode.FadedForAutoSkip && this.autoSkip)}
|
|| (Config.config.noticeVisibilityMode >= NoticeVisibilityMode.FadedForAutoSkip && this.autoSkip)}
|
||||||
timed={true}
|
timed={true}
|
||||||
maxCountdownTime={this.state.maxCountdownTime}
|
maxCountdownTime={this.state.maxCountdownTime}
|
||||||
style={noticeStyle}
|
style={noticeStyle}
|
||||||
|
@ -278,7 +279,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
|
|
||||||
{/* Unskip/Skip Button */}
|
{/* Unskip/Skip Button */}
|
||||||
{!this.props.smaller || this.segments[0].actionType === ActionType.Mute
|
{!this.props.voteNotice && (!this.props.smaller || this.segments[0].actionType === ActionType.Mute)
|
||||||
? this.getSkipButton(1) : null}
|
? this.getSkipButton(1) : null}
|
||||||
|
|
||||||
{/* Never show button */}
|
{/* Never show button */}
|
||||||
|
@ -374,7 +375,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
style.minWidth = "100px";
|
style.minWidth = "100px";
|
||||||
}
|
}
|
||||||
|
|
||||||
const showSkipButton = (buttonIndex !== 0 || this.props.smaller || this.segments[0].actionType === ActionType.Mute) && !this.props.upcomingNotice;
|
const showSkipButton = (buttonIndex !== 0 || this.props.smaller || this.props.voteNotice || this.segments[0].actionType === ActionType.Mute) && !this.props.upcomingNotice;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="sponsorSkipNoticeUnskipSection" style={{ visibility: !showSkipButton ? "hidden" : null }}>
|
<span className="sponsorSkipNoticeUnskipSection" style={{ visibility: !showSkipButton ? "hidden" : null }}>
|
||||||
|
@ -624,9 +625,9 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
|
|
||||||
unskip(buttonIndex: number, index: number, forceSeek: boolean): void {
|
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.props.voteNotice);
|
||||||
|
|
||||||
this.unskippedMode(buttonIndex, index, SkipButtonState.Redo);
|
this.unskippedMode(buttonIndex, index, this.segments[0].actionType === ActionType.Poi ? SkipButtonState.Undo : SkipButtonState.Redo);
|
||||||
}
|
}
|
||||||
|
|
||||||
reskip(buttonIndex: number, index: number, forceSeek: boolean): void {
|
reskip(buttonIndex: number, index: number, forceSeek: boolean): void {
|
||||||
|
@ -664,7 +665,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
|
||||||
}
|
}
|
||||||
|
|
||||||
getUnskippedModeInfo(buttonIndex: number, index: number, skipButtonState: SkipButtonState): SkipNoticeState {
|
getUnskippedModeInfo(buttonIndex: number, index: number, skipButtonState: SkipButtonState): SkipNoticeState {
|
||||||
const changeCountdown = this.segments[index].actionType !== ActionType.Poi;
|
const changeCountdown = !this.props.voteNotice && this.segments[index].actionType !== ActionType.Poi;
|
||||||
|
|
||||||
const maxCountdownTime = changeCountdown ?
|
const maxCountdownTime = changeCountdown ?
|
||||||
this.getFullDurationCountdown(index) : this.state.maxCountdownTime;
|
this.getFullDurationCountdown(index) : this.state.maxCountdownTime;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as CompileConfig from "../config.json";
|
import * as CompileConfig from "../config.json";
|
||||||
import * as invidiousList from "../ci/invidiouslist.json";
|
import * as invidiousList from "../ci/invidiouslist.json";
|
||||||
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, VideoID, SponsorHideType } from "./types";
|
import { Category, CategorySelection, CategorySkipOption, NoticeVisibilityMode, PreviewBarOption, SponsorTime, VideoID, SponsorHideType } from "./types";
|
||||||
import { Keybind, ProtoConfig, keybindEquals } from "../maze-utils/src/config";
|
import { Keybind, ProtoConfig, keybindEquals } from "../maze-utils/src/config";
|
||||||
import { HashedValue } from "../maze-utils/src/hash";
|
import { HashedValue } from "../maze-utils/src/hash";
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ interface SBConfig {
|
||||||
trackDownvotesInPrivate: boolean;
|
trackDownvotesInPrivate: boolean;
|
||||||
dontShowNotice: boolean;
|
dontShowNotice: boolean;
|
||||||
showUpcomingNotice: boolean;
|
showUpcomingNotice: boolean;
|
||||||
noticeVisibilityMode: NoticeVisbilityMode;
|
noticeVisibilityMode: NoticeVisibilityMode;
|
||||||
hideVideoPlayerControls: boolean;
|
hideVideoPlayerControls: boolean;
|
||||||
hideInfoButtonPlayerControls: boolean;
|
hideInfoButtonPlayerControls: boolean;
|
||||||
hideDeleteButtonPlayerControls: boolean;
|
hideDeleteButtonPlayerControls: boolean;
|
||||||
|
@ -297,7 +297,7 @@ const syncDefaults = {
|
||||||
trackDownvotesInPrivate: false,
|
trackDownvotesInPrivate: false,
|
||||||
dontShowNotice: false,
|
dontShowNotice: false,
|
||||||
showUpcomingNotice: false,
|
showUpcomingNotice: false,
|
||||||
noticeVisibilityMode: NoticeVisbilityMode.FadedForAutoSkip,
|
noticeVisibilityMode: NoticeVisibilityMode.FadedForAutoSkip,
|
||||||
hideVideoPlayerControls: false,
|
hideVideoPlayerControls: false,
|
||||||
hideInfoButtonPlayerControls: false,
|
hideInfoButtonPlayerControls: false,
|
||||||
hideDeleteButtonPlayerControls: false,
|
hideDeleteButtonPlayerControls: false,
|
||||||
|
@ -470,7 +470,11 @@ const syncDefaults = {
|
||||||
"preview-filler": {
|
"preview-filler": {
|
||||||
color: "#2E0066",
|
color: "#2E0066",
|
||||||
opacity: "0.7"
|
opacity: "0.7"
|
||||||
}
|
},
|
||||||
|
"chapter": {
|
||||||
|
color: "#fff",
|
||||||
|
opacity: "0"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1778,7 +1778,7 @@ function skipToTime({v, skipTime, skippingSegments, openNotice, forceAutoSkip, u
|
||||||
if (autoSkip || isSubmittingSegment) sendTelemetryAndCount(skippingSegments, skipTime[1] - skipTime[0], true);
|
if (autoSkip || isSubmittingSegment) sendTelemetryAndCount(skippingSegments, skipTime[1] - skipTime[0], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSkipNotice(skippingSegments: SponsorTime[], autoSkip: boolean, unskipTime: number, startReskip: boolean) {
|
function createSkipNotice(skippingSegments: SponsorTime[], autoSkip: boolean, unskipTime: number, startReskip: boolean, voteNotice = false) {
|
||||||
for (const skipNotice of skipNotices) {
|
for (const skipNotice of skipNotices) {
|
||||||
if (skippingSegments.length === skipNotice.segments.length
|
if (skippingSegments.length === skipNotice.segments.length
|
||||||
&& skippingSegments.every((segment) => skipNotice.segments.some((s) => s.UUID === segment.UUID))) {
|
&& skippingSegments.every((segment) => skipNotice.segments.some((s) => s.UUID === segment.UUID))) {
|
||||||
|
@ -1792,7 +1792,7 @@ function createSkipNotice(skippingSegments: SponsorTime[], autoSkip: boolean, un
|
||||||
const newSkipNotice = new SkipNotice(skippingSegments, autoSkip, skipNoticeContentContainer, () => {
|
const newSkipNotice = new SkipNotice(skippingSegments, autoSkip, skipNoticeContentContainer, () => {
|
||||||
upcomingNotice?.close();
|
upcomingNotice?.close();
|
||||||
upcomingNotice = null;
|
upcomingNotice = null;
|
||||||
}, unskipTime, startReskip, upcomingNoticeShown);
|
}, unskipTime, startReskip, upcomingNoticeShown, voteNotice);
|
||||||
if (isOnMobileYouTube() || Config.config.skipKeybind == null) newSkipNotice.setShowKeybindHint(false);
|
if (isOnMobileYouTube() || Config.config.skipKeybind == null) newSkipNotice.setShowKeybindHint(false);
|
||||||
skipNotices.push(newSkipNotice);
|
skipNotices.push(newSkipNotice);
|
||||||
|
|
||||||
|
@ -1811,13 +1811,13 @@ function createUpcomingNotice(skippingSegments: SponsorTime[], timeLeft: number,
|
||||||
upcomingNotice = new UpcomingNotice(skippingSegments, skipNoticeContentContainer, timeLeft / 1000, autoSkip);
|
upcomingNotice = new UpcomingNotice(skippingSegments, skipNoticeContentContainer, timeLeft / 1000, autoSkip);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null, forceSeek = false) {
|
function unskipSponsorTime(segment: SponsorTime, unskipTime: number = null, forceSeek = false, voteNotice = false) {
|
||||||
if (segment.actionType === ActionType.Mute) {
|
if (segment.actionType === ActionType.Mute) {
|
||||||
getVideo().muted = false;
|
getVideo().muted = false;
|
||||||
videoMuted = false;
|
videoMuted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forceSeek || segment.actionType === ActionType.Skip) {
|
if (forceSeek || segment.actionType === ActionType.Skip || voteNotice) {
|
||||||
//add a tiny bit of time to make sure it is not skipped again
|
//add a tiny bit of time to make sure it is not skipped again
|
||||||
setCurrentTime(unskipTime ?? segment.segment[0] + 0.001);
|
setCurrentTime(unskipTime ?? segment.segment[0] + 0.001);
|
||||||
}
|
}
|
||||||
|
@ -2533,20 +2533,20 @@ function previousChapter(): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleKeybindVote(type: number): Promise<void>{
|
async function handleKeybindVote(type: number): Promise<void>{
|
||||||
let lastSkipNotice = skipNotices[0]?.skipNoticeRef.current;
|
let lastSkipNotice = skipNotices[0]?.skipNoticeRef.current;
|
||||||
|
lastSkipNotice?.onMouseEnter();
|
||||||
|
|
||||||
if (!lastSkipNotice) {
|
if (!lastSkipNotice) {
|
||||||
const lastSegment = [...sponsorTimes].reverse()?.find((s) => s.source == SponsorSourceType.Server && s.actionType != 'chapter' && (s.segment[0] <= getCurrentTime() && getCurrentTime() - (s.segment[1] || s.segment[0]) <= Config.config.skipNoticeDuration));
|
const lastSegment = [...sponsorTimes].reverse()?.find((s) => s.source == SponsorSourceType.Server && (s.segment[0] <= getCurrentTime() && getCurrentTime() - (s.segment[1] || s.segment[0]) <= Config.config.skipNoticeDuration));
|
||||||
if (!lastSegment) return;
|
if (!lastSegment) return;
|
||||||
|
|
||||||
createSkipNotice([lastSegment], shouldAutoSkip(lastSegment), lastSegment?.segment[0], false);
|
createSkipNotice([lastSegment], shouldAutoSkip(lastSegment), lastSegment?.segment[0] + 0.001,false, true);
|
||||||
lastSkipNotice = await skipNotices[0]?.waitForSkipNoticeRef();
|
lastSkipNotice = await skipNotices[0].waitForSkipNoticeRef();
|
||||||
lastSkipNotice?.reskippedMode(0);
|
lastSkipNotice?.reskippedMode(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSkipNotice?.onMouseEnter();
|
vote(type,lastSkipNotice?.segments[0]?.UUID, undefined, lastSkipNotice);
|
||||||
vote(type,lastSkipNotice?.segments[0]?.UUID, undefined, lastSkipNotice);
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addHotkeyListener(): void {
|
function addHotkeyListener(): void {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Utils from "../utils";
|
||||||
const utils = new Utils();
|
const utils = new Utils();
|
||||||
|
|
||||||
import SkipNoticeComponent from "../components/SkipNoticeComponent";
|
import SkipNoticeComponent from "../components/SkipNoticeComponent";
|
||||||
import { SponsorTime, ContentContainer, NoticeVisbilityMode } from "../types";
|
import { SponsorTime, ContentContainer, NoticeVisibilityMode } from "../types";
|
||||||
import Config from "../config";
|
import Config from "../config";
|
||||||
import { SkipNoticeAction } from "../utils/noticeUtils";
|
import { SkipNoticeAction } from "../utils/noticeUtils";
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class SkipNotice {
|
||||||
skipNoticeRef: React.MutableRefObject<SkipNoticeComponent>;
|
skipNoticeRef: React.MutableRefObject<SkipNoticeComponent>;
|
||||||
root: Root;
|
root: Root;
|
||||||
|
|
||||||
constructor(segments: SponsorTime[], autoSkip = false, contentContainer: ContentContainer, componentDidMount: () => void, unskipTime: number = null, startReskip = false, upcomingNoticeShown: boolean) {
|
constructor(segments: SponsorTime[], autoSkip = false, contentContainer: ContentContainer, componentDidMount: () => void, unskipTime: number = null, startReskip = false, upcomingNoticeShown: boolean, voteNotice = false) {
|
||||||
this.skipNoticeRef = React.createRef();
|
this.skipNoticeRef = React.createRef();
|
||||||
|
|
||||||
this.segments = segments;
|
this.segments = segments;
|
||||||
|
@ -42,18 +42,18 @@ class SkipNotice {
|
||||||
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
this.noticeElement.id = "sponsorSkipNoticeContainer" + idSuffix;
|
||||||
|
|
||||||
referenceNode.prepend(this.noticeElement);
|
referenceNode.prepend(this.noticeElement);
|
||||||
|
|
||||||
this.root = createRoot(this.noticeElement);
|
this.root = createRoot(this.noticeElement);
|
||||||
this.root.render(
|
this.root.render(
|
||||||
<SkipNoticeComponent segments={segments}
|
<SkipNoticeComponent segments={segments}
|
||||||
autoSkip={autoSkip}
|
autoSkip={autoSkip}
|
||||||
startReskip={startReskip}
|
startReskip={startReskip}
|
||||||
|
voteNotice={voteNotice}
|
||||||
contentContainer={contentContainer}
|
contentContainer={contentContainer}
|
||||||
ref={this.skipNoticeRef}
|
ref={this.skipNoticeRef}
|
||||||
closeListener={() => this.close()}
|
closeListener={() => this.close()}
|
||||||
smaller={Config.config.noticeVisibilityMode >= NoticeVisbilityMode.MiniForAll
|
smaller={!voteNotice && (Config.config.noticeVisibilityMode >= NoticeVisibilityMode.MiniForAll
|
||||||
|| (Config.config.noticeVisibilityMode >= NoticeVisbilityMode.MiniForAutoSkip && autoSkip)}
|
|| (Config.config.noticeVisibilityMode >= NoticeVisibilityMode.MiniForAutoSkip && autoSkip))}
|
||||||
fadeIn={!upcomingNoticeShown}
|
fadeIn={!upcomingNoticeShown && !voteNotice}
|
||||||
unskipTime={unskipTime}
|
unskipTime={unskipTime}
|
||||||
componentDidMount={componentDidMount} />
|
componentDidMount={componentDidMount} />
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,7 @@ export interface ContentContainer {
|
||||||
(): {
|
(): {
|
||||||
vote: (type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent) => void;
|
vote: (type: number, UUID: SegmentUUID, category?: Category, skipNotice?: SkipNoticeComponent) => void;
|
||||||
dontShowNoticeAgain: () => void;
|
dontShowNoticeAgain: () => void;
|
||||||
unskipSponsorTime: (segment: SponsorTime, unskipTime: number, forceSeek?: boolean) => void;
|
unskipSponsorTime: (segment: SponsorTime, unskipTime: number, forceSeek?: boolean, voteNotice?: boolean) => void;
|
||||||
sponsorTimes: SponsorTime[];
|
sponsorTimes: SponsorTime[];
|
||||||
sponsorTimesSubmitting: SponsorTime[];
|
sponsorTimesSubmitting: SponsorTime[];
|
||||||
skipNotices: SkipNotice[];
|
skipNotices: SkipNotice[];
|
||||||
|
@ -219,7 +219,7 @@ export interface ToggleSkippable {
|
||||||
setShowKeybindHint: (show: boolean) => void;
|
setShowKeybindHint: (show: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum NoticeVisbilityMode {
|
export enum NoticeVisibilityMode {
|
||||||
FullSize = 0,
|
FullSize = 0,
|
||||||
MiniForAutoSkip = 1,
|
MiniForAutoSkip = 1,
|
||||||
MiniForAll = 2,
|
MiniForAll = 2,
|
||||||
|
|
|
@ -44,6 +44,14 @@ export function getUpcomingText(segments: SponsorTime[]): string {
|
||||||
return chrome.i18n.getMessage(messageId).replace("{0}", categoryName);
|
return chrome.i18n.getMessage(messageId).replace("{0}", categoryName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getVoteText(segments: SponsorTime[]): string {
|
||||||
|
const categoryName = chrome.i18n.getMessage(segments.length > 1 ? "multipleSegments"
|
||||||
|
: "category_" + segments[0].category + "_short") || chrome.i18n.getMessage("category_" + segments[0].category);
|
||||||
|
|
||||||
|
const messageId = "voted_on";
|
||||||
|
return chrome.i18n.getMessage(messageId).replace("{0}", categoryName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function getCategorySuffix(category: Category): string {
|
export function getCategorySuffix(category: Category): string {
|
||||||
if (category.startsWith("poi_")) {
|
if (category.startsWith("poi_")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue