diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 542e2e6..ef3b219 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -100,4 +100,9 @@ export const DOCUMENT_LINK = { "https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors", } as const; -export const BSKY_DOMAIN = process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; \ No newline at end of file +export const BSKY_DOMAIN = + process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; + +export const BSKY_PROFILE_LABEL = { + IMPERSONATION: "impersonation", +} as const; diff --git a/src/lib/domHelpers.ts b/src/lib/domHelpers.ts index 929ff72..f1fd28f 100644 --- a/src/lib/domHelpers.ts +++ b/src/lib/domHelpers.ts @@ -29,7 +29,9 @@ export const getAccountNameAndDisplayName = (userCell: Element) => { const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-"); const twDisplayName = displayNameEl?.textContent; const bskyHandle = - userCell.textContent?.match(new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`))?.[1] ?? + userCell.textContent?.match( + new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`), + )?.[1] ?? userCell.textContent ?.match(/bsky\.app\/profile\/([^/\s]+)…?/)?.[1] ?.replace("…", "") ?? diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index 15b27e4..7b91cce 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -1,7 +1,15 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import { isSimilarUser } from "~lib/bskyHelpers"; import type { getAccountNameAndDisplayName } from "~lib/domHelpers"; import { isOneSymbol } from "~lib/utils"; import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; +import { BSKY_PROFILE_LABEL } from "./constants"; + +const isImpersonationUser = (user: ProfileView) => { + return user.labels.some( + (label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION, + ); +}; export const searchBskyUser = async ({ client, @@ -25,11 +33,16 @@ export const searchBskyUser = async ({ } try { const searchResults = await client.searchUser({ - term: term, + term, limit: 3, }); for (const searchResult of searchResults) { + // skip impersonation users + if (isImpersonationUser(searchResult)) { + continue; + } + const { isSimilar: isUserFound, type } = isSimilarUser( // TODO: simplify { diff --git a/src/popup.tsx b/src/popup.tsx index d2f972b..26e588e 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -7,6 +7,7 @@ import { sendToBackground, sendToContentScript } from "@plasmohq/messaging"; import { AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE, + BSKY_DOMAIN, DOCUMENT_LINK, MAX_RELOAD_COUNT, MESSAGE_NAMES, @@ -14,7 +15,6 @@ import { RATE_LIMIT_ERROR_MESSAGE, STORAGE_KEYS, TARGET_URLS_REGEX, - BSKY_DOMAIN, } from "~lib/constants"; function IndexPopup() {