Blog Post to Markdown Extractor

Extract blog posts from aiwithamitay.com and convert them to markdown format

Size

5.5 KB

Version

1.0.1

Created

Oct 16, 2025

Updated

7 days ago

1// ==UserScript==
2// @name		Blog Post to Markdown Extractor
3// @description		Extract blog posts from aiwithamitay.com and convert them to markdown format
4// @version		1.0.1
5// @match		https://*.aiwithamitay.com/*
6// @icon		https://substackcdn.com/image/fetch/$s_!-exM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93358d74-a63c-4ff5-9b80-f84848277c93%2Ffavicon-32x32.png
7// ==/UserScript==
8(function() {
9    'use strict';
10
11    console.log('Blog Post to Markdown Extractor loaded');
12
13    // Function to extract blog post content and convert to markdown
14    function extractToMarkdown() {
15        try {
16            // Get the article element
17            const article = document.querySelector('article') || document.querySelector('.single-post') || document.querySelector('.post-content');
18            
19            if (!article) {
20                console.error('Article content not found');
21                return null;
22            }
23
24            // Extract title
25            const titleElement = document.querySelector('h1.post-title') || document.querySelector('h1') || document.querySelector('.post-title');
26            const title = titleElement ? titleElement.innerText.trim() : 'Untitled';
27
28            // Extract author and date
29            const authorElement = document.querySelector('.author-name') || document.querySelector('[class*="author"]');
30            const dateElement = document.querySelector('time') || document.querySelector('[class*="date"]');
31            
32            const author = authorElement ? authorElement.innerText.trim() : '';
33            const date = dateElement ? dateElement.innerText.trim() : '';
34
35            // Get the full text content
36            const fullText = article.innerText;
37
38            // Build markdown
39            let markdown = `# ${title}\n\n`;
40            
41            if (author) {
42                markdown += `**Author:** ${author}\n`;
43            }
44            if (date) {
45                markdown += `**Date:** ${date}\n`;
46            }
47            markdown += `\n---\n\n`;
48            markdown += fullText;
49
50            return markdown;
51        } catch (error) {
52            console.error('Error extracting content:', error);
53            return null;
54        }
55    }
56
57    // Function to create and show the extract button
58    function createExtractButton() {
59        // Create button
60        const button = document.createElement('button');
61        button.id = 'markdown-extract-btn';
62        button.innerHTML = '📄 Extract to Markdown';
63        button.style.cssText = `
64            position: fixed;
65            top: 20px;
66            right: 20px;
67            z-index: 10000;
68            padding: 12px 20px;
69            background: #007bff;
70            color: white;
71            border: none;
72            border-radius: 8px;
73            font-size: 14px;
74            font-weight: 600;
75            cursor: pointer;
76            box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
77            transition: all 0.3s ease;
78        `;
79
80        button.addEventListener('mouseenter', () => {
81            button.style.background = '#0056b3';
82            button.style.transform = 'translateY(-2px)';
83            button.style.boxShadow = '0 6px 16px rgba(0, 123, 255, 0.4)';
84        });
85
86        button.addEventListener('mouseleave', () => {
87            button.style.background = '#007bff';
88            button.style.transform = 'translateY(0)';
89            button.style.boxShadow = '0 4px 12px rgba(0, 123, 255, 0.3)';
90        });
91
92        button.addEventListener('click', async () => {
93            console.log('Extract button clicked');
94            const markdown = extractToMarkdown();
95            
96            if (markdown) {
97                // Copy to clipboard
98                try {
99                    await GM.setClipboard(markdown);
100                    
101                    // Show success message
102                    button.innerHTML = '✅ Copied to Clipboard!';
103                    button.style.background = '#28a745';
104                    
105                    setTimeout(() => {
106                        button.innerHTML = '📄 Extract to Markdown';
107                        button.style.background = '#007bff';
108                    }, 2000);
109                    
110                    console.log('Markdown copied to clipboard successfully');
111                } catch (error) {
112                    console.error('Error copying to clipboard:', error);
113                    button.innerHTML = '❌ Error';
114                    button.style.background = '#dc3545';
115                    
116                    setTimeout(() => {
117                        button.innerHTML = '📄 Extract to Markdown';
118                        button.style.background = '#007bff';
119                    }, 2000);
120                }
121            } else {
122                button.innerHTML = '❌ No Content Found';
123                button.style.background = '#dc3545';
124                
125                setTimeout(() => {
126                    button.innerHTML = '📄 Extract to Markdown';
127                    button.style.background = '#007bff';
128                }, 2000);
129            }
130        });
131
132        document.body.appendChild(button);
133        console.log('Extract button added to page');
134    }
135
136    // Initialize when page is ready
137    function init() {
138        // Wait for content to load
139        if (document.readyState === 'loading') {
140            document.addEventListener('DOMContentLoaded', () => {
141                setTimeout(createExtractButton, 1000);
142            });
143        } else {
144            setTimeout(createExtractButton, 1000);
145        }
146    }
147
148    init();
149})();
Blog Post to Markdown Extractor | Robomonkey