Spaces:
Running
Running
File size: 7,029 Bytes
2fc5fa6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | // Shared JavaScript across all pages
class SEOAutomaton {
constructor() {
this.isConnected = false;
this.tasks = [];
this.init();
}
init() {
console.log('SEO Automaton Pro initialized');
this.setupEventListeners();
this.simulateRealTimeUpdates();
}
setupEventListeners() {
// WordPress connection handler
const connectBtn = document.querySelector('button[class*="bg-gradient"]');
if (connectBtn) {
connectBtn.addEventListener('click', () => this.handleConnection());
}
// Chat functionality
const chatInput = document.querySelector('input[placeholder*="Ask your SEO agent"]');
const sendBtn = document.querySelector('button[class*="bg-primary"]');
if (sendBtn && chatInput) {
sendBtn.addEventListener('click', () => this.handleChatMessage(chatInput.value));
chatInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.handleChatMessage(chatInput.value);
chatInput.value = '';
}
});
}
}
handleConnection() {
this.isConnected = true;
this.showNotification('Successfully connected to WordPress! Starting SEO automation...', 'success');
// Simulate starting automation tasks
setTimeout(() => {
this.addTask('Site audit initiated', 'Analyzing site structure and content', 'in-progress');
}, 1000);
}
handleChatMessage(message) {
if (!message.trim()) return;
this.addChatMessage(message, 'user');
// Simulate AI response
setTimeout(() => {
const response = this.generateAIResponse(message);
this.addChatMessage(response, 'agent');
}, 1000);
}
addChatMessage(message, sender) {
const chatContainer = document.querySelector('.bg-gray-700.rounded-xl.p-4');
if (!chatContainer) return;
const messageDiv = document.createElement('div');
messageDiv.className = `flex justify-${sender === 'user' ? 'end' : 'start'} mb-4`;
const bubble = document.createElement('div');
bubble.className = sender === 'user'
? 'bg-primary-500 rounded-2xl rounded-tr-none px-4 py-3 max-w-xs';
bubble.innerHTML = `<p class="text-sm">${message}</p>`;
messageDiv.appendChild(bubble);
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
generateAIResponse(message) {
const responses = {
'audit': 'Starting comprehensive SEO audit. This will analyze your site structure, content quality, technical SEO factors, and performance metrics. Results will be available in approximately 2 minutes.',
'performance': 'I\'ll run performance optimization tasks including image compression, CSS/JS minification, and caching improvements.',
'keywords': 'Analyzing your current keyword strategy and identifying new opportunities based on search volume and competition.',
'default': 'I understand your request. Let me process that and provide you with the best optimization strategy for your WordPress site.'
};
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('audit')) return responses.audit;
if (lowerMessage.includes('performance') || lowerMessage.includes('speed')) return responses.performance;
if (lowerMessage.includes('keyword')) return responses.keywords;
return responses.default;
}
addTask(title, description, status = 'queued') {
const tasksContainer = document.querySelector('.space-y-4');
if (!tasksContainer) return;
const taskDiv = document.createElement('div');
const statusColors = {
'completed': 'green',
'in-progress': 'yellow',
'queued': 'blue'
};
taskDiv.className = `bg-gray-700 rounded-xl p-4 border-l-4 border-${statusColors[status]}-500';
taskDiv.innerHTML = `
<div class="flex justify-between items-center">
<span class="font-medium">${title}</span>
<span class="text-xs text-${statusColors[status]}-400 bg-${statusColors[status]}-400/10 px-2 py-1 rounded-full">${status.replace('-', ' ')}</span>
</div>
<p class="text-sm text-gray-400 mt-2">${description}</p>
`;
tasksContainer.appendChild(taskDiv);
this.tasks.push({ title, description, status });
}
simulateRealTimeUpdates() {
// Simulate real-time analytics updates
setInterval(() => {
if (!this.isConnected) return;
const visitorsElement = document.querySelector('.text-2xl.font-bold.text-primary-400');
if (visitorsElement) {
const current = parseInt(visitorsElement.textContent);
const change = Math.floor(Math.random() * 10) - 2;
visitorsElement.textContent = Math.max(800, current + change);
}
}, 5000);
}
showNotification(message, type = 'info') {
// Create notification element
const notification = document.createElement('div');
const bgColor = type === 'success' ? 'bg-green-500' : 'bg-blue-500';
notification.className = `fixed top-4 right-4 ${bgColor} text-white px-6 py-3 rounded-lg shadow-lg transform translate-x-full transition-transform duration-300 z-50';
notification.textContent = message;
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.classList.remove('translate-x-full');
}, 100);
// Remove after 3 seconds
setTimeout(() => {
notification.classList.add('translate-x-full');
setTimeout(() => {
if (notification.parentNode) {
notification.parentNode.removeChild(notification);
}
}, 300);
}, 3000);
}
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.seoAutomaton = new SEOAutomaton();
});
// Utility functions
const utils = {
formatNumber: (num) => {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + 'M';
}
if (num >= 1000) {
return (num / 1000).toFixed(1) + 'K';
}
return num.toString();
},
debounce: (func, wait) => {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
};
console.log('SEO Automaton Pro - AI-powered SEO automation platform loaded'); |