| 1 |
/* global jQuery, ajaxurl, metasyncBingConsoleData */ |
| 2 |
/** |
| 3 |
* MetaSync Bing IndexNow console. |
| 4 |
* |
| 5 |
* Extracted from views/metasync-bing-console.php (Phase 5, #887). |
| 6 |
*/ |
| 7 |
jQuery(document).ready(function ($) { |
| 8 |
$('#metasync-bing-response').hide(); |
| 9 |
|
| 10 |
$('#metasync-bing-btn-send').on('click', function () { |
| 11 |
const $button = $(this); |
| 12 |
const $url = $('#metasync-bing-url'); |
| 13 |
const $response = $('#metasync-bing-response'); |
| 14 |
const originalText = $button.html(); |
| 15 |
|
| 16 |
// Validate URLs |
| 17 |
if (!$url.val().trim()) { |
| 18 |
alert('Please enter at least one URL to submit.'); |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
// Disable button and show loading state |
| 23 |
$button.html('🔄 Submitting...').prop('disabled', true); |
| 24 |
|
| 25 |
// Make AJAX request |
| 26 |
jQuery.ajax({ |
| 27 |
method: 'POST', |
| 28 |
url: ajaxurl, |
| 29 |
data: { |
| 30 |
action: 'metasync_send_bing_indexnow', |
| 31 |
nonce: metasyncBingConsoleData.nonce, |
| 32 |
metasync_bing_url: $url.val() |
| 33 |
} |
| 34 |
}) |
| 35 |
.done(function (response) { |
| 36 |
$response.show(); |
| 37 |
|
| 38 |
// Parse response |
| 39 |
const urls = $url.val().split('\n').filter(Boolean); |
| 40 |
const urlsDisplay = urls.length > 1 ? urls.length + ' URLs submitted' : urls[0]; |
| 41 |
|
| 42 |
$('.result-urls').empty().append($('<strong>').text('Submitted:')).append(document.createTextNode(' ' + urlsDisplay)); |
| 43 |
|
| 44 |
if (response.success) { |
| 45 |
$('.result-status-code').text('� |
| 46 |
Success').css('color', '#4caf50'); |
| 47 |
$('.result-message').text(response.message || 'URLs successfully submitted to IndexNow.'); |
| 48 |
} else { |
| 49 |
$('.result-status-code').text('❌ Error').css('color', '#f44336'); |
| 50 |
$('.result-message').text(response.message || 'Failed to submit URLs. Please check your API key configuration.'); |
| 51 |
} |
| 52 |
|
| 53 |
// Show response details if available |
| 54 |
if (response.response_code) { |
| 55 |
var $msg = $('.result-message'); |
| 56 |
$msg.text($msg.text() + ' Response Code: ' + response.response_code); |
| 57 |
} |
| 58 |
}) |
| 59 |
.fail(function (xhr, status, error) { |
| 60 |
$response.show(); |
| 61 |
$('.result-urls').empty().append($('<strong>').text('Error')); |
| 62 |
$('.result-status-code').text('❌ Request Failed').css('color', '#f44336'); |
| 63 |
$('.result-message').text('Network error: ' + error); |
| 64 |
}) |
| 65 |
.always(function () { |
| 66 |
// Re-enable button |
| 67 |
$button.html(originalText).prop('disabled', false); |
| 68 |
}); |
| 69 |
}); |
| 70 |
}); |
| 71 |
|