Skip to content

Instantly share code, notes, and snippets.

@Spiderpig86
Created June 20, 2025 06:53
Show Gist options
  • Select an option

  • Save Spiderpig86/1b49718a9b505ae8b56a12e7a4ed599d to your computer and use it in GitHub Desktop.

Select an option

Save Spiderpig86/1b49718a9b505ae8b56a12e7a4ed599d to your computer and use it in GitHub Desktop.
Extract Page Contents for Prompting
function extractAllTextContent(root = document.body) {
const texts = [];
function walk(node) {
if (node.nodeType === Node.TEXT_NODE) {
const text = node.textContent.trim();
if (text) texts.push(text);
} else if (node.nodeType === Node.ELEMENT_NODE) {
// Skip <script>, <style>, and <noscript>
const tag = node.tagName.toLowerCase();
if (['script', 'style', 'noscript'].includes(tag)) return;
for (const child of node.childNodes) {
walk(child);
}
}
}
walk(root);
return texts.join('\n');
}
const content = extractAllTextContent();
const title = document.title;
const gptPrompt = `"""\nTitle: ${title}\n\n${content}\n"""\n\nPlease summarize the content in bullet points.`;
console.log(gptPrompt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment