Skip to content

Commit

Permalink
Merge pull request #566 from h3poteto/fix/status-parser
Browse files Browse the repository at this point in the history
Rescue undefined of statusParser
  • Loading branch information
h3poteto authored Mar 24, 2023
2 parents e1790e1 + 4ba17d6 commit ec8cc5c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/statusParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export function findLink(target: HTMLElement | null, parentClassName: string): s
}

export function findTag(target: HTMLElement, parentClass = 'toot'): string | null {
if (!target || !target.getAttribute) {
return null
}
const targetClass = target.getAttribute('class')
if (targetClass && targetClass.includes('hashtag')) {
return parseTag((target as HTMLLinkElement).href)
Expand All @@ -36,7 +39,7 @@ export function findTag(target: HTMLElement, parentClass = 'toot'): string | nul
return null
}
const parent = target.parentNode as HTMLElement
if (parent.getAttribute('class') === parentClass) {
if (parent.getAttribute && parent.getAttribute('class') === parentClass) {
return null
}
return findTag(parent, parentClass)
Expand All @@ -51,7 +54,7 @@ function parseTag(tagURL: string): string | null {
}

export function findAccount(target: HTMLElement | null, parentClassName: string): ParsedAccount | null {
if (!target) {
if (!target || !target.getAttribute) {
return null
}

Expand All @@ -77,7 +80,7 @@ export function findAccount(target: HTMLElement | null, parentClassName: string)
return null
}
const parent = target.parentNode as HTMLElement
if (parent.getAttribute('class') === parentClassName) {
if (parent.getAttribute && parent.getAttribute('class') === parentClassName) {
return null
}
return findAccount(parent, parentClassName)
Expand Down

0 comments on commit ec8cc5c

Please sign in to comment.