Merge pull request #50 from amhsirak/develop

feat: more detailed elementInfo
This commit is contained in:
Karishma Shukla
2024-10-05 15:26:22 +05:30
committed by GitHub
2 changed files with 20 additions and 0 deletions

View File

@@ -81,10 +81,24 @@ export const getElementInformation = async (
innerText?: string; innerText?: string;
url?: string; url?: string;
imageUrl?: string; imageUrl?: string;
attributes?: Record<string, string>;
innerHTML?: string;
outerHTML?: string;
} = { } = {
tagName: element?.tagName ?? '', tagName: element?.tagName ?? '',
}; };
if (element) {
info.attributes = Array.from(element.attributes).reduce(
(acc, attr) => {
acc[attr.name] = attr.value;
return acc;
},
{} as Record<string, string>
);
}
// Gather specific information based on the tag
if (element?.tagName === 'A') { if (element?.tagName === 'A') {
info.url = (element as HTMLAnchorElement).href; info.url = (element as HTMLAnchorElement).href;
info.innerText = element.innerText ?? ''; info.innerText = element.innerText ?? '';
@@ -96,6 +110,9 @@ export const getElementInformation = async (
info.innerText = element?.innerText ?? ''; info.innerText = element?.innerText ?? '';
} }
info.innerHTML = element.innerHTML;
info.outerHTML = element.outerHTML;
return info; return info;
} }
return null; return null;

View File

@@ -14,6 +14,9 @@ interface ElementInfo {
innerText?: string; innerText?: string;
url?: string; url?: string;
imageUrl?: string; imageUrl?: string;
attributes?: Record<string, string>;
innerHTML?: string;
outerHTML?: string;
} }
interface AttributeOption { interface AttributeOption {