diff --git a/src/content.ts b/src/content.ts index 71a38dd1..e7df90e7 100644 --- a/src/content.ts +++ b/src/content.ts @@ -17,7 +17,7 @@ import { getCategoryActionType } from "./utils/categoryUtils"; import { SkipButtonControlBar } from "./js-components/skipButtonControlBar"; import { Tooltip } from "./render/Tooltip"; import { getStartTimeFromUrl } from "./utils/urlParser"; -import { findValidElement, getControls, isVisible } from "./utils/pageUtils"; +import { findValidElement, getControls, getHashParams, isVisible } from "./utils/pageUtils"; import { CategoryPill } from "./render/CategoryPill"; import { AnimationUtils } from "./utils/animationUtils"; import { GenericUtils } from "./utils/genericUtils"; @@ -692,16 +692,8 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) { } const extraRequestData: Record = {}; - const windowHash = window.location.hash.substr(1); - if (windowHash) { - const params: Record = windowHash.split('&').reduce((acc, param) => { - const [key, value] = param.split('='); - acc[key] = value; - return acc; - }, {}); - - if (params.requiredSegment) extraRequestData.requiredSegment = params.requiredSegment; - } + const hashParams = getHashParams(); + if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment; // Check for hashPrefix setting const hashPrefix = (await utils.getHash(id, 1)).substr(0, 4); @@ -1582,6 +1574,8 @@ function updateSponsorTimesSubmitting(getFromConfig = true) { if (submissionNotice !== null) { submissionNotice.update(); } + + checkForPreloadedSegment(); } function openInfoMenu() { @@ -2023,3 +2017,23 @@ function showTimeWithoutSkips(skippedDuration: number): void { duration.innerText = (durationAfterSkips == null || skippedDuration <= 0) ? "" : " (" + durationAfterSkips + ")"; } + +function checkForPreloadedSegment() { + const hashParams = getHashParams(); + + const startTime = hashParams.sbStart as number; + const endTime = hashParams.sbEnd as number; + const category = hashParams.sbCategory as Category; + const actionType = hashParams.sbActionType as ActionType; + if (startTime && endTime) { + if (!sponsorTimesSubmitting.some((segment) => segment.segment[0] === startTime && segment.segment[1] === endTime)) { + sponsorTimesSubmitting.push({ + segment: [startTime, endTime], + UUID: utils.generateUserID() as SegmentUUID, + category: category ? category : Config.config.defaultCategory, + actionType: actionType ? actionType : ActionType.Skip, + source: SponsorSourceType.Local + }); + } + } +} \ No newline at end of file diff --git a/src/utils/pageUtils.ts b/src/utils/pageUtils.ts index d31ead47..6db26e19 100644 --- a/src/utils/pageUtils.ts +++ b/src/utils/pageUtils.ts @@ -40,4 +40,19 @@ function findValidElementFromGenerator(objects: T[] | NodeListOf } return null; +} + +export function getHashParams(): Record { + const windowHash = window.location.hash.substr(1); + if (windowHash) { + const params: Record = windowHash.split('&').reduce((acc, param) => { + const [key, value] = param.split('='); + acc[key] = value; + return acc; + }, {}); + + return params; + } + + return {}; } \ No newline at end of file