aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAjay <[email protected]>2022-01-14 19:34:54 -0500
committerAjay <[email protected]>2022-01-14 19:34:54 -0500
commitd50a69f1fd99f20a686e35b0cadcec02a62eec61 (patch)
tree1a8df83dcea1c1fa1afda886b1b977c54eac7337 /src
parent31014b78ac8b71c3384a40f42b6e35995b508dee (diff)
downloadSponsorBlock-d50a69f1fd99f20a686e35b0cadcec02a62eec61.tar.gz
SponsorBlock-d50a69f1fd99f20a686e35b0cadcec02a62eec61.zip
New hash format for previewing segments
Diffstat (limited to 'src')
-rw-r--r--src/content.ts27
-rw-r--r--src/utils/pageUtils.ts8
2 files changed, 21 insertions, 14 deletions
diff --git a/src/content.ts b/src/content.ts
index e7df90e7..81ba097b 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -2021,19 +2021,20 @@ function showTimeWithoutSkips(skippedDuration: number): void {
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
- });
+ const segments = hashParams.segments;
+ if (Array.isArray(segments)) {
+ for (const segment of segments) {
+ if (Array.isArray(segment.segment)) {
+ if (!sponsorTimesSubmitting.some((s) => s.segment[0] === segment.segment[0] && s.segment[1] === s.segment[1])) {
+ sponsorTimesSubmitting.push({
+ segment: segment.segment,
+ UUID: utils.generateUserID() as SegmentUUID,
+ category: segment.category ? segment.category : Config.config.defaultCategory,
+ actionType: segment.actionType ? segment.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 6db26e19..28ac37d8 100644
--- a/src/utils/pageUtils.ts
+++ b/src/utils/pageUtils.ts
@@ -47,7 +47,13 @@ export function getHashParams(): Record<string, unknown> {
if (windowHash) {
const params: Record<string, unknown> = windowHash.split('&').reduce((acc, param) => {
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;
}, {});