Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(twitter): dom selector #5888

Merged
merged 3 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function resolveCurrentVisitingIdentityInner(
const nickname = getNickname()
const handle = getTwitterId()
const avatar = getAvatar()

ref.value = {
identifier: new ProfileIdentifier(twitterBase.networkIdentifier, handle),
nickname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ export const searchNewTweetButtonSelector: () => LiveSelector<E, true> = () => {
return querySelector<E>('[data-testid="SideNav_NewTweet_Button"]')
}

export const searchNickNameSelector: () => LiveSelector<E, true> = () =>
querySelector<E>('[data-testid="UserProfileHeader_Items"]')
export const searchNickNameSelector: () => LiveSelector<E, true> = () => querySelector<E>('[data-testid="UserName"]')
export const searchAvatarSelector = () =>
querySelector<HTMLImageElement>('[data-testid="primaryColumn"] a[href$="/photo"] img[src*="profile_images"]')
export const searchNFTAvatarSelector = () =>
Expand Down
16 changes: 6 additions & 10 deletions packages/mask/src/social-network-adaptor/twitter.com/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@ export const usernameValidator: NonNullable<SocialNetwork.Utils['isValidUsername
}

export const getNickname = () => {
const node = searchNickNameSelector().evaluate()?.parentElement?.parentElement?.firstChild
?.nextSibling as HTMLDivElement
const node = searchNickNameSelector().evaluate()?.querySelector('span span') as HTMLDivElement
if (!node) return ''

const nicknameNode = node.querySelector<HTMLSpanElement>('div span')
if (!nicknameNode) return ''

return collectNodeText(nicknameNode)
return collectNodeText(node)
}

export const getTwitterId = () => {
const node = searchNickNameSelector().evaluate()?.parentElement?.parentElement?.firstChild?.nextSibling?.firstChild
?.firstChild?.lastChild as HTMLDivElement
const node = searchNickNameSelector()
.evaluate()
?.firstElementChild?.firstElementChild?.nextElementSibling?.querySelector('span') as HTMLDivElement
if (node) {
const twitterIdNode = node.querySelector('div span')
if (twitterIdNode) return twitterIdNode.innerHTML.trim().replace('@', '')
return node.innerHTML.trim().replace('@', '')
}

const ele = searchAvatarSelector().evaluate()?.closest('a') || searchNFTAvatarSelector().evaluate()?.closest('a')
Expand Down