php

add_action('wp_ajax_openai_generate_text', 'openai_generate_text');
add_action('wp_ajax_nopriv_openai_generate_text', 'openai_generate_text');

function openai_generate_text() {
    // Get the type from the AJAX request
    $type = sanitize_text_field($_POST['type']);

    // Adjust the prompt based on the selected type
    $prompt = "";
    if ($type === 'nude') {
        $prompt = "Generate 1 explicit NSFW prompt for an AI girlfriend image generator with a focus on nude images. Format: Character Description, Setting, Additional Details. Use explicit terms like naked, breasts, ass, vagina, etc., to be clear. Use parenthesis occasionally to emphasize specific details like eyes, lips, breasts, etc. Example: Naked woman with long blonde hair, Luxurious Bedroom, (Blue Eyes), (Red Lips), Lying on the bed, Full body, Full view.";
    } elseif ($type === 'porn') {
        $prompt = "Generate 1 explicit NSFW prompt for an AI girlfriend image generator with a focus on pornographic content. Format: Character Description, Setting, Additional Details. Include specific sex positions and poses like doggystyle, missionary, ass on glass, nude orgasm, open legs, cowgirl, masturbation, blowjob, dildo, nude selfie, cum shot, nude in bathtub, cameltoe, etc. Mention if there are multiple characters or specific genders (e.g., man and woman). Use parenthesis occasionally to emphasize specific details like eyes, lips, breasts, etc. Example: Naked woman with long blonde hair, Luxurious Bedroom, (Blue Eyes), (Red Lips), Doggystyle position, Full body, Full view.";
    } else {
        $prompt = "Generate 1 prompt for an AI girlfriend image generator with a focus on normal images. Format: Character Description, Setting, Additional Details. Use parenthesis occasionally to emphasize specific details like eyes, lips, etc. Example: Octoberfest Dirndl Dress, Dark Woods, Campfire, Dark Eyeshadow, Maroon (Red Lipstick), Full body, Full view.";
    }

    // OpenAI API URL and key
    $api_url = 'https://api.openai.com/v1/chat/completions';
    $api_key = 'sk-proj-K9TNRy18puRvh0K8K6NoT3BlbkFJ7SFLE1vrD0sGnMTWU3ut';  // Replace with your actual OpenAI API key

    // Headers for the OpenAI API
    $headers = [
        'Content-Type' => 'application/json',
        'Authorization' => 'Bearer ' . $api_key
    ];

    // Body for the OpenAI API
    $body = [
        'model' => 'gpt-3.5-turbo',
        'messages' => [['role' => 'user', 'content' => $prompt]],
        'temperature' => 0.7
    ];

    // Args for the WordPress HTTP API
    $args = [
        'method' => 'POST',
        'headers' => $headers,
        'body' => json_encode($body),
        'timeout' => 120
    ];

    // Send the request
    $response = wp_remote_request($api_url, $args);

    // Handle the response
    if (is_wp_error($response)) {
        $error_message = $response->get_error_message();
        wp_send_json_error("Something went wrong: $error_message");
    } else {
        $body = wp_remote_retrieve_body($response);
        $data = json_decode($body, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            wp_send_json_error('Invalid JSON in API response');
        } elseif (!isset($data['choices'][0]['message']['content'])) {
            wp_send_json_error('API request failed. Response: ' . $body);
        } else {
            wp_send_json_success($data['choices'][0]['message']['content']);
        }
    }

    // Always die in functions echoing AJAX content
    wp_die();
}

html + java

