Greasy Fork is available in English.

JanitorAI Personality Snatcher

Steals JanitorAI bot descriptions.

// ==UserScript==
// @name         JanitorAI Personality Snatcher
// @namespace    https://greasyfork.org/
// @version      1.0
// @description  Steals JanitorAI bot descriptions.
// @author       Pugsby, ChatGPT
// @match        http*://*.janitorai.com/chats*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=janitorai.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create the button
    const button = document.createElement('button');
    button.innerText = 'Steal Personality';
    button.style.position = 'fixed';
    button.style.top = '8px'; // Move to the top of the screen
    button.style.left = '50%'; // Center horizontally
    button.style.transform = 'translate(-50%, 0)'; // Adjust for horizontal centering
    button.style.padding = '5px 8px'; // Reduced vertical padding
    button.style.borderRadius = '6px';
    button.style.backgroundColor = 'rgba(128, 90, 213, 0.6)';
    button.style.color = 'var(--chakra-colors-whiteAlpha-800)';
    button.style.border = 'none';
    button.style.cursor = 'pointer';
    button.style.zIndex = '9999';
    button.style.fontFamily = 'var(--chakra-fonts-body)';
    button.style.lineHeight = '1';
    button.style.fontSize = '14px';

    let requestCount = 0; // Counter for fetch requests

    // Function to log fetch requests
    function logFetchRequests() {
        const originalFetch = window.fetch;
        button.style.backgroundColor = 'rgba(169, 20, 20, 0.6)';
        window.fetch = async (...args) => {
            requestCount++; // Increment the request counter

            // Change button color when request is made

            // Log only on the second request
            if (requestCount === 2) {
                const requestBody = args[1]?.body; // Get the request body if available

                if (requestBody) {
                    try {
                        const jsonBody = JSON.parse(requestBody); // Parse the JSON body
                        const messages = jsonBody.messages; // Access the messages key

                        if (Array.isArray(messages) && messages.length > 0) {
                            const content = messages[0].content; // Get the content of the first message

                            // Find the text after the second occurrence of "'s Persona: "
                            const occurrences = content.split("'s Persona: ");
                            if (occurrences.length > 2) {
                                let result = occurrences.slice(2).join("'s Persona: "); // Join all parts after the second occurrence

                                // Find the text up to "[System note"
                                const systemNoteIndex = result.indexOf("[System note");
                                if (systemNoteIndex !== -1) {
                                    result = result.substring(0, systemNoteIndex).trim(); // Trim result to just before "[System note"
                                }
                                result = 'Personality: ' + result;

                                // Copy the result to clipboard
                                await navigator.clipboard.writeText(result);
                                alert('Copied to clipboard.\n' + result);
                                button.style.backgroundColor = 'rgba(128, 90, 213, 0.6)';

                            } else {
                                alert('Less than two occurrences of "\'s Persona: " found.');
                                button.style.backgroundColor = 'rgba(128, 90, 213, 0.6)';

                            }
                        } else {
                            alert('No messages found or messages is not an array.');
                            button.style.backgroundColor = 'rgba(128, 90, 213, 0.6)';

                        }
                    } catch (error) {
                        alert('Error parsing JSON: ' + error);
                        button.style.backgroundColor = 'rgba(128, 90, 213, 0.6)';

                    }
                }

                requestCount = 0; // Reset the counter after handling the second request
            }


            return originalFetch(...args); // Proceed with the fetch request
        };
    }

    // Add an event listener for the button click
    button.addEventListener('click', () => {
        requestCount = 0; // Reset counter when button is clicked
        logFetchRequests();
        alert('Send a message or reload previous bot message to obtain description.');
    });

    // Append the button to the body
    document.body.appendChild(button);
})();