diff --git a/src/content.ts b/src/content.ts index 7a737af..9495de4 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1,3 +1,4 @@ +import { isOutOfTopViewport } from './lib/domHelpers'; import { BskyClient } from "./lib/bskyClient"; import type { PlasmoCSConfig } from "plasmo" import { MESSAGE_NAMES } from "~lib/constants"; @@ -37,7 +38,11 @@ const searchBskyUsers = async ({ const userCells = getUserCells() debugLog(`userCells length: ${userCells.length}`) - for (const [index, userCell] of userCells.entries()) { + let index = 0 + for (const userCell of userCells) { + if(isOutOfTopViewport(userCell)) { + continue + } const { twAccountName, twDisplayName } = getAccountNameAndDisplayName(userCell) if (notFoundUserCache.has(twAccountName)) { insertNotFoundEl(userCell) @@ -96,6 +101,8 @@ const searchBskyUsers = async ({ notFoundUserCache.add(twAccountName) } } + + index++ if (process.env.NODE_ENV === "development" && index > 5) { break } diff --git a/src/lib/domHelpers.ts b/src/lib/domHelpers.ts index d308303..a25b372 100644 --- a/src/lib/domHelpers.ts +++ b/src/lib/domHelpers.ts @@ -144,3 +144,8 @@ export const cleanBskyUserElements = () => { }) } } + +export const isOutOfTopViewport = (el: Element) => { + const rect = el.getBoundingClientRect(); + return rect.top < 0 +}