mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-09 04:57:09 +03:00
New hash format for previewing segments
This commit is contained in:
@@ -2021,19 +2021,20 @@ function showTimeWithoutSkips(skippedDuration: number): void {
|
|||||||
function checkForPreloadedSegment() {
|
function checkForPreloadedSegment() {
|
||||||
const hashParams = getHashParams();
|
const hashParams = getHashParams();
|
||||||
|
|
||||||
const startTime = hashParams.sbStart as number;
|
const segments = hashParams.segments;
|
||||||
const endTime = hashParams.sbEnd as number;
|
if (Array.isArray(segments)) {
|
||||||
const category = hashParams.sbCategory as Category;
|
for (const segment of segments) {
|
||||||
const actionType = hashParams.sbActionType as ActionType;
|
if (Array.isArray(segment.segment)) {
|
||||||
if (startTime && endTime) {
|
if (!sponsorTimesSubmitting.some((s) => s.segment[0] === segment.segment[0] && s.segment[1] === s.segment[1])) {
|
||||||
if (!sponsorTimesSubmitting.some((segment) => segment.segment[0] === startTime && segment.segment[1] === endTime)) {
|
sponsorTimesSubmitting.push({
|
||||||
sponsorTimesSubmitting.push({
|
segment: segment.segment,
|
||||||
segment: [startTime, endTime],
|
UUID: utils.generateUserID() as SegmentUUID,
|
||||||
UUID: utils.generateUserID() as SegmentUUID,
|
category: segment.category ? segment.category : Config.config.defaultCategory,
|
||||||
category: category ? category : Config.config.defaultCategory,
|
actionType: segment.actionType ? segment.actionType : ActionType.Skip,
|
||||||
actionType: actionType ? actionType : ActionType.Skip,
|
source: SponsorSourceType.Local
|
||||||
source: SponsorSourceType.Local
|
});
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,13 @@ export function getHashParams(): Record<string, unknown> {
|
|||||||
if (windowHash) {
|
if (windowHash) {
|
||||||
const params: Record<string, unknown> = windowHash.split('&').reduce((acc, param) => {
|
const params: Record<string, unknown> = windowHash.split('&').reduce((acc, param) => {
|
||||||
const [key, value] = param.split('=');
|
const [key, value] = param.split('=');
|
||||||
acc[key] = value;
|
const decoded = decodeURIComponent(value);
|
||||||
|
try {
|
||||||
|
acc[key] = decoded?.match(/{|\[/) ? JSON.parse(decoded) : value;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to parse hash parameter ${key}: ${value}`);
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user