From 0ef224bc1136dd0f6a9dbf240096d14773eaf0f0 Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Fri, 10 Apr 2026 02:49:54 +0200 Subject: [PATCH] do not fix the cli the same links and image links --- extension/background.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/extension/background.js b/extension/background.js index 0313634..fd03615 100644 --- a/extension/background.js +++ b/extension/background.js @@ -567,13 +567,21 @@ function contentDispatch(funcName, args) { return document.querySelector(selector) !== null; } function extractLinks() { - return Array.from(document.querySelectorAll("a[href]")).map(a => ({ - text: a.textContent.trim().slice(0, 100), - href: a.href, - })); + 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), + href, + }); + return links; + }, []); } 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 = img.src || img.getAttribute("data-src") || @@ -581,10 +589,13 @@ function contentDispatch(funcName, args) { img.getAttribute("data-original") || (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 alt = img.alt && !FAKE_ALT.has(img.alt.trim().toLowerCase()) ? img.alt.trim() : ""; - return { alt, src }; - }).filter(img => img.src !== ""); + images.push({ alt, src }); + return images; + }, []); } function extractText() { return document.body.innerText;