Last active
November 18, 2024 13:48
-
-
Save julianengel/12e8c62698d29e5d53f156a5e0cbaf24 to your computer and use it in GitHub Desktop.
Y-Combinator Save Application To Markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to extract form data | |
function extractFormData() { | |
// Get all div elements that might contain form fields | |
const formDivs = document.querySelectorAll('div.q'); | |
let extractedData = []; | |
formDivs.forEach(div => { | |
// Find label and input/textarea elements | |
const label = div.querySelector('label span'); | |
const input = div.querySelector('input, textarea'); | |
if (label && input) { | |
extractedData.push({ | |
label: label.textContent.trim(), | |
value: input.value | |
}); | |
} | |
}); | |
return extractedData; | |
} | |
// Function to format data as markdown | |
function formatDataAsMarkdown(data) { | |
let markdownContent = '# Form Data Extract\n\n'; | |
data.forEach(item => { | |
markdownContent += `## ${item.label}\n`; | |
markdownContent += `${item.value}\n\n`; | |
}); | |
return markdownContent; | |
} | |
// Function to save data as markdown file | |
function saveToFile(data) { | |
const markdownContent = formatDataAsMarkdown(data); | |
const blob = new Blob([markdownContent], { type: 'text/markdown' }); | |
const url = window.URL.createObjectURL(blob); | |
const a = document.createElement('a'); | |
a.href = url; | |
a.download = 'form_data.md'; | |
document.body.appendChild(a); | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
document.body.removeChild(a); | |
} | |
// Main execution | |
function extractAndSaveFormData() { | |
const formData = extractFormData(); | |
saveToFile(formData); | |
} | |
// You can call this function to start the extraction and save process | |
// extractAndSaveFormData(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment