# mxchat-basic/2.3.3/js/activation-script.js

MxChat – AI Chatbot &amp; Content Generation for WordPress, version 2.3.3. 224 lines.

- Page: https://pluginprobe.com/plugins/mxchat-basic/2.3.3/code/js/activation-script.js
- Raw: https://pluginprobe.com/plugins/mxchat-basic/2.3.3/raw/js/activation-script.js
- Modified: 2025-07-29T11:58:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/mxchat-basic/2.3.3/code/js/activation-script.js#L10-L20`.

```javascript
/**
 * Enhanced MxChat License Activation JS
 * This handles BOTH local activation AND domain tracking
 * Plus deactivation functionality
 */
jQuery(document).ready(function($) {
    // Get configuration from hidden fields
    const AJAX_URL = $('#mxchat-ajax-url').val() || ajaxurl;
    const NONCE = $('#mxchat-nonce').val();
    const API_URL = $('#mxchat-api-url').val() || 'https://mxchat.ai';
    
    // Elements
    const form = $('#mxchat-activation-form');
    const spinner = $('#mxchat-activation-spinner');
    const submitButton = $('#activate_license_button');
    const licenseStatus = $('#mxchat-license-status');
    
    // Activation handling
    if (form.length && licenseStatus.length && submitButton.length) {
        function handleActivationResponse(response) {
            spinner.hide();
            if (response.success) {
                licenseStatus.text('Active');
                licenseStatus.removeClass('inactive').addClass('active');
                form.hide();
                
                alert('License activated successfully!');
                
                // Track domain on your website
                trackDomainActivation();
                
                setTimeout(function() {
                    location.reload();
                }, 1500);
            } else {
                licenseStatus.text('Inactive');
                alert(response.data || 'Activation failed. Please check your input.');
                submitButton.prop('disabled', false);
            }
        }

        function checkActivationStatus() {
            const email = $('#mxchat_pro_email').val();
            const key = $('#mxchat_activation_key').val();
            
            $.ajax({
                type: 'POST',
                url: AJAX_URL,
                data: {
                    action: 'mxchat_check_license_status',
                    email: email,
                    key: key,
                    security: NONCE
                },
                success: function(response) {
                    if (response.is_active) {
                        licenseStatus.text('Active');
                        licenseStatus.removeClass('inactive').addClass('active');
                        form.hide();
                        alert('Your license has been activated successfully!');
                        
                        trackDomainActivation();
                        
                        setTimeout(function() {
                            location.reload();
                        }, 1500);
                    } else {
                        alert('License activation timed out. Please try again or contact support if the problem persists.');
                        submitButton.prop('disabled', false);
                    }
                },
                error: function() {
                    alert('Unable to verify license status. Please refresh the page to check if activation was successful.');
                    submitButton.prop('disabled', false);
                }
            });
        }

        function trackDomainActivation() {
            $.ajax({
                type: 'POST',
                url: API_URL + '/mxchat-api/activate-license',
                data: {
                    mxchat_pro_email: $('#mxchat_pro_email').val(),
                    mxchat_activation_key: $('#mxchat_activation_key').val(),
                    domain: $('#mxchat_domain').val()
                },
                success: function(response) {
                    //console.log('Domain tracking:', response.success ? 'Success' : 'Failed');
                },
                error: function() {
                    //console.log('Domain tracking: Connection error');
                }
            });
        }

        form.on('submit', function(event) {
            event.preventDefault();
            spinner.show();
            submitButton.prop('disabled', true);
        
            var formData = {
                action: 'mxchat_handle_activate_license',
                mxchat_pro_email: $('#mxchat_pro_email').val(),
                mxchat_activation_key: $('#mxchat_activation_key').val(),
                security: NONCE
            };
        
            $.ajax({
                type: 'POST',
                url: AJAX_URL,
                data: formData,
                timeout: 70000,
                success: function(response) {
                    handleActivationResponse(response);
                },
                error: function(jqXHR, textStatus) {
                    if (textStatus === 'timeout') {
                        spinner.hide();
                        alert('Activation is taking longer than expected. Checking status...');
                        checkActivationStatus();
                    } else {
                        alert('Activation failed due to a server error: ' + (jqXHR.responseText || textStatus));
                        spinner.hide();
                        submitButton.prop('disabled', false);
                    }
                }
            });
        });
    }
    
    // Domain linking for existing activations
    $('#link-domain-button').on('click', function() {
        const button = $(this);
        const status = $('#domain-link-status');
        const originalText = button.text();
        
        button.prop('disabled', true).text('Linking...');
        status.html('<span style="color: #666;">Processing...</span>');
        
        $.ajax({
            type: 'POST',
            url: API_URL + '/mxchat-api/link-domain',
            data: {
                email: $('#mxchat_pro_email').val(),
                license_key: $('#mxchat_activation_key').val(),
                domain: $('#mxchat_domain').val()
            },
            success: function(response) {
                if (response.success) {
                    status.html('<span style="color: green;">✓ Domain linked successfully!</span>');
                    button.hide();
                    
                    setTimeout(function() {
                        location.reload();
                    }, 3000);
                } else {
                    status.html('<span style="color: red;">✗ ' + (response.data || 'Failed to link domain') + '</span>');
                    button.prop('disabled', false).text(originalText);
                }
            },
            error: function(jqXHR, textStatus) {
                status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
                button.prop('disabled', false).text(originalText);
            }
        });
    });
    
    // License deactivation
    $('#deactivate-license-button').on('click', function() {
        const button = $(this);
        const status = $('#deactivate-status');
        const originalText = button.text();
        
        // Confirmation dialog
        const confirmMessage = 'Are you sure you want to deactivate this license?\n\n' +
                             'This will:\n' +
                             '• Disable pro features on this site\n' +
                             '• Unlink this domain from your account\n' +
                             '• Allow you to activate on a different site\n\n' +
                             'You can reactivate anytime with the same license key.';
        
        if (!confirm(confirmMessage)) {
            return;
        }
        
        button.prop('disabled', true).text('Deactivating...');
        status.html('<span style="color: #666;">Processing...</span>');
        
        $.ajax({
            type: 'POST',
            url: AJAX_URL,
            data: {
                action: 'mxchat_deactivate_license',
                security: NONCE
            },
            timeout: 15000,
            success: function(response) {
                if (response.success) {
                    status.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
                    
                    // Show success message
                    alert('License deactivated successfully!\n\nYou can now activate this license on another site.');
                    
                    // Reload page to show deactivated state
                    setTimeout(function() {
                        location.reload();
                    }, 2000);
                } else {
                    status.html('<span style="color: red;">✗ ' + (response.data || 'Deactivation failed') + '</span>');
                    button.prop('disabled', false).text(originalText);
                }
            },
            error: function(jqXHR, textStatus) {
                if (textStatus === 'timeout') {
                    status.html('<span style="color: orange;">⚠ Deactivation timed out. Please check your account dashboard.</span>');
                } else {
                    status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
                }
                button.prop('disabled', false).text(originalText);
            }
        });
    });
});
```
