File size: 1,863 Bytes
0d773d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
(function () {
const extractElementData = (el) => {
const tag = el.tagName.toLowerCase();
if (
tag === "input" &&
el.name !== "DXScript" &&
el.name !== "DXMVCEditorsValues" &&
el.name !== "DXCss"
) {
return {
type: "input",
name: el.name,
value:
el.type === "checkbox" || el.type === "radio"
? el.checked
? el.value
: null
: el.value,
};
} else if (tag === "select") {
const selectedOption = el.querySelector("option:checked");
return {
type: "select",
name: el.name,
value: selectedOption ? selectedOption.value : null,
};
} else if (tag.startsWith("h") && el.textContent.trim()) {
return { type: "header", tag, content: el.textContent.trim() };
} else if (
["label", "span", "p", "b", "strong"].includes(tag) &&
el.textContent.trim()
) {
return { type: tag, content: el.textContent.trim() };
}
};
const getElementValues = (els) =>
Array.from(els).map(extractElementData).filter(Boolean);
const getIframeInputValues = (iframe) => {
try {
const iframeDoc = iframe.contentWindow.document;
return getElementValues(
iframeDoc.querySelectorAll("input, select, header, label, span, p")
);
} catch (e) {
console.error("Can't access iframe:", e);
return [];
}
};
const inputValues = getElementValues(
document.querySelectorAll("input, select, header, label, span, p")
);
const iframeInputValues = Array.from(document.querySelectorAll("iframe")).map(
getIframeInputValues
);
return `
## input values\n
\`\`\`json\n
${JSON.stringify(inputValues)}\n
\`\`\`\n
## iframe input values\n
\`\`\`json\n
${JSON.stringify(iframeInputValues)}\n
\`\`\``;
})();
|