Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/components/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ function renderCell(cell: string) {
return cell;
}

async function copyToClipboard(result: {
title?: string;
table: string[][];
includeHeader?: boolean;
}) {
let tableToCopy = result.table;
if (!result.includeHeader) {
tableToCopy = result.table.slice(1); // Remove the first row (header)
}

await navigator.clipboard.writeText(array2tsv(tableToCopy));
setTimeout(() => window.close(), 200);
}

interface Props {
results: ScrapperResults;
}
Expand Down Expand Up @@ -43,10 +57,7 @@ const Preview: FunctionComponent<Props> = ({ results = [] }) => {
<Button
className="copy-btn"
type="secondary"
onClick={async () => {
await navigator.clipboard.writeText(array2tsv(result.table));
setTimeout(() => window.close(), 200);
}}
onClick={() => copyToClipboard(result)}
>
<img alt="copy" src="/icons/copy.svg" />
</Button>
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/babymarket.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.babymarkt.de/*
listElementsQuery: .site-main
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/babypark-de.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.babypark.de/*
listElementsQuery: .column
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/babypark-nl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.babypark.nl/*
listElementsQuery: .column
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/pinkorblue.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.pinkorblue.*
listElementsQuery: .site-main
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/rosaoazul-es.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.rosaoazul.es/*
listElementsQuery: .site-main
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/scrappers/roseoubleu-fr.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
url: https://www.roseoubleu.fr/*
listElementsQuery: .site-main
includeHeader: false
elementParser:

- title: Item Description
Expand Down
1 change: 1 addition & 0 deletions src/utils/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function getCurrentTab() {
export interface ScrapperOptions {
url: string | Array<string>;
header?: string;
includeHeader?: boolean;
listElementsQuery?: string;
elementParser?: Array<{
title: string;
Expand Down
1 change: 1 addition & 0 deletions src/utils/scrappers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export async function customScrapper(options: ScrapperOptions) {
{
title: options.header,
table: [[...options.elementParser!.map((element) => element.title)], ...tableElements],
includeHeader: options.includeHeader ?? true,
},
];
}
1 change: 1 addition & 0 deletions src/utils/scrappers/div-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export async function scrapDivHTMLTables(options: ScrapperOptions) {
{
title: options.header,
table,
includeHeader: true,
},
];
}
1 change: 1 addition & 0 deletions src/utils/scrappers/html-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export async function scrapHTMLTables() {
.map((table, index: number) => ({
title: titles[index],
table: toArray(table),
includeHeader: true,
}))
.filter((table) => !table.table.every((row: Row) => row.every((col) => col === '')));
}