Fred808 commited on
Commit
911fe16
·
verified ·
1 Parent(s): 8518a27

Upload script.js

Browse files
Files changed (1) hide show
  1. static/js/script.js +159 -0
static/js/script.js ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const uploadForm = document.getElementById('uploadForm');
3
+ const uploadBtn = document.getElementById('uploadBtn');
4
+ const btnText = uploadBtn.querySelector('.btn-text');
5
+ const loadingSpinner = uploadBtn.querySelector('.loading-spinner');
6
+ const resultsSection = document.getElementById('resultsSection');
7
+ const resultsContent = document.getElementById('resultsContent');
8
+ const clearBtn = document.getElementById('clearBtn');
9
+ const filenamesInput = document.getElementById('filenames');
10
+
11
+ // Form submission handler
12
+ uploadForm.addEventListener('submit', async function(e) {
13
+ e.preventDefault();
14
+
15
+ const filenames = filenamesInput.value.trim();
16
+ if (!filenames) {
17
+ alert('Please enter at least one filename');
18
+ return;
19
+ }
20
+
21
+ // Show loading state
22
+ setLoadingState(true);
23
+
24
+ try {
25
+ const formData = new FormData();
26
+ formData.append('filenames', filenames);
27
+
28
+ const response = await fetch('/upload', {
29
+ method: 'POST',
30
+ body: formData
31
+ });
32
+
33
+ if (!response.ok) {
34
+ throw new Error(`HTTP error! status: ${response.status}`);
35
+ }
36
+
37
+ const results = await response.text();
38
+ displayResults(results);
39
+
40
+ } catch (error) {
41
+ console.error('Upload error:', error);
42
+ displayResults(`❌ Error: ${error.message}`);
43
+ } finally {
44
+ setLoadingState(false);
45
+ }
46
+ });
47
+
48
+ // Clear results handler
49
+ clearBtn.addEventListener('click', function() {
50
+ resultsContent.textContent = '';
51
+ resultsSection.style.display = 'none';
52
+ });
53
+
54
+ // Auto-resize textarea
55
+ filenamesInput.addEventListener('input', function() {
56
+ this.style.height = 'auto';
57
+ this.style.height = Math.min(this.scrollHeight, 200) + 'px';
58
+ });
59
+
60
+ // Functions
61
+ function setLoadingState(isLoading) {
62
+ uploadBtn.disabled = isLoading;
63
+
64
+ if (isLoading) {
65
+ btnText.style.display = 'none';
66
+ loadingSpinner.style.display = 'flex';
67
+ } else {
68
+ btnText.style.display = 'flex';
69
+ loadingSpinner.style.display = 'none';
70
+ }
71
+ }
72
+
73
+ function displayResults(results) {
74
+ // Format results with proper styling
75
+ const formattedResults = formatResults(results);
76
+ resultsContent.innerHTML = formattedResults;
77
+ resultsSection.style.display = 'block';
78
+
79
+ // Scroll to results
80
+ resultsSection.scrollIntoView({
81
+ behavior: 'smooth',
82
+ block: 'start'
83
+ });
84
+ }
85
+
86
+ function formatResults(results) {
87
+ if (!results) return '<span class="error">No results received</span>';
88
+
89
+ return results.split('\n').map(line => {
90
+ line = line.trim();
91
+ if (!line) return '';
92
+
93
+ if (line.startsWith('✅')) {
94
+ return `<div class="success">${escapeHtml(line)}</div>`;
95
+ } else if (line.startsWith('❌')) {
96
+ return `<div class="error">${escapeHtml(line)}</div>`;
97
+ } else if (line.startsWith('⏩')) {
98
+ return `<div class="warning">${escapeHtml(line)}</div>`;
99
+ } else {
100
+ return `<div>${escapeHtml(line)}</div>`;
101
+ }
102
+ }).join('');
103
+ }
104
+
105
+ function escapeHtml(text) {
106
+ const div = document.createElement('div');
107
+ div.textContent = text;
108
+ return div.innerHTML;
109
+ }
110
+
111
+ // Add some interactive effects
112
+ const uploadCard = document.querySelector('.upload-card');
113
+
114
+ // Add subtle hover effect to form elements
115
+ const formElements = document.querySelectorAll('input, textarea, button');
116
+ formElements.forEach(element => {
117
+ element.addEventListener('focus', function() {
118
+ uploadCard.style.transform = 'translateY(-2px)';
119
+ });
120
+
121
+ element.addEventListener('blur', function() {
122
+ uploadCard.style.transform = 'translateY(-5px)';
123
+ });
124
+ });
125
+
126
+ // Add keyboard shortcuts
127
+ document.addEventListener('keydown', function(e) {
128
+ // Ctrl/Cmd + Enter to submit form
129
+ if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
130
+ e.preventDefault();
131
+ uploadForm.dispatchEvent(new Event('submit'));
132
+ }
133
+
134
+ // Escape to clear results
135
+ if (e.key === 'Escape' && resultsSection.style.display !== 'none') {
136
+ clearBtn.click();
137
+ }
138
+ });
139
+
140
+ // Add tooltip for keyboard shortcuts
141
+ const tooltip = document.createElement('div');
142
+ tooltip.innerHTML = `
143
+ <div style="position: fixed; bottom: 20px; right: 20px; background: rgba(0,0,0,0.8); color: white; padding: 10px; border-radius: 8px; font-size: 0.8rem; z-index: 1000;">
144
+ <div><kbd>Ctrl+Enter</kbd> Submit form</div>
145
+ <div><kbd>Esc</kbd> Clear results</div>
146
+ </div>
147
+ `;
148
+
149
+ // Show tooltip on first visit
150
+ setTimeout(() => {
151
+ document.body.appendChild(tooltip);
152
+ setTimeout(() => {
153
+ tooltip.style.opacity = '0';
154
+ tooltip.style.transition = 'opacity 0.5s';
155
+ setTimeout(() => tooltip.remove(), 500);
156
+ }, 3000);
157
+ }, 1000);
158
+ });
159
+