Skip to content

Commit

Permalink
WE: Add some filtering to remove bad images
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoy committed Dec 5, 2019
1 parent 1bfe1c7 commit 9156973
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion WebExtension/src/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ if (window[extensionContainerId]) {

return (exactMatches.length > 0 ? exactMatches : fuzzyMatches)
.reduce((acc, element) => [...acc, ...getImgElementsWithin(element)], [])
.filter(element => isImg(element) && element.src)
.filter(element =>
isImg(element) &&
element.src &&
element.complete && // Filter images that haven't completely loaded
element.naturalWidth > 0 && // Filter images that haven't loaded correctly
element.naturalHeight > 0
)
.reduce((max, element) => (element.offsetHeight * element.offsetWidth) > (max ? (max.offsetHeight * max.offsetWidth) : 0) ? element : max, null)
}

Expand Down

0 comments on commit 9156973

Please sign in to comment.