do not fix the cli the same links and image links
This commit is contained in:
+18
-7
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user