skip out of top viewport

This commit is contained in:
kawamataryo 2023-05-24 05:47:18 +09:00
parent 1043d1e45e
commit 5f11e76484
2 changed files with 13 additions and 1 deletions

View File

@ -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
}

View File

@ -144,3 +144,8 @@ export const cleanBskyUserElements = () => {
})
}
}
export const isOutOfTopViewport = (el: Element) => {
const rect = el.getBoundingClientRect();
return rect.top < 0
}