PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.12
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.12
2.7.0 2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 All 139 releases
metasync / views / js / metasync-bot-statistics.js

metasync-bot-statistics.js in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.12, at views/js/metasync-bot-statistics.js

88 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global metasyncBotStatsData, jQuery, ajaxurl */
2 /**
3 * MetaSync Bot Statistics
4 *
5 * Extracted for Phase 5, #887.
6 * Copy-to-clipboard and reset bot statistics functionality.
7 *
8 * Localized object: metasyncBotStatsData
9 * - resetNonce (string)
10 *
11 * @since Phase 5
12 */
13 jQuery(document).ready(function ($) {
14 var resetNonce = metasyncBotStatsData.resetNonce;
15
16 // Copy button functionality
17 $('.copy-btn').on('click', function (e) {
18 e.preventDefault();
19 e.stopPropagation();
20
21 var $btn = $(this);
22 var textToCopy = $btn.data('copy');
23
24 function showSuccess() {
25 $btn.addClass('copied');
26 $btn.find('.copy-tooltip').text('Copied!');
27 setTimeout(function () {
28 $btn.removeClass('copied');
29 $btn.find('.copy-tooltip').text('Copy');
30 }, 2000);
31 }
32
33 if (navigator.clipboard && navigator.clipboard.writeText) {
34 navigator.clipboard.writeText(textToCopy).then(function () {
35 showSuccess();
36 }).catch(function () {
37 fallbackCopy(textToCopy, $btn, showSuccess);
38 });
39 } else {
40 fallbackCopy(textToCopy, $btn, showSuccess);
41 }
42 });
43
44 function fallbackCopy(text, $btn, successCallback) {
45 var $temp = $('<textarea>');
46 $temp.css({ position: 'absolute', left: '-9999px' });
47 $('body').append($temp);
48 $temp.val(text).select();
49 try {
50 document.execCommand('copy');
51 successCallback();
52 } catch (err) {
53 alert('Failed to copy. Please copy manually.');
54 }
55 $temp.remove();
56 }
57
58 $('#reset-bot-stats').on('click', function (e) {
59 e.preventDefault();
60
61 if (!confirm('Are you sure you want to reset all bot detection statistics? This action cannot be undone.')) {
62 return;
63 }
64
65 var $button = $(this);
66 var originalText = $button.html();
67
68 $button.prop('disabled', true).html('\u231B Resetting...');
69
70 $.post(ajaxurl, {
71 action: 'metasync_reset_bot_stats',
72 nonce: resetNonce
73 })
74 .done(function (response) {
75 if (response.success) {
76 location.reload();
77 } else {
78 alert('Error: ' + (response.data ? response.data.message : 'Unknown error'));
79 $button.prop('disabled', false).html(originalText);
80 }
81 })
82 .fail(function () {
83 alert('Network error while resetting statistics');
84 $button.prop('disabled', false).html(originalText);
85 });
86 });
87 });
88