Skip to content

Commit 4b3f586

Browse files
committed
isElementVisible experiment
1 parent 80e3a43 commit 4b3f586

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/content-script/shared-functions.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,17 @@ function getAllTitleCardsTypes(): Array<NodeListOf<Element>> {
350350
]
351351
return AllTitleCardsTypes
352352
}
353+
function isElementVisible(el: HTMLElement): boolean {
354+
if (!el) return false
355+
const rect = el.getBoundingClientRect()
356+
const visible =
357+
// el.checkVisibility({ checkOpacity: true, visibilityProperty: true, contentVisibilityAuto: true }) &&
358+
rect.bottom > 0 &&
359+
rect.right > 0 &&
360+
rect.top < (window.innerHeight || document.documentElement.clientHeight) &&
361+
rect.left < (window.innerWidth || document.documentElement.clientWidth)
362+
return visible
363+
}
353364

354365
async function addRating(showRating: boolean, optionHideTitles: boolean) {
355366
url = window.location.href
@@ -398,7 +409,17 @@ async function addRating(showRating: boolean, optionHideTitles: boolean) {
398409
(!media_type || DBCache[title]?.media_type == media_type)
399410
) {
400411
useDBCache(title, card, media_type)
401-
} else {
412+
}
413+
// if element is not visible skip it
414+
// else if (!isElementVisible(card)) {
415+
// if (isNetflix || isDisney || isHotstar || isHBO || isParamount) card.classList.remove("imdb")
416+
// else if (isPrimeVideo) {
417+
// if (type == 0) card?.closest("li")?.classList.remove("imdb")
418+
// else if (type == 1) card?.classList.remove("imdb")
419+
// }
420+
// continue
421+
// }
422+
else {
402423
getMovieInfo(title, card, media_type)
403424
updateDBCache = true
404425
}

0 commit comments

Comments
 (0)