function sensaCollectTables(limit) {
  const tables = [];
  for (const table of document.querySelectorAll("table")) {
    if (!sensaIsElementVisible(table)) {
      continue;
    }

    const headers = Array.from(table.querySelectorAll("th"))
      .map((cell) => sensaNormalizeText(cell.textContent || ""))
      .filter(Boolean)
      .slice(0, 8);

    const rows = [];
    for (const row of table.querySelectorAll("tr")) {
      const cells = Array.from(row.querySelectorAll("td"))
        .map((cell) => sensaNormalizeText(cell.textContent || ""))
        .filter(Boolean)
        .slice(0, 8);
      if (cells.length) {
        rows.push(cells);
      }
      if (rows.length >= 4) {
        break;
      }
    }

    if (!headers.length && !rows.length) {
      continue;
    }

    tables.push({ headers, rows });
    if (tables.length >= limit) {
      break;
    }
  }
  return tables;
}

function sensaCollectLists(limit) {
  const lists = [];
  for (const list of document.querySelectorAll("ul, ol")) {
    if (!sensaIsElementVisible(list)) {
      continue;
    }
    const items = Array.from(list.querySelectorAll("li"))
      .map((item) => sensaNormalizeText(item.textContent || ""))
      .filter(Boolean)
      .slice(0, 8);
    if (!items.length) {
      continue;
    }
    lists.push(items);
    if (lists.length >= limit) {
      break;
    }
  }
  return lists;
}