<!DOCTYPE html>
<html>
<head>
    <title>NSFW Prompt Generation Tool</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@600&display=swap" rel="stylesheet">
    <style>
        /* Basic styles for the text generation tool */
        body {
            font-family: 'Poppins', sans-serif;
        }
        #text-generation-tool {
            width: 100%;
            max-width: 600px;
            margin: 0 auto;
        }

        #type {
            width: 48%;
            padding: 15px;
            margin-bottom: 20px;
            font-size: 16px;
            border-radius: 5px;
            border: 1px solid #ddd;
            display: inline-block;
            vertical-align: top;
            transition: all 0.3s ease;
        }

        #generate-button, #use-prompt-button {
            display: inline-block;
            width: 48%;
            padding: 15px;
            font-size: 14px;
            border: none;
            border-radius: 5px;
            color: #fff;
            cursor: pointer;
            transition: all 0.3s ease;
            font-weight: 600;
            font-family: 'Poppins', sans-serif;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin-bottom: 10px;
        }

        #generate-button {
            background-color: #3498db;
        }

        #generate-button:hover {
            background-color: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
        }

        #use-prompt-button {
            background-color: #2ecc71;
            position: relative;
        }

        #use-prompt-button:hover {
            background-color: #27ae60;
            transform: translateY(-2px);
            box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
        }

        #chat-container {
            padding: 10px;
            height: auto;
            max-height: 150px;
            overflow-y: auto;
            margin-bottom: 20px;
            word-wrap: break-word;
        }

        .prompt-message {
            background-color: #D6DCDF4F;
            border-radius: 8px;
            padding: 10px;
            margin-bottom: 10px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .prompt-message:hover {
            background-color: #c4c9cc;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .action-buttons {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
        }

        .dropdown {
            display: none;
            position: absolute;
            right: 0;
            top: 100%;
            background-color: #fff;
            min-width: 100px;
            height: auto;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
            z-index: 1;
            border-radius: 8px;
            overflow: hidden;
            transition: all 0.3s ease;
        }

        #use-prompt-button:hover .dropdown {
            display: block;
        }

        .dropdown a {
            display: block;
            width: 100%;
            height: 45px;
            background-size: cover;
            background-repeat: no-repeat;
            background-position: center;
            filter: brightness(50%);
            transition: all 0.3s ease;
        }

        .dropdown a.candy-ai {
            background-image: url('https://menprovement.com/wp-content/uploads/2024/05/Candy-AI-Logo-200-x-100.png');
        }

        .dropdown a.nectar-ai {
            background-image: url('https://menprovement.com/wp-content/uploads/2024/05/Nectar-AI-Logo-200-x-100.png');
        }

        .dropdown a.girlfriend-gpt {
            background-image: url('https://menprovement.com/wp-content/uploads/2024/05/GirlfriendGPT-Logo-200-x-100.png');
        }

        .dropdown a:hover {
            filter: brightness(100%);
        }

        /* CSS for the loader */
        .loader {
            display: none;
            margin: 50px auto;
            border: 16px solid #f3f3f3; /* Light grey */
            border-top: 16px solid #3498db; /* Blue */
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        @media (max-width: 768px) {
            #type, #generate-button, #use-prompt-button {
                width: 100%;
                font-size: 14px;
            }

            #generate-button {
                padding: 12px;
            }

            .action-buttons {
                flex-direction: column;
            }

            .dropdown {
                width: 100%;
            }

            .dropdown a {
                height: 60px; /* Increase height for better clickability */
                width: 100%; /* Ensure it spans full width */
            }

            #type {
                padding: 20px; /* Increase padding for better clickability */
                font-size: 18px; /* Increase font size */
            }
        }
    </style>
</head>
<body>
    <div id="text-generation-tool">
        <select id="type">
            <option value="normal">Normal</option>
            <option value="nude">Nude</option>
            <option value="porn">Porn</option>
        </select>
        <button id="generate-button">Generate NSFW prompt</button>
        <div id="chat-container"></div>
        <div class="action-buttons">
            <button id="use-prompt-button">Use Prompt
                <div class="dropdown">
                    <a href="https://menprovement.com/recommends/candy-ai-image-generator/" target="_blank" class="candy-ai"></a>
                    <a href="https://menprovement.com/recommends/nectar-ai-image-generator/" target="_blank" class="nectar-ai"></a>
                    <a href="https://menprovement.com/recommends/girlfriend-gpt/" target="_blank" class="girlfriend-gpt"></a>
                </div>
            </button>
        </div>
        <div id="loading" class="loader"></div>
    </div>

    <script>
        document.getElementById("generate-button").addEventListener("click", function(e){
            e.preventDefault();

            var type = document.getElementById('type').value;
            var chatContainer = document.getElementById('chat-container');
            var loading = document.getElementById('loading');

            // Clear the chat container before adding new content
            chatContainer.innerHTML = '';

            loading.style.display = 'block';

            var formData = new FormData();
            formData.append('action', 'openai_generate_text');
            formData.append('type', type);

            fetch('/wp-admin/admin-ajax.php', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                loading.style.display = 'none';
                if(data.success) {
                    var message = document.createElement('div');
                    message.textContent = data.data;
                    message.className = 'prompt-message';
                    chatContainer.appendChild(message);

                    // Add click event to copy the prompt
                    message.addEventListener('click', function() {
                        var textArea = document.createElement('textarea');
                        textArea.value = this.textContent;
                        document.body.appendChild(textArea);
                        textArea.select();
                        document.execCommand('copy');
                        document.body.removeChild(textArea);
                        alert('Copied to clipboard!');
                    });
                } else {
                    alert('An error occurred: ' + data.data);
                }
            })
            .catch(error => {
                loading.style.display = 'none';
                alert('An error occurred: ' + error.message);
            });
        });
    </script>
</body>
</html>