Size
4.8 KB
Version
1.0.1
Created
Oct 17, 2025
Updated
3 months ago
1// ==UserScript==
2// @name Stripchat Chat Exporter
3// @description Automatically exports chat messages to JSON file every minute
4// @version 1.0.1
5// @match https://*.stripchat.com/*
6// @icon https://assets.striiiipst.com/assets/icons/favicon-32x32.png?v=9670c787
7// @grant GM.xmlhttpRequest
8// ==/UserScript==
9(function() {
10 'use strict';
11
12 console.log('Stripchat Chat Exporter: Extension loaded');
13
14 // Function to extract chat messages
15 function extractChatMessages() {
16 const messagesContainer = document.querySelector('.messages');
17 if (!messagesContainer) {
18 console.log('Chat messages container not found');
19 return [];
20 }
21
22 const messageElements = messagesContainer.querySelectorAll('.message.message-base');
23 const messages = [];
24
25 messageElements.forEach((messageEl) => {
26 try {
27 // Extract username
28 const usernameEl = messageEl.querySelector('.user-levels-username-text');
29 const username = usernameEl ? usernameEl.textContent.trim() : 'Unknown';
30
31 // Extract message text (get the text after the username element)
32 const messageBodyEl = messageEl.querySelector('.message-body');
33 let messageText = '';
34
35 if (messageBodyEl) {
36 // Clone the element to manipulate it
37 const clone = messageBodyEl.cloneNode(true);
38 // Remove the username div to get only the message text
39 const usernameDiv = clone.querySelector('.message-username');
40 if (usernameDiv) {
41 usernameDiv.remove();
42 }
43 messageText = clone.textContent.trim();
44 }
45
46 // Get timestamp
47 const timestamp = new Date().toISOString();
48
49 messages.push({
50 username: username,
51 message: messageText,
52 extractedAt: timestamp
53 });
54 } catch (error) {
55 console.error('Error extracting message:', error);
56 }
57 });
58
59 console.log(`Extracted ${messages.length} chat messages`);
60 return messages;
61 }
62
63 // Function to download JSON file
64 function downloadJSON(data, filename) {
65 const jsonString = JSON.stringify(data, null, 2);
66 const blob = new Blob([jsonString], { type: 'application/json' });
67 const url = URL.createObjectURL(blob);
68
69 const a = document.createElement('a');
70 a.href = url;
71 a.download = filename;
72 a.style.display = 'none';
73
74 document.body.appendChild(a);
75 a.click();
76
77 // Clean up
78 setTimeout(() => {
79 document.body.removeChild(a);
80 URL.revokeObjectURL(url);
81 }, 100);
82
83 console.log(`Downloaded: ${filename}`);
84 }
85
86 // Function to export chat messages
87 function exportChatMessages() {
88 const messages = extractChatMessages();
89
90 if (messages.length === 0) {
91 console.log('No messages to export');
92 return;
93 }
94
95 // Create filename with timestamp
96 const now = new Date();
97 const timestamp = now.toISOString().replace(/[:.]/g, '-').slice(0, -5);
98 const filename = `stripchat-chat-${timestamp}.json`;
99
100 // Create export data
101 const exportData = {
102 exportedAt: now.toISOString(),
103 url: window.location.href,
104 messageCount: messages.length,
105 messages: messages
106 };
107
108 // Download the file
109 downloadJSON(exportData, filename);
110 }
111
112 // Initialize the extension
113 function init() {
114 console.log('Stripchat Chat Exporter: Initializing...');
115
116 // Wait for chat to load
117 const checkChatInterval = setInterval(() => {
118 const messagesContainer = document.querySelector('.messages');
119 if (messagesContainer) {
120 console.log('Chat container found, starting export timer');
121 clearInterval(checkChatInterval);
122
123 // Export immediately on load
124 exportChatMessages();
125
126 // Set up interval to export every minute (60000 milliseconds)
127 setInterval(() => {
128 console.log('Auto-exporting chat messages...');
129 exportChatMessages();
130 }, 60000);
131 }
132 }, 1000);
133
134 // Clear the check interval after 30 seconds if chat not found
135 setTimeout(() => {
136 clearInterval(checkChatInterval);
137 }, 30000);
138 }
139
140 // Start the extension when page loads
141 if (document.readyState === 'loading') {
142 document.addEventListener('DOMContentLoaded', init);
143 } else {
144 init();
145 }
146})();