mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 01:01:55 +01:00
Support older browsers
This commit is contained in:
parent
56bc3fca04
commit
4045978b54
2 changed files with 7 additions and 7 deletions
|
@ -11,13 +11,13 @@ export function urlTimeToSeconds(time: string): number {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const re = /(?:(?<hours>\d{1,3})h)?(?:(?<minutes>\d{1,2})m)?(?<seconds>\d+)s?/;
|
const re = /(?:(\d{1,3})h)?(?:(\d{1,2})m)?(\d+)s?/;
|
||||||
const match = re.exec(time);
|
const match = re.exec(time);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
const hours = parseInt(match.groups.hours ?? '0', 10);
|
const hours = parseInt(match[1] ?? '0', 10);
|
||||||
const minutes = parseInt(match.groups.minutes ?? '0', 10);
|
const minutes = parseInt(match[2] ?? '0', 10);
|
||||||
const seconds = parseInt(match.groups.seconds ?? '0', 10);
|
const seconds = parseInt(match[3] ?? '0', 10);
|
||||||
|
|
||||||
return hours * 3600 + minutes * 60 + seconds;
|
return hours * 3600 + minutes * 60 + seconds;
|
||||||
} else if (/\d+/.test(time)) {
|
} else if (/\d+/.test(time)) {
|
||||||
|
|
|
@ -5,15 +5,15 @@ describe("getStartTimeFromUrl", () => {
|
||||||
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123")).toBe(123);
|
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123")).toBe(123);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("parses with a seconds", () => {
|
it("parses with seconds", () => {
|
||||||
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123s")).toBe(123);
|
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123s")).toBe(123);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("parses with a minutes", () => {
|
it("parses with minutes", () => {
|
||||||
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=23m3s")).toBe(23 * 60 + 3);
|
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=23m3s")).toBe(23 * 60 + 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("parses with a hours", () => {
|
it("parses with hours", () => {
|
||||||
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1h2m3s")).toBe(1 * 60 * 60 + 2 * 60 + 3);
|
expect(getStartTimeFromUrl("https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1h2m3s")).toBe(1 * 60 * 60 + 2 * 60 + 3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue