Add method to create segments from url parameters

This commit is contained in:
Ajay
2022-01-14 19:21:09 -05:00
parent cf9e016581
commit 31014b78ac
2 changed files with 40 additions and 11 deletions

View File

@@ -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<string, unknown> = {};
const windowHash = window.location.hash.substr(1);
if (windowHash) {
const params: Record<string, unknown> = 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
});
}
}
}

View File

@@ -40,4 +40,19 @@ function findValidElementFromGenerator<T>(objects: T[] | NodeListOf<HTMLElement>
}
return null;
}
export function getHashParams(): Record<string, unknown> {
const windowHash = window.location.hash.substr(1);
if (windowHash) {
const params: Record<string, unknown> = windowHash.split('&').reduce((acc, param) => {
const [key, value] = param.split('=');
acc[key] = value;
return acc;
}, {});
return params;
}
return {};
}