Created
June 20, 2025 06:53
-
-
Save Spiderpig86/1b49718a9b505ae8b56a12e7a4ed599d to your computer and use it in GitHub Desktop.
Extract Page Contents for Prompting
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 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