Skip to content

Commit

Permalink
Fix photo mode inconsistent download issue
Browse files Browse the repository at this point in the history
  • Loading branch information
EltonChou committed Jan 1, 2024
1 parent d4763f4 commit 4976253
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/content_script/core/Harvester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isArticlePhotoMode, selectArtcleMode } from '../utils/article'
import { createElementFromHTML, makeButtonListener } from '../utils/maker'
import { addBreadcrumb } from '@sentry/browser'
import { copy as arrCopy, reduce as arrReduce } from 'fp-ts/lib/Array'
import { fromNullable as eitherNullable, toError } from 'fp-ts/lib/Either'
import { fromNullable as eitherNullable } from 'fp-ts/lib/Either'
import * as IOE from 'fp-ts/lib/IOEither'
import { fromPredicate as optionFromPredicate } from 'fp-ts/lib/Option'
import { pipe } from 'fp-ts/lib/function'
Expand All @@ -18,7 +18,8 @@ const featureRegEx = Object.freeze({
})

const getLinksFromArticle = (article: HTMLElement): string[] => {
if (isArticlePhotoMode(article)) return [window.location.pathname]
const parentArticle = article.closest('article')
if (!parentArticle || isArticlePhotoMode(article)) return [window.location.pathname]
const anchorEles = select.all('[data-testid="User-Name"] [href]', article)
const timeEle = select('a > time', article)
if (timeEle?.parentElement?.tagName === 'A') anchorEles.push(timeEle.parentElement)
Expand Down Expand Up @@ -50,16 +51,20 @@ const parseLinks =
)

export const parseTweetInfo = (article: HTMLElement): IOE.IOEither<Error, TweetInfo> => {
addBreadcrumb({
category: 'parse',
message: 'Parse tweet info.',
level: 'info',
})

return pipe(
IOE.of({
links: getLinksFromArticle(article),
}),
IOE.Do,
IOE.tap(() =>
pipe(
() =>
addBreadcrumb({
category: 'parse',
message: 'Parse tweet info.',
level: 'info',
}),
IOE.of
)
),
IOE.bind('links', () => IOE.right(getLinksFromArticle(article))),
IOE.bind('screenName', ({ links }) =>
pipe(links, parseLinks('screenName')(getScreenNameFromLink))
),
Expand Down
2 changes: 2 additions & 0 deletions src/content_script/utils/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ export const articleHasMedia = (article: HTMLElement) =>

export const isArticleCanBeAppend = (article: HTMLElement) =>
!(select.exists('.deck-harvester', article) || select.exists('.harvester', article))

export const getParentArticle = (ele: HTMLElement): HTMLElement => ele.closest('article')

0 comments on commit 4976253

Please sign in to comment.