Skip to content

Commit

Permalink
Look for class="article" for content
Browse files Browse the repository at this point in the history
Quite a few sites use this, but fail the current
heuristic.
  • Loading branch information
mrichtarsky committed Feb 13, 2024
1 parent ed09cb7 commit 3b6c1ba
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/utils/get-core-content-text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,28 @@ function findLargestElement(e) {
}

export function getCoreContentText() {
function getTextFrom(e) {
return e.innerText || e.textContent
}

for (const [siteName, selectors] of Object.entries(adapters)) {
if (location.hostname.includes(siteName)) {
const element = getPossibleElementByQuerySelector(selectors)
if (element) return element.innerText || element.textContent
if (element) return getTextFrom(element)
break
}
}

const element = document.querySelector('article')
if (element) {
return getTextFrom(element)
}

const largestElement = findLargestElement(document.body)
const secondLargestElement = findLargestElement(largestElement)
console.log(largestElement)
console.log(secondLargestElement)

function getTextFrom(e) {
return e.innerText || e.textContent
}

let ret
if (!largestElement) {
ret = getTextFrom(document.body)
Expand Down

0 comments on commit 3b6c1ba

Please sign in to comment.