mirror of
https://github.com/WenPai-org/wpban.git
synced 2025-08-04 20:55:15 +08:00
完全重写
This commit is contained in:
parent
fa7b00b4f5
commit
0ae1b5b593
13 changed files with 4657 additions and 78 deletions
537
assets/admin.css
Normal file
537
assets/admin.css
Normal file
|
@ -0,0 +1,537 @@
|
|||
/* WPBan Pro Admin Styles - WordPress Native Experience */
|
||||
|
||||
.wpban-wrap {
|
||||
margin-top: 20px;
|
||||
max-width: 1400px;
|
||||
}
|
||||
|
||||
/* Dashboard Grid */
|
||||
.wpban-dashboard {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.wpban-stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.wpban-stat-card {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
|
||||
position: relative;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.wpban-stat-card:hover {
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.wpban-stat-card h3 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #1d2327;
|
||||
}
|
||||
|
||||
.wpban-stat-number {
|
||||
font-size: 36px;
|
||||
font-weight: 300;
|
||||
color: #2271b1;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.wpban-stat-trend {
|
||||
margin-top: 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.wpban-stat-trend .up {
|
||||
color: #d63638;
|
||||
}
|
||||
|
||||
.wpban-stat-trend .down {
|
||||
color: #00a32a;
|
||||
}
|
||||
|
||||
/* Grid Layout */
|
||||
.wpban-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 20px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.wpban-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.wpban-card {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
|
||||
}
|
||||
|
||||
.wpban-card h2 {
|
||||
margin: 0 0 15px 0;
|
||||
font-size: 1.3em;
|
||||
font-weight: 600;
|
||||
color: #1d2327;
|
||||
}
|
||||
|
||||
.wpban-card h3 {
|
||||
margin: 20px 0 10px 0;
|
||||
font-size: 1.1em;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
.wpban-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 20px 0;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* Bypass URL */
|
||||
.wpban-bypass-url {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.wpban-bypass-url label {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.wpban-input-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.wpban-input-group input {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* Templates Grid */
|
||||
.wpban-templates-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.wpban-template-card {
|
||||
background: #f6f7f7;
|
||||
border: 1px solid #dcdcde;
|
||||
padding: 20px;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.wpban-template-card:hover {
|
||||
background: #fff;
|
||||
border-color: #2271b1;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.wpban-template-card h3 {
|
||||
margin: 0 0 10px 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.wpban-template-card p {
|
||||
margin: 0 0 15px 0;
|
||||
color: #50575e;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.wpban-tabs {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: none;
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
border-top: none;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.tab-content h2 {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
/* Crawler Controls */
|
||||
.wpban-crawler-controls {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* Crawler Grid */
|
||||
.wpban-crawler-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.wpban-crawler-item {
|
||||
display: block;
|
||||
padding: 12px;
|
||||
background: #f6f7f7;
|
||||
border: 1px solid #dcdcde;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.wpban-crawler-item:hover {
|
||||
background: #fff;
|
||||
border-color: #2271b1;
|
||||
}
|
||||
|
||||
.wpban-crawler-item input[type="checkbox"] {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.wpban-crawler-name {
|
||||
font-weight: 600;
|
||||
display: inline-block;
|
||||
margin-right: 8px;
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.wpban-crawler-desc {
|
||||
font-size: 12px;
|
||||
color: #50575e;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
/* Notices */
|
||||
.wpban-notice {
|
||||
padding: 12px;
|
||||
margin: 15px 0;
|
||||
border-left: 4px solid;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.wpban-notice-warning {
|
||||
border-left-color: #f0b849;
|
||||
background-color: #fef8ee;
|
||||
}
|
||||
|
||||
.wpban-notice-warning p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Logs */
|
||||
.wpban-logs-filters {
|
||||
background: #fff;
|
||||
border: 1px solid #c3c4c7;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.wpban-logs-filters form {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.wpban-logs-filters input[type="date"],
|
||||
.wpban-logs-filters input[type="text"],
|
||||
.wpban-logs-filters select {
|
||||
height: 30px;
|
||||
line-height: 28px;
|
||||
}
|
||||
|
||||
/* Badges */
|
||||
.wpban-badge {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
border-radius: 3px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.wpban-badge-banned {
|
||||
background: #d63638;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.wpban-badge-blocked {
|
||||
background: #f0b849;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.wpban-badge-failed_login {
|
||||
background: #dba617;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.wpban-badge-bypass {
|
||||
background: #00a32a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
/* Truncate */
|
||||
.wpban-truncate {
|
||||
display: inline-block;
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* Country Selector */
|
||||
.wpban-country-selector select {
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Rate Limit Settings */
|
||||
.form-table input[type="number"] {
|
||||
width: 80px;
|
||||
}
|
||||
|
||||
/* Tools Grid */
|
||||
.wpban-tools-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
/* Chart Container */
|
||||
#wpban-country-chart {
|
||||
max-height: 300px;
|
||||
}
|
||||
|
||||
/* Activity List */
|
||||
.wpban-activity-list {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.wpban-activity-list li {
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f0f0f1;
|
||||
}
|
||||
|
||||
.wpban-activity-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
/* Form Elements */
|
||||
.form-table textarea.code {
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* Pagination */
|
||||
.tablenav-pages {
|
||||
margin: 20px 0;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.tablenav-pages .pagination-links {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tablenav-pages a,
|
||||
.tablenav-pages span {
|
||||
display: inline-block;
|
||||
padding: 3px 8px;
|
||||
margin: 0 2px;
|
||||
background: #f6f7f7;
|
||||
border: 1px solid #dcdcde;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.tablenav-pages .current {
|
||||
background: #2271b1;
|
||||
color: #fff;
|
||||
border-color: #2271b1;
|
||||
}
|
||||
|
||||
/* Responsive Tables */
|
||||
@media (max-width: 782px) {
|
||||
.wp-list-table {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
|
||||
.wpban-stats-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.wpban-templates-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.wpban-crawler-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.wpban-tools-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.wpban-logs-filters form {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.wpban-logs-filters input,
|
||||
.wpban-logs-filters select,
|
||||
.wpban-logs-filters button {
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loading States */
|
||||
.wpban-loading {
|
||||
opacity: 0.6;
|
||||
pointer-events: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.wpban-loading::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin: -10px 0 0 -10px;
|
||||
border: 2px solid #f3f3f3;
|
||||
border-top: 2px solid #2271b1;
|
||||
border-radius: 50%;
|
||||
animation: wpban-spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes wpban-spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.button.button-small {
|
||||
padding: 0 8px;
|
||||
line-height: 26px;
|
||||
height: 28px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* WP Editor in Settings */
|
||||
.tab-content .wp-editor-wrap {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* Empty States */
|
||||
.wpban-empty-state {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
color: #646970;
|
||||
}
|
||||
|
||||
.wpban-empty-state p {
|
||||
font-size: 16px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Success/Error Messages */
|
||||
.wpban-message {
|
||||
padding: 12px;
|
||||
margin: 15px 0;
|
||||
border-left: 4px solid;
|
||||
background: #fff;
|
||||
animation: wpban-fade-in 0.3s ease;
|
||||
}
|
||||
|
||||
.wpban-message.success {
|
||||
border-left-color: #00a32a;
|
||||
background-color: #f0f8f0;
|
||||
}
|
||||
|
||||
.wpban-message.error {
|
||||
border-left-color: #d63638;
|
||||
background-color: #fef1f1;
|
||||
}
|
||||
|
||||
@keyframes wpban-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Row Actions */
|
||||
.row-actions {
|
||||
font-size: 12px;
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.row-actions a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Status Indicators */
|
||||
.wpban-status {
|
||||
display: inline-block;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.wpban-status.active {
|
||||
background: #00a32a;
|
||||
}
|
||||
|
||||
.wpban-status.inactive {
|
||||
background: #787c82;
|
||||
}
|
||||
|
||||
/* Code Preview */
|
||||
.wpban-code-preview {
|
||||
background: #f6f7f7;
|
||||
border: 1px solid #dcdcde;
|
||||
padding: 15px;
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
font-size: 13px;
|
||||
overflow-x: auto;
|
||||
white-space: pre;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
335
assets/admin.js
Normal file
335
assets/admin.js
Normal file
|
@ -0,0 +1,335 @@
|
|||
/**
|
||||
* WPBan Pro Admin JavaScript
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
// Tab Navigation
|
||||
$(document).on('click', '.nav-tab', function(e) {
|
||||
e.preventDefault();
|
||||
const target = $(this).attr('href');
|
||||
|
||||
$('.nav-tab').removeClass('nav-tab-active');
|
||||
$(this).addClass('nav-tab-active');
|
||||
|
||||
$('.tab-content').removeClass('active');
|
||||
$(target).addClass('active');
|
||||
|
||||
// Save active tab to localStorage
|
||||
localStorage.setItem('wpban_active_tab', target);
|
||||
});
|
||||
|
||||
// Restore active tab
|
||||
$(document).ready(function() {
|
||||
const activeTab = localStorage.getItem('wpban_active_tab');
|
||||
if (activeTab && $(activeTab).length) {
|
||||
$('.nav-tab[href="' + activeTab + '"]').trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
// Settings Form Handler
|
||||
$('#wpban-settings-form').on('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const $form = $(this);
|
||||
const $button = $('#wpban-save-settings');
|
||||
const $spinner = $button.next('.spinner');
|
||||
|
||||
$button.prop('disabled', true);
|
||||
$spinner.addClass('is-active');
|
||||
|
||||
$.ajax({
|
||||
url: wpban.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wpban_save_settings',
|
||||
settings: $form.serialize(),
|
||||
_ajax_nonce: $('#wpban_nonce').val()
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', response.data.message);
|
||||
} else {
|
||||
showMessage('error', response.data || wpban.i18n.error);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
showMessage('error', wpban.i18n.error);
|
||||
},
|
||||
complete: function() {
|
||||
$button.prop('disabled', false);
|
||||
$spinner.removeClass('is-active');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Apply Template
|
||||
window.wpbanApplyTemplate = function(templateId) {
|
||||
if (!confirm(wpban.i18n.confirm_template)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(wpban.ajax_url, {
|
||||
action: 'wpban_apply_template',
|
||||
template: templateId,
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', response.data.message);
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
} else {
|
||||
showMessage('error', response.data || wpban.i18n.error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Copy Text to Clipboard
|
||||
window.wpbanCopyText = function(text) {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
showMessage('success', 'Copied to clipboard!');
|
||||
}).catch(() => {
|
||||
// Fallback for older browsers
|
||||
const $temp = $('<input>');
|
||||
$('body').append($temp);
|
||||
$temp.val(text).select();
|
||||
document.execCommand('copy');
|
||||
$temp.remove();
|
||||
showMessage('success', 'Copied to clipboard!');
|
||||
});
|
||||
};
|
||||
|
||||
// Crawler Selection
|
||||
window.wpbanSelectCrawlers = function(type, select) {
|
||||
if (type === 'all') {
|
||||
$('.wpban-crawler-item input').prop('checked', select);
|
||||
} else {
|
||||
$(`.wpban-crawler-item[data-type="${type}"] input`).prop('checked', select);
|
||||
}
|
||||
};
|
||||
|
||||
// Export Logs
|
||||
window.wpbanExportLogs = function() {
|
||||
window.location.href = wpban.ajax_url + '?action=wpban_export_logs&_ajax_nonce=' + wpban.nonce;
|
||||
};
|
||||
|
||||
// Clear Logs
|
||||
window.wpbanClearLogs = function() {
|
||||
if (!confirm(wpban.i18n.confirm_clear)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(wpban.ajax_url, {
|
||||
action: 'wpban_clear_logs',
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', response.data.message);
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Test Email
|
||||
window.wpbanTestEmail = function() {
|
||||
const $button = event.target;
|
||||
$button.disabled = true;
|
||||
|
||||
$.post(wpban.ajax_url, {
|
||||
action: 'wpban_test_email',
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', response.data.message);
|
||||
} else {
|
||||
showMessage('error', response.data || wpban.i18n.error);
|
||||
}
|
||||
}).always(function() {
|
||||
$button.disabled = false;
|
||||
});
|
||||
};
|
||||
|
||||
// Export Settings
|
||||
window.wpbanExportSettings = function() {
|
||||
$.get(wpban.ajax_url, {
|
||||
action: 'wpban_export_settings',
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
const blob = new Blob([response.data], {type: 'application/json'});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'wpban-settings-' + new Date().toISOString().split('T')[0] + '.json';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Optimize Database
|
||||
window.wpbanOptimizeDatabase = function() {
|
||||
const $button = event.target;
|
||||
$button.disabled = true;
|
||||
|
||||
$.post(wpban.ajax_url, {
|
||||
action: 'wpban_optimize_database',
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', 'Database optimized successfully!');
|
||||
}
|
||||
}).always(function() {
|
||||
$button.disabled = false;
|
||||
});
|
||||
};
|
||||
|
||||
// Clear Old Logs
|
||||
window.wpbanClearOldLogs = function() {
|
||||
if (!confirm('This will permanently delete all logs older than 30 days. Continue?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$.post(wpban.ajax_url, {
|
||||
action: 'wpban_clear_old_logs',
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
showMessage('success', response.data.message);
|
||||
setTimeout(() => location.reload(), 1500);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Live Search for Crawlers
|
||||
let searchTimeout;
|
||||
$(document).on('input', '#wpban-crawler-search', function() {
|
||||
const query = $(this).val().toLowerCase();
|
||||
clearTimeout(searchTimeout);
|
||||
|
||||
searchTimeout = setTimeout(() => {
|
||||
$('.wpban-crawler-item').each(function() {
|
||||
const $item = $(this);
|
||||
const text = $item.text().toLowerCase();
|
||||
$item.toggle(text.indexOf(query) > -1);
|
||||
});
|
||||
}, 300);
|
||||
});
|
||||
|
||||
// Real-time Log Updates (optional)
|
||||
if ($('#wpban-logs-container').length) {
|
||||
// Auto-refresh logs every 30 seconds
|
||||
setInterval(function() {
|
||||
if (document.visibilityState === 'visible') {
|
||||
refreshLogs();
|
||||
}
|
||||
}, 30000);
|
||||
}
|
||||
|
||||
function refreshLogs() {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
|
||||
$.get(wpban.ajax_url, {
|
||||
action: 'wpban_get_logs',
|
||||
page: params.get('paged') || 1,
|
||||
date_from: params.get('date_from'),
|
||||
date_to: params.get('date_to'),
|
||||
action_filter: params.get('action_filter'),
|
||||
ip_filter: params.get('ip_filter'),
|
||||
_ajax_nonce: wpban.nonce
|
||||
}, function(response) {
|
||||
if (response.success) {
|
||||
$('#wpban-logs-container tbody').html(response.data.html);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Show Message
|
||||
function showMessage(type, message) {
|
||||
const $message = $('<div>')
|
||||
.addClass('wpban-message ' + type)
|
||||
.text(message)
|
||||
.prependTo('.wpban-wrap')
|
||||
.hide()
|
||||
.fadeIn();
|
||||
|
||||
setTimeout(() => {
|
||||
$message.fadeOut(() => $message.remove());
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Geo Blocking Mode Toggle
|
||||
$('input[name="settings[geo_blocking][mode]"]').on('change', function() {
|
||||
const mode = $(this).val();
|
||||
const $label = $('.wpban-country-selector').prev('th').find('label');
|
||||
|
||||
if (mode === 'whitelist') {
|
||||
$label.text('Allowed Countries');
|
||||
} else {
|
||||
$label.text('Blocked Countries');
|
||||
}
|
||||
});
|
||||
|
||||
// Initialize Select2 for country selector (if available)
|
||||
if ($.fn.select2) {
|
||||
$('.wpban-country-selector select').select2({
|
||||
placeholder: 'Select countries...',
|
||||
width: '100%'
|
||||
});
|
||||
}
|
||||
|
||||
// Handle browser restrictions toggle
|
||||
$('input[name="settings[browser_restrictions][wechat_qq][enabled]"]').on('change', function() {
|
||||
const $fields = $(this).closest('table').find('tr').not(':first');
|
||||
$fields.toggle($(this).is(':checked'));
|
||||
}).trigger('change');
|
||||
|
||||
// Email notifications toggle
|
||||
$('input[name="settings[email_notifications][enabled]"]').on('change', function() {
|
||||
const $fields = $(this).closest('table').find('tr').not(':first');
|
||||
$fields.toggle($(this).is(':checked'));
|
||||
}).trigger('change');
|
||||
|
||||
// Geo blocking toggle
|
||||
$('input[name="settings[geo_blocking][enabled]"]').on('change', function() {
|
||||
const $fields = $(this).closest('table').find('tr').not(':first');
|
||||
$fields.toggle($(this).is(':checked'));
|
||||
}).trigger('change');
|
||||
|
||||
// Keyboard shortcuts
|
||||
$(document).on('keydown', function(e) {
|
||||
// Ctrl/Cmd + S to save
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
||||
e.preventDefault();
|
||||
$('#wpban-save-settings').trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
// Tooltip initialization
|
||||
$('.wpban-tooltip').tooltip({
|
||||
position: {
|
||||
my: 'center bottom-10',
|
||||
at: 'center top'
|
||||
}
|
||||
});
|
||||
|
||||
// Confirm before leaving with unsaved changes
|
||||
let formChanged = false;
|
||||
$('#wpban-settings-form').on('change', 'input, select, textarea', function() {
|
||||
formChanged = true;
|
||||
});
|
||||
|
||||
window.addEventListener('beforeunload', function(e) {
|
||||
if (formChanged) {
|
||||
e.preventDefault();
|
||||
e.returnValue = 'You have unsaved changes. Are you sure you want to leave?';
|
||||
}
|
||||
});
|
||||
|
||||
$('#wpban-save-settings').on('click', function() {
|
||||
formChanged = false;
|
||||
});
|
||||
|
||||
})(jQuery);
|
Loading…
Add table
Add a link
Reference in a new issue