You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

content.js 1.8KB

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