do not fix the cli the same links and image links

This commit is contained in:
2026-04-10 02:49:54 +02:00
parent f18d2d5536
commit 0ef224bc11
+17 -6
View File
@@ -567,13 +567,21 @@ function contentDispatch(funcName, args) {
return document.querySelector(selector) !== null; return document.querySelector(selector) !== null;
} }
function extractLinks() { function extractLinks() {
return Array.from(document.querySelectorAll("a[href]")).map(a => ({ const seen = new Set();
return Array.from(document.querySelectorAll("a[href]")).reduce((links, a) => {
const href = a.href;
if (!href || seen.has(href)) return links;
seen.add(href);
links.push({
text: a.textContent.trim().slice(0, 100), text: a.textContent.trim().slice(0, 100),
href: a.href, href,
})); });
return links;
}, []);
} }
function extractImages() { function extractImages() {
return Array.from(document.querySelectorAll("img")).map(img => { const seen = new Set();
return Array.from(document.querySelectorAll("img")).reduce((images, img) => {
const src = const src =
img.src || img.src ||
img.getAttribute("data-src") || img.getAttribute("data-src") ||
@@ -581,10 +589,13 @@ function contentDispatch(funcName, args) {
img.getAttribute("data-original") || img.getAttribute("data-original") ||
(img.srcset ? img.srcset.split(",")[0].trim().split(" ")[0] : "") || (img.srcset ? img.srcset.split(",")[0].trim().split(" ")[0] : "") ||
""; "";
if (!src || seen.has(src)) return images;
seen.add(src);
const FAKE_ALT = new Set(["true", "false", "null", "undefined", "image", "img"]); const FAKE_ALT = new Set(["true", "false", "null", "undefined", "image", "img"]);
const alt = img.alt && !FAKE_ALT.has(img.alt.trim().toLowerCase()) ? img.alt.trim() : ""; const alt = img.alt && !FAKE_ALT.has(img.alt.trim().toLowerCase()) ? img.alt.trim() : "";
return { alt, src }; images.push({ alt, src });
}).filter(img => img.src !== ""); return images;
}, []);
} }
function extractText() { function extractText() {
return document.body.innerText; return document.body.innerText;