Remove the table with text content less than 20 because these are ads

This commit is contained in:
Hongbo Wu 2022-09-22 22:16:03 +08:00
parent 99dad48dd1
commit 0239103fc4

View file

@ -11,9 +11,11 @@ export class AxiosHandler {
prehandle = (url: URL, dom: Document): Promise<Document> => {
const body = dom.querySelector('table')
let isFooter = false
// this removes ads and replaces table with a div
body?.querySelectorAll('table').forEach((el, k) => {
if (k > 0) {
body?.querySelectorAll('table').forEach((el) => {
// remove the footer and the ads
if (!el.textContent || el.textContent.length < 20 || isFooter) {
el.remove()
} else {
// removes the first few rows of the table (the header)
@ -28,6 +30,8 @@ export class AxiosHandler {
const div = dom.createElement('div')
div.innerHTML = el.innerHTML
el.parentNode?.replaceChild(div, el)
// set the isFooter flag to true because the next table is the footer
isFooter = true
}
})