fix: align market selection checkboxes

This commit is contained in:
2026-04-24 22:10:16 +08:00
parent 7da1bcf255
commit fe60253cd3
3 changed files with 121 additions and 34 deletions
+37 -5
View File
@@ -431,7 +431,7 @@ function readDivGridAuthorIds(root: ParentNode): string[] | null {
) ?? null
: null;
const authorColumn = authorSection
? getDirectContentColumns(authorSection)[0] ?? null
? getNativeAuthorColumn(authorSection)
: null;
if (!authorColumn) {
return null;
@@ -497,7 +497,7 @@ function syncDivGridRoot(root: HTMLElement): MarketTableDom | null {
type: "body"
});
const authorColumn = getDirectContentColumns(authorSection)[0] ?? null;
const authorColumn = getNativeAuthorColumn(authorSection);
const actionColumn = getActionColumn(rightSection);
if (!authorColumn || !actionColumn) {
@@ -752,7 +752,11 @@ function ensureDivHeaderCell(
nextCell.textContent = label;
applyColumnWidth(nextCell, field);
applyPluginHeaderCellStyles(nextCell);
container.appendChild(nextCell);
if (field === SELECTION_COLUMN_KEY) {
container.insertBefore(nextCell, templateCell);
} else {
container.appendChild(nextCell);
}
return nextCell;
}
@@ -774,7 +778,11 @@ function ensureDivBodyColumn(
nextColumn.dataset.marketColumnGroup = field;
applyColumnWidth(nextColumn, field);
syncDivColumnCells(nextColumn, templateColumn, field, rowCount);
container.appendChild(nextColumn);
if (field === SELECTION_COLUMN_KEY) {
container.insertBefore(nextColumn, templateColumn);
} else {
container.appendChild(nextColumn);
}
return nextColumn;
}
@@ -802,7 +810,9 @@ function syncDivColumnCells(
templateCells[index] ?? templateCells[templateCells.length - 1] ?? null;
const nextCell =
field === SELECTION_COLUMN_KEY
? createBareContentCell(column.ownerDocument)
? templateCell
? createSelectionContentCell(templateCell)
: createBareContentCell(column.ownerDocument)
: templateCell
? cloneElementShallow(templateCell)
: createBareContentCell(column.ownerDocument);
@@ -1106,6 +1116,21 @@ function getActionColumn(bodySection: HTMLElement): HTMLElement | null {
return columns[columns.length - 1] ?? null;
}
function getNativeAuthorColumn(authorSection: HTMLElement): HTMLElement | null {
return (
getDirectContentColumns(authorSection).find(
(column) =>
!column.dataset.marketColumnGroup &&
getDirectContentCells(column).some(
(cell) =>
cell.querySelector("a") ||
cell.querySelector(".author-nickname") ||
Boolean(cell.dataset.authorId)
)
) ?? null
);
}
function getDirectHeaderCells(section: Element): HTMLElement[] {
return Array.from(section.querySelectorAll(".header-cell")).filter(
(cell): cell is HTMLElement =>
@@ -1162,6 +1187,13 @@ function createBareContentCell(document: Document): HTMLElement {
return cell;
}
function createSelectionContentCell(templateCell: HTMLElement): HTMLElement {
const cell = cloneElementShallow(templateCell);
cell.removeAttribute("data-testid");
cell.removeAttribute("data-author-id");
return cell;
}
function extractAuthorId(authorCell: HTMLElement): string {
const explicitAuthorId = authorCell.dataset.authorId;
if (explicitAuthorId) {