mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Remove lookbehind because safari
Resolves https://github.com/ajayyy/SponsorBlock/issues/1626
This commit is contained in:
@@ -41,11 +41,16 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
|
|||||||
const startTime = getFormattedTimeToSeconds(match[0]);
|
const startTime = getFormattedTimeToSeconds(match[0]);
|
||||||
if (startTime !== null) {
|
if (startTime !== null) {
|
||||||
// Remove "seconds", "at", special characters, and ")" if there was a "("
|
// Remove "seconds", "at", special characters, and ")" if there was a "("
|
||||||
const specialCharsMatcher = /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:(\s]+$|(?<=^\s*\(.+)[-:()\s]*$/g
|
const specialCharMatchers = [{
|
||||||
const titleLeft = line.split(match[0])[0].replace(specialCharsMatcher, "");
|
matcher: /^(?:\s+seconds?)?[-:()\s]*|(?:\s+at)?[-:(\s]+$/g
|
||||||
|
}, {
|
||||||
|
matcher: /[-:()\s]*$/g,
|
||||||
|
condition: (value) => !!value.match(/^\s*\(/)
|
||||||
|
}];
|
||||||
|
const titleLeft = removeIf(line.split(match[0])[0], specialCharMatchers);
|
||||||
let titleRight = null;
|
let titleRight = null;
|
||||||
const split2 = line.split(match[1] || match[0]);
|
const split2 = line.split(match[1] || match[0]);
|
||||||
titleRight = split2[split2.length - 1].replace(specialCharsMatcher, "");
|
titleRight = removeIf(split2[split2.length - 1], specialCharMatchers)
|
||||||
|
|
||||||
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
|
const title = titleLeft?.length > titleRight?.length ? titleLeft : titleRight;
|
||||||
if (title) {
|
if (title) {
|
||||||
@@ -77,6 +82,17 @@ export function importTimes(data: string, videoDuration: number): SponsorTime[]
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeIf(value: string, matchers: Array<{ matcher: RegExp, condition?: (value: string) => boolean }>): string {
|
||||||
|
let result = value;
|
||||||
|
for (const matcher of matchers) {
|
||||||
|
if (!matcher.condition || matcher.condition(value)) {
|
||||||
|
result = result.replace(matcher.matcher, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
export function exportTimesAsHashParam(segments: SponsorTime[]): string {
|
export function exportTimesAsHashParam(segments: SponsorTime[]): string {
|
||||||
const hashparamSegments = segments.map(segment => ({
|
const hashparamSegments = segments.map(segment => ({
|
||||||
actionType: segment.actionType,
|
actionType: segment.actionType,
|
||||||
|
|||||||
Reference in New Issue
Block a user