PeerPush Auto Commenter

Automatically generate and post AI-powered comments on PeerPush

Size

7.7 KB

Version

1.0.1

Created

Oct 29, 2025

Updated

about 1 month ago

1// ==UserScript==
2// @name		PeerPush Auto Commenter
3// @description		Automatically generate and post AI-powered comments on PeerPush
4// @version		1.0.1
5// @match		https://*.peerpush.net/*
6// @icon		https://peerpush.net/favicon-32x32.png
7// ==/UserScript==
8(function() {
9    'use strict';
10
11    console.log('PeerPush Auto Commenter initialized');
12
13    // Debounce function to prevent excessive calls
14    function debounce(func, wait) {
15        let timeout;
16        return function executedFunction(...args) {
17            const later = () => {
18                clearTimeout(timeout);
19                func(...args);
20            };
21            clearTimeout(timeout);
22            timeout = setTimeout(later, wait);
23        };
24    }
25
26    // Function to get page context for AI
27    function getPageContext() {
28        const title = document.querySelector('h1')?.textContent || '';
29        const description = document.querySelector('meta[name="description"]')?.content || '';
30        const pageText = document.querySelector('main')?.textContent?.slice(0, 1000) || '';
31        
32        return {
33            title: title.trim(),
34            description: description.trim(),
35            content: pageText.trim()
36        };
37    }
38
39    // Function to generate AI comment
40    async function generateComment() {
41        try {
42            console.log('Generating AI comment...');
43            const context = getPageContext();
44            
45            const prompt = `You are commenting on a PeerPush product page. The product is: "${context.title}". 
46            
47Context: ${context.content.slice(0, 500)}
48
49Generate a thoughtful, engaging comment (max 200 characters) that:
50- Shows genuine interest in the product
51- Asks a relevant question or shares a positive observation
52- Sounds natural and conversational
53- Is encouraging and supportive
54
55Just return the comment text, nothing else.`;
56
57            const comment = await RM.aiCall(prompt);
58            console.log('Generated comment:', comment);
59            return comment.trim();
60        } catch (error) {
61            console.error('Error generating comment:', error);
62            throw error;
63        }
64    }
65
66    // Function to post comment
67    async function postComment(commentText) {
68        const textarea = document.querySelector('textarea[placeholder="Share your thoughts..."]');
69        const submitButton = document.querySelector('button[type="submit"]');
70        
71        if (!textarea || !submitButton) {
72            throw new Error('Comment form elements not found');
73        }
74
75        // Set the comment text
76        textarea.value = commentText;
77        
78        // Trigger input event to update character count and enable button
79        const inputEvent = new Event('input', { bubbles: true });
80        textarea.dispatchEvent(inputEvent);
81        
82        // Wait a bit for the UI to update
83        await new Promise(resolve => setTimeout(resolve, 500));
84        
85        // Click the submit button
86        submitButton.click();
87        
88        console.log('Comment posted successfully');
89    }
90
91    // Function to create the auto comment button
92    function createAutoCommentButton() {
93        // Check if button already exists
94        if (document.getElementById('peerpush-auto-comment-btn')) {
95            return;
96        }
97
98        // Find the comment section
99        const commentSection = document.querySelector('form.space-y-3');
100        if (!commentSection) {
101            console.log('Comment form not found yet');
102            return;
103        }
104
105        // Create button container
106        const buttonContainer = document.createElement('div');
107        buttonContainer.id = 'peerpush-auto-comment-container';
108        buttonContainer.style.cssText = 'margin-bottom: 16px;';
109
110        // Create the button
111        const button = document.createElement('button');
112        button.id = 'peerpush-auto-comment-btn';
113        button.type = 'button';
114        button.textContent = '✨ Generate AI Comment';
115        button.style.cssText = `
116            font-weight: 500;
117            border-radius: 8px;
118            cursor: pointer;
119            display: inline-flex;
120            align-items: center;
121            justify-content: center;
122            gap: 8px;
123            transition: all 0.2s;
124            padding: 10px 16px;
125            font-size: 14px;
126            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
127            color: white;
128            border: none;
129            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
130        `;
131
132        // Hover effects
133        button.addEventListener('mouseenter', () => {
134            button.style.transform = 'translateY(-1px)';
135            button.style.boxShadow = '0 4px 8px rgba(0,0,0,0.15)';
136        });
137
138        button.addEventListener('mouseleave', () => {
139            button.style.transform = 'translateY(0)';
140            button.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
141        });
142
143        // Click handler
144        button.addEventListener('click', async () => {
145            const originalText = button.textContent;
146            
147            try {
148                // Show loading state
149                button.disabled = true;
150                button.textContent = '⏳ Generating...';
151                button.style.opacity = '0.7';
152                button.style.cursor = 'not-allowed';
153
154                // Generate comment
155                const comment = await generateComment();
156
157                // Update button
158                button.textContent = '📝 Posting...';
159
160                // Post comment
161                await postComment(comment);
162
163                // Success state
164                button.textContent = '✅ Posted!';
165                button.style.background = 'linear-gradient(135deg, #11998e 0%, #38ef7d 100%)';
166
167                // Reset after 3 seconds
168                setTimeout(() => {
169                    button.textContent = originalText;
170                    button.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
171                    button.disabled = false;
172                    button.style.opacity = '1';
173                    button.style.cursor = 'pointer';
174                }, 3000);
175
176            } catch (error) {
177                console.error('Error in auto comment:', error);
178                
179                // Error state
180                button.textContent = '❌ Error - Try Again';
181                button.style.background = 'linear-gradient(135deg, #eb3349 0%, #f45c43 100%)';
182
183                // Reset after 3 seconds
184                setTimeout(() => {
185                    button.textContent = originalText;
186                    button.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)';
187                    button.disabled = false;
188                    button.style.opacity = '1';
189                    button.style.cursor = 'pointer';
190                }, 3000);
191            }
192        });
193
194        buttonContainer.appendChild(button);
195
196        // Insert before the comment form
197        commentSection.parentElement.insertBefore(buttonContainer, commentSection);
198        
199        console.log('Auto comment button added successfully');
200    }
201
202    // Initialize the extension
203    function init() {
204        console.log('Initializing PeerPush Auto Commenter...');
205        
206        // Try to create button immediately
207        createAutoCommentButton();
208
209        // Watch for DOM changes to handle dynamic content
210        const observer = new MutationObserver(debounce(() => {
211            createAutoCommentButton();
212        }, 500));
213
214        observer.observe(document.body, {
215            childList: true,
216            subtree: true
217        });
218
219        console.log('PeerPush Auto Commenter ready!');
220    }
221
222    // Wait for page to be ready
223    if (document.readyState === 'loading') {
224        document.addEventListener('DOMContentLoaded', init);
225    } else {
226        init();
227    }
228})();
PeerPush Auto Commenter | Robomonkey