Compare commits
2 commits
679cc3e3f2
...
ada8122f60
Author | SHA1 | Date | |
---|---|---|---|
ada8122f60 | |||
558d1e66b7 |
1 changed files with 63 additions and 3 deletions
66
src/index.ts
66
src/index.ts
|
@ -58,11 +58,65 @@ function recurseElement(page: Page, el: Element) {
|
|||
});
|
||||
}
|
||||
}
|
||||
if (["audio", "video", "img", "source", "iframe"].includes(el.name)) {
|
||||
|
||||
if (["audio", "video"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
for (const source of sources) {
|
||||
if (source.attribs.src) {
|
||||
checkUrl(page, source, source.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["picture"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
for (const source of sources) {
|
||||
if (source.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["img"].includes(el.name)) {
|
||||
if (el.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
}
|
||||
}
|
||||
if (["audio", "video"].includes(el.name)) {
|
||||
const sources = getSources(el);
|
||||
if (sources.length > 0) {
|
||||
for (const source of sources) {
|
||||
if (source.attribs.src) {
|
||||
checkUrl(page, source, source.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, source),
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (el.attribs.src) {
|
||||
checkUrl(page, el, el.attribs.src);
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
description: getHtml(rawHtml, el),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (["img", "iframe", "track"].includes(el.name)) {
|
||||
if (el.attribs.src) {
|
||||
checkUrl(page, el, el.attribs.src);
|
||||
} else if (el.attribs.srcset) {
|
||||
// TODO: implementar srcset #3
|
||||
} else {
|
||||
report.things.push({
|
||||
type: "media-no-src",
|
||||
|
@ -78,6 +132,12 @@ function recurseElement(page: Page, el: Element) {
|
|||
}
|
||||
}
|
||||
|
||||
function getSources(el: Element) {
|
||||
return el.children.filter(
|
||||
(c) => c.type === "tag" && c.name === "source"
|
||||
) as Element[];
|
||||
}
|
||||
|
||||
function checkUrl({ report, rawHtml }: Page, el: Element, url: string) {
|
||||
if (isHttp(url)) {
|
||||
report.things.push({
|
||||
|
|
Loading…
Reference in a new issue