Initial commit
This commit is contained in:
@@ -0,0 +1,724 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Viral Velocity - AI Image Scorer</title>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
min-height: 100vh;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 10px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.header p {
|
||||
font-size: 1.1rem;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
.upload-section {
|
||||
background: #f8f9fa;
|
||||
border-radius: 15px;
|
||||
padding: 30px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.upload-area {
|
||||
border: 3px dashed #667eea;
|
||||
border-radius: 15px;
|
||||
padding: 40px;
|
||||
margin: 20px 0;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.upload-area:hover {
|
||||
border-color: #764ba2;
|
||||
background: #f0f2ff;
|
||||
}
|
||||
|
||||
.upload-area.dragover {
|
||||
border-color: #764ba2;
|
||||
background: #e8ecff;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 3rem;
|
||||
color: #667eea;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
font-size: 1.2rem;
|
||||
color: #666;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.upload-hint {
|
||||
font-size: 0.9rem;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.preferences-section {
|
||||
background: #f8f9fa;
|
||||
border-radius: 15px;
|
||||
padding: 30px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.preferences-section h3 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.preferences-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.preference-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.preference-group label {
|
||||
font-weight: 600;
|
||||
color: #555;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.preference-group select {
|
||||
padding: 12px;
|
||||
border: 2px solid #e1e5e9;
|
||||
border-radius: 8px;
|
||||
font-size: 1rem;
|
||||
background: white;
|
||||
transition: border-color 0.3s ease;
|
||||
}
|
||||
|
||||
.preference-group select:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.analyze-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 15px 40px;
|
||||
border-radius: 10px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.analyze-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.analyze-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.loading {
|
||||
display: none;
|
||||
text-align: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-top: 4px solid #667eea;
|
||||
border-radius: 50%;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto 15px;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
.results-section {
|
||||
display: none;
|
||||
background: #f8f9fa;
|
||||
border-radius: 15px;
|
||||
padding: 30px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.score-display {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.final-score {
|
||||
font-size: 4rem;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.score-label {
|
||||
font-size: 1.2rem;
|
||||
color: #666;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.score-breakdown {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.score-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.score-card h4 {
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.score-value {
|
||||
font-size: 2rem;
|
||||
font-weight: 700;
|
||||
color: #667eea;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.score-details {
|
||||
font-size: 0.9rem;
|
||||
color: #666;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.recommendations {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.recommendations h4 {
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.recommendation-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.recommendation-list li {
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid #eee;
|
||||
color: #555;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.recommendation-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.recommendation-list li:before {
|
||||
content: "💡 ";
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.error {
|
||||
background: #ffe6e6;
|
||||
color: #d63031;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
border-left: 4px solid #d63031;
|
||||
}
|
||||
|
||||
.success {
|
||||
background: #e6ffe6;
|
||||
color: #00b894;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin: 20px 0;
|
||||
border-left: 4px solid #00b894;
|
||||
}
|
||||
|
||||
.rejection-card {
|
||||
background: #fff5f5;
|
||||
border: 2px solid #e74c3c;
|
||||
border-left: 4px solid #e74c3c;
|
||||
}
|
||||
|
||||
.rejection-card h4 {
|
||||
color: #e74c3c;
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.rejection-message {
|
||||
color: #c0392b;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.rejection-message p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
.rejection-message strong {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.rejection-message em {
|
||||
font-style: italic;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.risk-analysis-card {
|
||||
background: #f8f9fa;
|
||||
border: 2px solid #6c757d;
|
||||
border-left: 4px solid #6c757d;
|
||||
}
|
||||
|
||||
.risk-analysis-card h4 {
|
||||
color: #495057;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.risk-scores {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.risk-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background: white;
|
||||
border-left: 4px solid #dee2e6;
|
||||
}
|
||||
|
||||
.risk-item.high-risk {
|
||||
background: #fff5f5;
|
||||
border-left-color: #e74c3c;
|
||||
}
|
||||
|
||||
.risk-item.medium-risk {
|
||||
background: #fffbf0;
|
||||
border-left-color: #f39c12;
|
||||
}
|
||||
|
||||
.risk-item.low-risk {
|
||||
background: #f0fff4;
|
||||
border-left-color: #27ae60;
|
||||
}
|
||||
|
||||
.risk-icon {
|
||||
font-size: 1.2rem;
|
||||
margin-right: 10px;
|
||||
width: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.risk-name {
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.risk-score {
|
||||
font-weight: 700;
|
||||
margin: 0 10px;
|
||||
color: #495057;
|
||||
}
|
||||
|
||||
.risk-level {
|
||||
font-size: 0.9rem;
|
||||
color: #6c757d;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.violations-section {
|
||||
margin-top: 20px;
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.violations-section h5 {
|
||||
color: #e74c3c;
|
||||
margin-bottom: 10px;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.violations-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.violations-list li {
|
||||
padding: 8px 0;
|
||||
color: #c0392b;
|
||||
border-bottom: 1px solid #f8d7da;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.violations-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.violations-list li:before {
|
||||
content: "⚠️ ";
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.enhancement-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 15px 30px;
|
||||
border-radius: 10px;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
margin: 20px 0;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
|
||||
}
|
||||
|
||||
.enhancement-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.enhancement-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.enhancement-section {
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.enhancement-section h3 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
font-size: 1.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.enhancement-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
background: #f8f9fa;
|
||||
border: 2px solid #dee2e6;
|
||||
color: #495057;
|
||||
padding: 10px 15px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.nav-btn:hover:not(:disabled) {
|
||||
background: #e9ecef;
|
||||
border-color: #adb5bd;
|
||||
}
|
||||
|
||||
.nav-btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.enhancement-counter {
|
||||
font-weight: 600;
|
||||
color: #495057;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.enhancement-display {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.original-image, .enhanced-image {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.original-image h4, .enhanced-image h4 {
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
.comparison-img {
|
||||
max-width: 100%;
|
||||
max-height: 300px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.enhancement-actions {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
padding: 12px 25px;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.reject-btn {
|
||||
background: #e74c3c;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.reject-btn:hover {
|
||||
background: #c0392b;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.save-btn {
|
||||
background: #27ae60;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.save-btn:hover {
|
||||
background: #229954;
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.enhancement-prompt {
|
||||
background: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
border-left: 4px solid #667eea;
|
||||
}
|
||||
|
||||
.enhancement-prompt h5 {
|
||||
color: #333;
|
||||
margin-bottom: 10px;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.enhancement-prompt p {
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.header h1 {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.main-content {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.preferences-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.score-breakdown {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.risk-item {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.risk-score, .risk-level {
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.risk-scores {
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.enhancement-display {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.enhancement-actions {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
width: 100%;
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.enhancement-controls {
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 12px 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1><i class="fas fa-rocket"></i> Viral Velocity</h1>
|
||||
<p>AI-Powered Social Media Image Scoring with Personalization</p>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div class="upload-section">
|
||||
<h3><i class="fas fa-upload"></i> Upload Your Image</h3>
|
||||
<div class="upload-area" id="uploadArea">
|
||||
<div class="upload-icon">
|
||||
<i class="fas fa-cloud-upload-alt"></i>
|
||||
</div>
|
||||
<div class="upload-text">Click to upload or drag and drop</div>
|
||||
<div class="upload-hint">Supports JPG, PNG, GIF (Max 10MB)</div>
|
||||
<input type="file" id="imageInput" accept="image/*" style="display: none;">
|
||||
</div>
|
||||
<div id="imagePreview" style="display: none; margin-top: 20px;">
|
||||
<img id="previewImg" style="max-width: 300px; max-height: 300px; border-radius: 10px;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="preferences-section">
|
||||
<h3><i class="fas fa-cog"></i> Personalization Preferences</h3>
|
||||
<div class="preferences-grid">
|
||||
<div class="preference-group">
|
||||
<label for="aesthetic">Aesthetic Style</label>
|
||||
<select id="aesthetic">
|
||||
<option value="">Select Aesthetic</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="preference-group">
|
||||
<label for="niche">Content Niche</label>
|
||||
<select id="niche">
|
||||
<option value="">Select Niche</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="preference-group">
|
||||
<label for="targetAudience">Target Audience</label>
|
||||
<select id="targetAudience">
|
||||
<option value="">Select Audience</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="preference-group">
|
||||
<label for="contentType">Content Type</label>
|
||||
<select id="contentType">
|
||||
<option value="">Select Content Type</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="preference-group">
|
||||
<label for="brandVoice">Brand Voice</label>
|
||||
<select id="brandVoice">
|
||||
<option value="">Select Brand Voice</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<button class="analyze-btn" id="analyzeBtn" disabled>
|
||||
<i class="fas fa-magic"></i> Analyze Image
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Analyzing your image with AI...</p>
|
||||
</div>
|
||||
|
||||
<div class="results-section" id="resultsSection">
|
||||
<div class="score-display">
|
||||
<div class="final-score" id="finalScore">0</div>
|
||||
<div class="score-label">Viral Velocity Score</div>
|
||||
</div>
|
||||
|
||||
<div class="score-breakdown" id="scoreBreakdown">
|
||||
<!-- Score cards will be inserted here -->
|
||||
</div>
|
||||
|
||||
<div class="recommendations">
|
||||
<h4><i class="fas fa-lightbulb"></i> Recommendations</h4>
|
||||
<ul class="recommendation-list" id="recommendationList">
|
||||
<!-- Recommendations will be inserted here -->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,699 @@
|
||||
// API Configuration
|
||||
const API_BASE_URL = window.location.origin;
|
||||
|
||||
// DOM Elements
|
||||
const uploadArea = document.getElementById('uploadArea');
|
||||
const imageInput = document.getElementById('imageInput');
|
||||
const imagePreview = document.getElementById('imagePreview');
|
||||
const previewImg = document.getElementById('previewImg');
|
||||
const analyzeBtn = document.getElementById('analyzeBtn');
|
||||
const loading = document.getElementById('loading');
|
||||
const resultsSection = document.getElementById('resultsSection');
|
||||
|
||||
// Preference selectors
|
||||
const aestheticSelect = document.getElementById('aesthetic');
|
||||
const nicheSelect = document.getElementById('niche');
|
||||
const targetAudienceSelect = document.getElementById('targetAudience');
|
||||
const contentTypeSelect = document.getElementById('contentType');
|
||||
const brandVoiceSelect = document.getElementById('brandVoice');
|
||||
|
||||
// State
|
||||
let selectedImage = null;
|
||||
let preferences = null;
|
||||
let enhancedImages = [];
|
||||
let currentEnhancementIndex = 0;
|
||||
|
||||
// Initialize the application
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
loadPreferences();
|
||||
setupEventListeners();
|
||||
});
|
||||
|
||||
// Load available preferences from API
|
||||
async function loadPreferences() {
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/available-preferences`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
populateSelects(data);
|
||||
} else {
|
||||
showError('Failed to load preferences. Make sure the API server is running.');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading preferences:', error);
|
||||
showError('Failed to connect to API server. Please start the server with: python api.py');
|
||||
}
|
||||
}
|
||||
|
||||
// Populate preference dropdowns
|
||||
function populateSelects(data) {
|
||||
// Populate aesthetics
|
||||
data.aesthetics.forEach(aesthetic => {
|
||||
const option = document.createElement('option');
|
||||
option.value = aesthetic;
|
||||
option.textContent = aesthetic;
|
||||
aestheticSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Populate niches
|
||||
data.niches.forEach(niche => {
|
||||
const option = document.createElement('option');
|
||||
option.value = niche;
|
||||
option.textContent = niche;
|
||||
nicheSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Populate target audiences
|
||||
data.target_audiences.forEach(audience => {
|
||||
const option = document.createElement('option');
|
||||
option.value = audience;
|
||||
option.textContent = audience;
|
||||
targetAudienceSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Populate content types
|
||||
data.content_types.forEach(type => {
|
||||
const option = document.createElement('option');
|
||||
option.value = type;
|
||||
option.textContent = type;
|
||||
contentTypeSelect.appendChild(option);
|
||||
});
|
||||
|
||||
// Populate brand voices
|
||||
data.brand_voices.forEach(voice => {
|
||||
const option = document.createElement('option');
|
||||
option.value = voice;
|
||||
option.textContent = voice;
|
||||
brandVoiceSelect.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
// Setup event listeners
|
||||
function setupEventListeners() {
|
||||
// Upload area click
|
||||
uploadArea.addEventListener('click', () => {
|
||||
imageInput.click();
|
||||
});
|
||||
|
||||
// File input change
|
||||
imageInput.addEventListener('change', handleImageSelect);
|
||||
|
||||
// Drag and drop
|
||||
uploadArea.addEventListener('dragover', handleDragOver);
|
||||
uploadArea.addEventListener('dragleave', handleDragLeave);
|
||||
uploadArea.addEventListener('drop', handleDrop);
|
||||
|
||||
// Analyze button
|
||||
analyzeBtn.addEventListener('click', analyzeImage);
|
||||
|
||||
// Preference changes
|
||||
aestheticSelect.addEventListener('change', updateAnalyzeButton);
|
||||
nicheSelect.addEventListener('change', updateAnalyzeButton);
|
||||
targetAudienceSelect.addEventListener('change', updateAnalyzeButton);
|
||||
contentTypeSelect.addEventListener('change', updateAnalyzeButton);
|
||||
brandVoiceSelect.addEventListener('change', updateAnalyzeButton);
|
||||
}
|
||||
|
||||
// Handle image selection
|
||||
function handleImageSelect(event) {
|
||||
const file = event.target.files[0];
|
||||
if (file) {
|
||||
processImageFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle drag over
|
||||
function handleDragOver(event) {
|
||||
event.preventDefault();
|
||||
uploadArea.classList.add('dragover');
|
||||
}
|
||||
|
||||
// Handle drag leave
|
||||
function handleDragLeave(event) {
|
||||
event.preventDefault();
|
||||
uploadArea.classList.remove('dragover');
|
||||
}
|
||||
|
||||
// Handle drop
|
||||
function handleDrop(event) {
|
||||
event.preventDefault();
|
||||
uploadArea.classList.remove('dragover');
|
||||
|
||||
const files = event.dataTransfer.files;
|
||||
if (files.length > 0) {
|
||||
processImageFile(files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Process image file
|
||||
function processImageFile(file) {
|
||||
// Validate file type
|
||||
if (!file.type.startsWith('image/')) {
|
||||
showError('Please select a valid image file.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate file size (10MB limit)
|
||||
if (file.size > 10 * 1024 * 1024) {
|
||||
showError('Image file size must be less than 10MB.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create preview
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
previewImg.src = e.target.result;
|
||||
imagePreview.style.display = 'block';
|
||||
selectedImage = file;
|
||||
updateAnalyzeButton();
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
// Update analyze button state
|
||||
function updateAnalyzeButton() {
|
||||
const hasImage = selectedImage !== null;
|
||||
const hasPreferences = aestheticSelect.value || nicheSelect.value ||
|
||||
targetAudienceSelect.value || contentTypeSelect.value ||
|
||||
brandVoiceSelect.value;
|
||||
|
||||
analyzeBtn.disabled = !hasImage;
|
||||
|
||||
if (hasImage && hasPreferences) {
|
||||
analyzeBtn.innerHTML = '<i class="fas fa-magic"></i> Analyze with Preferences';
|
||||
} else if (hasImage) {
|
||||
analyzeBtn.innerHTML = '<i class="fas fa-magic"></i> Analyze Image';
|
||||
}
|
||||
}
|
||||
|
||||
// Analyze image
|
||||
async function analyzeImage() {
|
||||
if (!selectedImage) {
|
||||
showError('Please select an image first.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading
|
||||
loading.style.display = 'block';
|
||||
resultsSection.style.display = 'none';
|
||||
analyzeBtn.disabled = true;
|
||||
|
||||
try {
|
||||
// Convert image to base64
|
||||
const base64Image = await fileToBase64(selectedImage);
|
||||
|
||||
// Prepare request data
|
||||
const requestData = {
|
||||
image: base64Image
|
||||
};
|
||||
|
||||
// Add preferences if any are selected
|
||||
const userPreferences = {};
|
||||
if (aestheticSelect.value) userPreferences.aesthetic = aestheticSelect.value;
|
||||
if (nicheSelect.value) userPreferences.niche = nicheSelect.value;
|
||||
if (targetAudienceSelect.value) userPreferences.target_audience = targetAudienceSelect.value;
|
||||
if (contentTypeSelect.value) userPreferences.content_type = contentTypeSelect.value;
|
||||
if (brandVoiceSelect.value) userPreferences.brand_voice = brandVoiceSelect.value;
|
||||
|
||||
if (Object.keys(userPreferences).length > 0) {
|
||||
requestData.user_preferences = userPreferences;
|
||||
}
|
||||
|
||||
// Send request to API
|
||||
const response = await fetch(`${API_BASE_URL}/score-image`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
displayResults(result);
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || 'Analysis failed');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Analysis error:', error);
|
||||
showError(`Analysis failed: ${error.message}`);
|
||||
} finally {
|
||||
// Hide loading
|
||||
loading.style.display = 'none';
|
||||
analyzeBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert file to base64
|
||||
function fileToBase64(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => {
|
||||
// Remove the data URL prefix (e.g., "data:image/jpeg;base64,")
|
||||
const base64 = reader.result.split(',')[1];
|
||||
resolve(base64);
|
||||
};
|
||||
reader.onerror = error => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
// Display results
|
||||
function displayResults(result) {
|
||||
// Check if content was rejected
|
||||
if (result.status === 'rejected') {
|
||||
displayRejectedContent(result);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update final score
|
||||
document.getElementById('finalScore').textContent = result.final_score;
|
||||
|
||||
// Update score breakdown
|
||||
const scoreBreakdown = document.getElementById('scoreBreakdown');
|
||||
scoreBreakdown.innerHTML = '';
|
||||
|
||||
const scoreCategories = [
|
||||
{ key: 'technical_quality', name: 'Technical Quality', icon: '🔧' },
|
||||
{ key: 'compositional_strength', name: 'Compositional Strength', icon: '📐' },
|
||||
{ key: 'psychological_engagement', name: 'Psychological Engagement', icon: '🧠' },
|
||||
{ key: 'trend_zeitgeist', name: 'Trend & Zeitgeist', icon: '📈' }
|
||||
];
|
||||
|
||||
scoreCategories.forEach(category => {
|
||||
const scoreData = result[category.key];
|
||||
const card = document.createElement('div');
|
||||
card.className = 'score-card';
|
||||
card.innerHTML = `
|
||||
<h4>${category.icon} ${category.name}</h4>
|
||||
<div class="score-value">${scoreData.score}/100</div>
|
||||
<div class="score-details">${scoreData.details}</div>
|
||||
`;
|
||||
scoreBreakdown.appendChild(card);
|
||||
});
|
||||
|
||||
// Update recommendations
|
||||
const recommendationList = document.getElementById('recommendationList');
|
||||
recommendationList.innerHTML = '';
|
||||
|
||||
if (result.recommendations && result.recommendations.length > 0) {
|
||||
result.recommendations.forEach(recommendation => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = recommendation;
|
||||
recommendationList.appendChild(li);
|
||||
});
|
||||
} else {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = 'No specific recommendations available.';
|
||||
recommendationList.appendChild(li);
|
||||
}
|
||||
|
||||
// Show results
|
||||
resultsSection.style.display = 'block';
|
||||
|
||||
// Add enhancement button if score is low
|
||||
if (result.final_score < 80) {
|
||||
addEnhancementButton();
|
||||
}
|
||||
|
||||
// Scroll to results
|
||||
resultsSection.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
|
||||
// Display rejected content message
|
||||
function displayRejectedContent(result) {
|
||||
// Update final score to show 0
|
||||
document.getElementById('finalScore').textContent = '0';
|
||||
document.getElementById('finalScore').style.color = '#e74c3c';
|
||||
|
||||
// Clear score breakdown
|
||||
const scoreBreakdown = document.getElementById('scoreBreakdown');
|
||||
scoreBreakdown.innerHTML = '';
|
||||
|
||||
// Create rejection message card
|
||||
const rejectionCard = document.createElement('div');
|
||||
rejectionCard.className = 'score-card rejection-card';
|
||||
rejectionCard.innerHTML = `
|
||||
<h4>🚫 Content Rejected</h4>
|
||||
<div class="rejection-message">
|
||||
<p><strong>${result.message}</strong></p>
|
||||
<p><em>Reason: ${result.rejection_reason}</em></p>
|
||||
</div>
|
||||
`;
|
||||
scoreBreakdown.appendChild(rejectionCard);
|
||||
|
||||
// Add risk analysis card if moderation details are available
|
||||
if (result.moderation_details && result.moderation_details.risk_scores) {
|
||||
const riskCard = document.createElement('div');
|
||||
riskCard.className = 'score-card risk-analysis-card';
|
||||
|
||||
const riskScores = result.moderation_details.risk_scores;
|
||||
const violations = result.moderation_details.violations || [];
|
||||
|
||||
let riskContent = '<h4>🔍 Risk Analysis</h4>';
|
||||
riskContent += '<div class="risk-scores">';
|
||||
|
||||
// Display risk scores
|
||||
const riskCategories = [
|
||||
{ key: 'adult', name: 'Adult Content', icon: '🔞' },
|
||||
{ key: 'violence', name: 'Violence', icon: '⚔️' },
|
||||
{ key: 'racy', name: 'Racy Content', icon: '💋' },
|
||||
{ key: 'medical', name: 'Medical Content', icon: '🏥' },
|
||||
{ key: 'spoof', name: 'Spoof/Manipulated', icon: '🎭' }
|
||||
];
|
||||
|
||||
riskCategories.forEach(category => {
|
||||
const score = riskScores[category.key] || 0;
|
||||
const riskLevel = getRiskLevelText(score);
|
||||
const riskClass = getRiskClass(score);
|
||||
|
||||
riskContent += `
|
||||
<div class="risk-item ${riskClass}">
|
||||
<span class="risk-icon">${category.icon}</span>
|
||||
<span class="risk-name">${category.name}</span>
|
||||
<span class="risk-score">${score}/5</span>
|
||||
<span class="risk-level">${riskLevel}</span>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
||||
riskContent += '</div>';
|
||||
|
||||
// Display violations if any
|
||||
if (violations.length > 0) {
|
||||
riskContent += '<div class="violations-section">';
|
||||
riskContent += '<h5>🚨 Detected Violations:</h5>';
|
||||
riskContent += '<ul class="violations-list">';
|
||||
violations.forEach(violation => {
|
||||
riskContent += `<li>${violation}</li>`;
|
||||
});
|
||||
riskContent += '</ul>';
|
||||
riskContent += '</div>';
|
||||
}
|
||||
|
||||
riskCard.innerHTML = riskContent;
|
||||
scoreBreakdown.appendChild(riskCard);
|
||||
}
|
||||
|
||||
// Update recommendations with content guidelines
|
||||
const recommendationList = document.getElementById('recommendationList');
|
||||
recommendationList.innerHTML = '';
|
||||
|
||||
if (result.recommendations && result.recommendations.length > 0) {
|
||||
result.recommendations.forEach(recommendation => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = recommendation;
|
||||
recommendationList.appendChild(li);
|
||||
});
|
||||
}
|
||||
|
||||
// Show results
|
||||
resultsSection.style.display = 'block';
|
||||
|
||||
// Scroll to results
|
||||
resultsSection.scrollIntoView({ behavior: 'smooth' });
|
||||
}
|
||||
|
||||
// Helper function to get risk level text
|
||||
function getRiskLevelText(score) {
|
||||
switch(score) {
|
||||
case 0: return 'Unknown';
|
||||
case 1: return 'Very Unlikely';
|
||||
case 2: return 'Unlikely';
|
||||
case 3: return 'Possible';
|
||||
case 4: return 'Likely';
|
||||
case 5: return 'Very Likely';
|
||||
default: return 'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to get risk class for styling
|
||||
function getRiskClass(score) {
|
||||
if (score >= 4) return 'high-risk';
|
||||
if (score >= 3) return 'medium-risk';
|
||||
return 'low-risk';
|
||||
}
|
||||
|
||||
// Add enhancement button to results
|
||||
function addEnhancementButton() {
|
||||
const resultsSection = document.getElementById('resultsSection');
|
||||
|
||||
// Remove existing enhancement button
|
||||
const existingButton = document.getElementById('enhancementBtn');
|
||||
if (existingButton) {
|
||||
existingButton.remove();
|
||||
}
|
||||
|
||||
// Create enhancement button
|
||||
const enhancementBtn = document.createElement('button');
|
||||
enhancementBtn.id = 'enhancementBtn';
|
||||
enhancementBtn.className = 'enhancement-btn';
|
||||
enhancementBtn.innerHTML = '<i class="fas fa-magic"></i> Enhance Image with AI';
|
||||
enhancementBtn.onclick = enhanceImage;
|
||||
|
||||
// Insert after score display
|
||||
const scoreDisplay = document.querySelector('.score-display');
|
||||
scoreDisplay.parentNode.insertBefore(enhancementBtn, scoreDisplay.nextSibling);
|
||||
}
|
||||
|
||||
// Enhance image with AI
|
||||
async function enhanceImage() {
|
||||
if (!selectedImage) {
|
||||
showError('Please select an image first.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Show loading
|
||||
const loading = document.getElementById('loading');
|
||||
loading.style.display = 'block';
|
||||
loading.querySelector('p').textContent = 'Generating enhanced images with AI...';
|
||||
|
||||
const enhancementBtn = document.getElementById('enhancementBtn');
|
||||
if (enhancementBtn) {
|
||||
enhancementBtn.disabled = true;
|
||||
}
|
||||
|
||||
try {
|
||||
// Convert image to base64
|
||||
const base64Image = await fileToBase64(selectedImage);
|
||||
|
||||
// Prepare request data
|
||||
const requestData = {
|
||||
image: base64Image
|
||||
};
|
||||
|
||||
// Add preferences if any are selected
|
||||
const userPreferences = {};
|
||||
if (aestheticSelect.value) userPreferences.aesthetic = aestheticSelect.value;
|
||||
if (nicheSelect.value) userPreferences.niche = nicheSelect.value;
|
||||
if (targetAudienceSelect.value) userPreferences.target_audience = targetAudienceSelect.value;
|
||||
if (contentTypeSelect.value) userPreferences.content_type = contentTypeSelect.value;
|
||||
if (brandVoiceSelect.value) userPreferences.brand_voice = brandVoiceSelect.value;
|
||||
|
||||
if (Object.keys(userPreferences).length > 0) {
|
||||
requestData.user_preferences = userPreferences;
|
||||
}
|
||||
|
||||
// Send enhancement request
|
||||
const response = await fetch(`${API_BASE_URL}/enhance-image`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
enhancedImages = result.enhanced_images;
|
||||
currentEnhancementIndex = 0;
|
||||
|
||||
if (enhancedImages.length > 0) {
|
||||
displayEnhancedImages();
|
||||
} else {
|
||||
showError('No enhanced images were generated.');
|
||||
}
|
||||
} else {
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.detail || 'Enhancement failed');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Enhancement error:', error);
|
||||
showError(`Enhancement failed: ${error.message}`);
|
||||
} finally {
|
||||
// Hide loading
|
||||
loading.style.display = 'none';
|
||||
loading.querySelector('p').textContent = 'Analyzing your image with AI...';
|
||||
|
||||
if (enhancementBtn) {
|
||||
enhancementBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Display enhanced images
|
||||
function displayEnhancedImages() {
|
||||
const resultsSection = document.getElementById('resultsSection');
|
||||
|
||||
// Remove existing enhancement section
|
||||
const existingEnhancement = document.getElementById('enhancementSection');
|
||||
if (existingEnhancement) {
|
||||
existingEnhancement.remove();
|
||||
}
|
||||
|
||||
// Create enhancement section
|
||||
const enhancementSection = document.createElement('div');
|
||||
enhancementSection.id = 'enhancementSection';
|
||||
enhancementSection.className = 'enhancement-section';
|
||||
|
||||
enhancementSection.innerHTML = `
|
||||
<h3><i class="fas fa-star"></i> AI Enhanced Images</h3>
|
||||
<div class="enhancement-controls">
|
||||
<button class="nav-btn" onclick="previousEnhancedImage()" id="prevBtn">
|
||||
<i class="fas fa-chevron-left"></i>
|
||||
</button>
|
||||
<span class="enhancement-counter">${currentEnhancementIndex + 1} / ${enhancedImages.length}</span>
|
||||
<button class="nav-btn" onclick="nextEnhancedImage()" id="nextBtn">
|
||||
<i class="fas fa-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="enhancement-display">
|
||||
<div class="original-image">
|
||||
<h4>Original</h4>
|
||||
<img src="${previewImg.src}" alt="Original" class="comparison-img">
|
||||
</div>
|
||||
<div class="enhanced-image">
|
||||
<h4>Enhanced Version ${currentEnhancementIndex + 1}</h4>
|
||||
<img src="data:image/jpeg;base64,${enhancedImages[currentEnhancementIndex].image}" alt="Enhanced" class="comparison-img">
|
||||
</div>
|
||||
</div>
|
||||
<div class="enhancement-actions">
|
||||
<button class="action-btn reject-btn" onclick="rejectEnhancedImage()">
|
||||
<i class="fas fa-times"></i> Discard
|
||||
</button>
|
||||
<button class="action-btn save-btn" onclick="saveEnhancedImage()">
|
||||
<i class="fas fa-save"></i> Save
|
||||
</button>
|
||||
</div>
|
||||
<div class="enhancement-prompt">
|
||||
<h5>Enhancement Details:</h5>
|
||||
<p>${enhancedImages[currentEnhancementIndex].prompt}</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
resultsSection.appendChild(enhancementSection);
|
||||
enhancementSection.scrollIntoView({ behavior: 'smooth' });
|
||||
|
||||
updateEnhancementControls();
|
||||
}
|
||||
|
||||
// Navigation functions for enhanced images
|
||||
window.previousEnhancedImage = function() {
|
||||
if (currentEnhancementIndex > 0) {
|
||||
currentEnhancementIndex--;
|
||||
displayEnhancedImages();
|
||||
}
|
||||
};
|
||||
|
||||
window.nextEnhancedImage = function() {
|
||||
if (currentEnhancementIndex < enhancedImages.length - 1) {
|
||||
currentEnhancementIndex++;
|
||||
displayEnhancedImages();
|
||||
}
|
||||
};
|
||||
|
||||
window.rejectEnhancedImage = function() {
|
||||
// Remove current enhanced image from array
|
||||
enhancedImages.splice(currentEnhancementIndex, 1);
|
||||
|
||||
if (enhancedImages.length === 0) {
|
||||
// No more enhanced images
|
||||
const enhancementSection = document.getElementById('enhancementSection');
|
||||
if (enhancementSection) {
|
||||
enhancementSection.remove();
|
||||
}
|
||||
showSuccess('All enhanced images have been discarded.');
|
||||
} else {
|
||||
// Adjust index if needed
|
||||
if (currentEnhancementIndex >= enhancedImages.length) {
|
||||
currentEnhancementIndex = enhancedImages.length - 1;
|
||||
}
|
||||
displayEnhancedImages();
|
||||
}
|
||||
};
|
||||
|
||||
window.saveEnhancedImage = function() {
|
||||
const enhancedImage = enhancedImages[currentEnhancementIndex];
|
||||
|
||||
// Create download link
|
||||
const link = document.createElement('a');
|
||||
link.href = `data:image/jpeg;base64,${enhancedImage.image}`;
|
||||
link.download = `enhanced_image_v${enhancedImage.version}.jpg`;
|
||||
link.click();
|
||||
|
||||
showSuccess(`Enhanced image version ${enhancedImage.version} saved successfully!`);
|
||||
};
|
||||
|
||||
// Update enhancement navigation controls
|
||||
function updateEnhancementControls() {
|
||||
const prevBtn = document.getElementById('prevBtn');
|
||||
const nextBtn = document.getElementById('nextBtn');
|
||||
const counter = document.querySelector('.enhancement-counter');
|
||||
|
||||
if (prevBtn) prevBtn.disabled = currentEnhancementIndex === 0;
|
||||
if (nextBtn) nextBtn.disabled = currentEnhancementIndex === enhancedImages.length - 1;
|
||||
if (counter) counter.textContent = `${currentEnhancementIndex + 1} / ${enhancedImages.length}`;
|
||||
}
|
||||
|
||||
// Show error message
|
||||
function showError(message) {
|
||||
// Remove existing error messages
|
||||
const existingError = document.querySelector('.error');
|
||||
if (existingError) {
|
||||
existingError.remove();
|
||||
}
|
||||
|
||||
// Create error element
|
||||
const errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'error';
|
||||
errorDiv.innerHTML = `<i class="fas fa-exclamation-triangle"></i> ${message}`;
|
||||
|
||||
// Insert after header
|
||||
const mainContent = document.querySelector('.main-content');
|
||||
mainContent.insertBefore(errorDiv, mainContent.firstChild);
|
||||
|
||||
// Auto-remove after 5 seconds
|
||||
setTimeout(() => {
|
||||
if (errorDiv.parentNode) {
|
||||
errorDiv.remove();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
// Show success message
|
||||
function showSuccess(message) {
|
||||
// Remove existing success messages
|
||||
const existingSuccess = document.querySelector('.success');
|
||||
if (existingSuccess) {
|
||||
existingSuccess.remove();
|
||||
}
|
||||
|
||||
// Create success element
|
||||
const successDiv = document.createElement('div');
|
||||
successDiv.className = 'success';
|
||||
successDiv.innerHTML = `<i class="fas fa-check-circle"></i> ${message}`;
|
||||
|
||||
// Insert after header
|
||||
const mainContent = document.querySelector('.main-content');
|
||||
mainContent.insertBefore(successDiv, mainContent.firstChild);
|
||||
|
||||
// Auto-remove after 3 seconds
|
||||
setTimeout(() => {
|
||||
if (successDiv.parentNode) {
|
||||
successDiv.remove();
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
Reference in New Issue
Block a user