-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathscript.js
More file actions
574 lines (490 loc) · 19.3 KB
/
Copy pathscript.js
File metadata and controls
574 lines (490 loc) · 19.3 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Theme Toggle Functionality
const themeToggle = document.getElementById('theme-toggle');
const themeIcon = document.querySelector('.theme-icon');
const body = document.body;
// Load saved theme or default to light (Anthropic style)
const savedTheme = localStorage.getItem('theme') || 'light';
if (savedTheme === 'dark') {
body.classList.add('dark-theme');
themeIcon.textContent = '🌙';
} else {
themeIcon.textContent = '☀️';
}
themeToggle.addEventListener('click', () => {
body.classList.toggle('dark-theme');
const isDark = body.classList.contains('dark-theme');
themeIcon.textContent = isDark ? '🌙' : '☀️';
localStorage.setItem('theme', isDark ? 'dark' : 'light');
});
// Commands Data and State
let allCommands = [];
let filteredCommands = [];
let currentView = 'list';
let currentFilter = 'all';
// Pagination State
let currentPage = 1;
const commandsPerPage = 12;
// DOM Elements
const commandsContainer = document.getElementById('commands-container');
const commandSearch = document.getElementById('command-search');
const listViewBtn = document.getElementById('list-view');
const gridViewBtn = document.getElementById('grid-view');
const filterTags = document.getElementById('filter-tags');
const commandsCount = document.getElementById('commands-count');
// Copy to clipboard functionality
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
// Find the copy button that was clicked
const copyBtn = event.target.closest('.copy-btn');
if (copyBtn) {
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
setTimeout(() => {
copyBtn.textContent = originalText;
}, 1000);
}
}).catch(err => {
console.error('Failed to copy:', err);
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
const copyBtn = event.target.closest('.copy-btn');
if (copyBtn) {
const originalText = copyBtn.textContent;
copyBtn.textContent = 'Copied!';
setTimeout(() => {
copyBtn.textContent = originalText;
}, 1000);
}
});
}
// Load commands from GitHub (works both locally and when deployed)
async function loadCommands() {
try {
const dataURL = 'https://raw.githubusercontent.com/kiliczsh/claude-cmd/refs/heads/main/commands/commands.json';
const response = await fetch(dataURL);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
allCommands = await response.json();
filteredCommands = [...allCommands];
// Extract unique tags and create filter buttons
const tags = new Set();
allCommands.forEach(cmd => {
cmd.tags.forEach(tag => tags.add(tag));
});
createFilterTags([...tags].sort());
renderCommands();
updateCommandsCount();
renderPagination();
} catch (error) {
console.error('Error loading commands:', error);
commandsContainer.innerHTML = `
<div class="error-message">
<p>Failed to load commands. Please try again later.</p>
<p>Error: ${error.message}</p>
</div>
`;
commandsCount.textContent = 'Error loading commands';
}
}
// Create filter tag buttons
function createFilterTags(tags) {
filterTags.innerHTML = '<button class="tag-filter active" data-tag="all">All</button>';
tags.forEach(tag => {
const button = document.createElement('button');
button.className = 'tag-filter';
button.dataset.tag = tag;
button.textContent = capitalizeFirst(tag);
filterTags.appendChild(button);
});
// Add event listeners to filter buttons
filterTags.addEventListener('click', (e) => {
if (e.target.classList.contains('tag-filter')) {
// Remove active class from all buttons
filterTags.querySelectorAll('.tag-filter').forEach(btn => {
btn.classList.remove('active');
});
// Add active class to clicked button
e.target.classList.add('active');
// Update filter and render
currentFilter = e.target.dataset.tag;
applyFilters();
}
});
}
// Apply search and tag filters
function applyFilters() {
const searchTerm = commandSearch.value.toLowerCase().trim();
filteredCommands = allCommands.filter(cmd => {
// Tag filter
const tagMatch = currentFilter === 'all' || cmd.tags.includes(currentFilter);
// Search filter
const searchMatch = !searchTerm ||
cmd.name.toLowerCase().includes(searchTerm) ||
cmd.description.toLowerCase().includes(searchTerm) ||
cmd.tags.some(tag => tag.toLowerCase().includes(searchTerm)) ||
cmd.author.toLowerCase().includes(searchTerm);
return tagMatch && searchMatch;
});
// Reset to first page when filters change
currentPage = 1;
renderCommands();
updateCommandsCount();
renderPagination();
}
// Render commands based on current view with pagination
function renderCommands() {
if (filteredCommands.length === 0) {
commandsContainer.innerHTML = `
<div class="no-commands">
<p>No commands found matching your criteria.</p>
<p>Try adjusting your search or filter settings.</p>
</div>
`;
return;
}
// Calculate pagination
const startIndex = (currentPage - 1) * commandsPerPage;
const endIndex = startIndex + commandsPerPage;
const commandsToShow = filteredCommands.slice(startIndex, endIndex);
const containerClass = currentView === 'grid' ? 'commands-grid' : 'commands-list';
commandsContainer.className = containerClass;
commandsContainer.innerHTML = commandsToShow
.map(cmd => createCommandCard(cmd))
.join('');
}
// Create individual command card HTML
function createCommandCard(command) {
const category = command.id.split('/')[0] || 'general';
const tagsHtml = command.tags
.map(tag => `<span class="command-tag">${tag}</span>`)
.join('');
return `
<div class="command-card" onclick="showCommandDetails('${command.id}')" style="cursor: pointer;">
<div class="command-header">
<h3 class="command-name">${escapeHtml(command.name)}</h3>
<span class="command-category">${capitalizeFirst(category)}</span>
</div>
<p class="command-description">${escapeHtml(command.description)}</p>
<div class="command-meta">
<div class="command-author">
<span>👤</span>
<span>${escapeHtml(command.author)}</span>
</div>
<div class="command-tags">
${tagsHtml}
</div>
</div>
</div>
`;
}
// Update commands count display
function updateCommandsCount() {
const total = allCommands.length;
const filtered = filteredCommands.length;
const startIndex = (currentPage - 1) * commandsPerPage + 1;
const endIndex = Math.min(currentPage * commandsPerPage, filtered);
if (filtered === 0) {
commandsCount.textContent = 'No commands found';
} else if (filtered === total) {
commandsCount.textContent = `Showing ${startIndex}-${endIndex} of ${total} commands`;
} else {
commandsCount.textContent = `Showing ${startIndex}-${endIndex} of ${filtered} filtered commands (${total} total)`;
}
}
// Render pagination controls
function renderPagination() {
const totalPages = Math.ceil(filteredCommands.length / commandsPerPage);
const paginationContainer = document.getElementById('pagination-controls');
if (!paginationContainer || totalPages <= 1) {
if (paginationContainer) paginationContainer.innerHTML = '';
return;
}
let paginationHTML = '';
// Previous button
if (currentPage > 1) {
paginationHTML += `<button class="pagination-btn" onclick="goToPage(${currentPage - 1})">« Previous</button>`;
}
// Page numbers
const startPage = Math.max(1, currentPage - 2);
const endPage = Math.min(totalPages, currentPage + 2);
if (startPage > 1) {
paginationHTML += `<button class="pagination-btn" onclick="goToPage(1)">1</button>`;
if (startPage > 2) {
paginationHTML += `<span class="pagination-ellipsis">...</span>`;
}
}
for (let i = startPage; i <= endPage; i++) {
const activeClass = i === currentPage ? 'active' : '';
paginationHTML += `<button class="pagination-btn ${activeClass}" onclick="goToPage(${i})">${i}</button>`;
}
if (endPage < totalPages) {
if (endPage < totalPages - 1) {
paginationHTML += `<span class="pagination-ellipsis">...</span>`;
}
paginationHTML += `<button class="pagination-btn" onclick="goToPage(${totalPages})">${totalPages}</button>`;
}
// Next button
if (currentPage < totalPages) {
paginationHTML += `<button class="pagination-btn" onclick="goToPage(${currentPage + 1})">Next »</button>`;
}
paginationContainer.innerHTML = paginationHTML;
}
// Navigate to specific page
function goToPage(page) {
const totalPages = Math.ceil(filteredCommands.length / commandsPerPage);
if (page >= 1 && page <= totalPages) {
currentPage = page;
renderCommands();
updateCommandsCount();
renderPagination();
// Scroll to top of commands section
document.getElementById('commands').scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
}
// View toggle functionality
listViewBtn.addEventListener('click', () => {
currentView = 'list';
listViewBtn.classList.add('active');
gridViewBtn.classList.remove('active');
renderCommands();
});
gridViewBtn.addEventListener('click', () => {
currentView = 'grid';
gridViewBtn.classList.add('active');
listViewBtn.classList.remove('active');
renderCommands();
});
// Search functionality with debouncing
let searchTimeout;
commandSearch.addEventListener('input', () => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
applyFilters();
}, 300);
});
// FAQ Functionality
document.addEventListener('DOMContentLoaded', () => {
const faqQuestions = document.querySelectorAll('.faq-question');
faqQuestions.forEach(question => {
question.addEventListener('click', () => {
const faqItem = question.parentElement;
const isActive = faqItem.classList.contains('active');
// Close all FAQ items
document.querySelectorAll('.faq-item').forEach(item => {
item.classList.remove('active');
});
// Open clicked item if it wasn't active
if (!isActive) {
faqItem.classList.add('active');
}
});
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Utility functions
function capitalizeFirst(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Privacy Policy Modal (simple implementation)
function showPrivacyPolicy() {
alert('Privacy Policy: This is a static website hosted on GitHub Pages. We do not collect any personal data. The theme preference is stored locally in your browser.');
}
// Terms of Service Modal (simple implementation)
function showTermsOfService() {
alert('Terms of Service: Claude CMD is provided "as is" under the MIT License. Use at your own risk. See the GitHub repository for full license terms.');
}
// Enhanced intersection observer for staggered animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry, index) => {
if (entry.isIntersecting) {
// Add staggered delay for smoother animations
setTimeout(() => {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}, index * 100);
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animatedElements = document.querySelectorAll('.use-case-card, .command-card, .install-card');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});
// Command details modal functionality
let selectedCommand = null;
function showCommandDetails(commandId) {
selectedCommand = allCommands.find(cmd => cmd.id === commandId);
if (!selectedCommand) return;
const modal = document.getElementById('command-modal');
const category = selectedCommand.id.split('/')[0] || 'general';
// Populate modal content
document.getElementById('modal-command-name').textContent = selectedCommand.name;
document.getElementById('modal-command-category').textContent = capitalizeFirst(category);
document.getElementById('modal-command-author').textContent = `👤 ${selectedCommand.author}`;
document.getElementById('modal-command-description').textContent = selectedCommand.description;
// Tags
const tagsContainer = document.getElementById('modal-command-tags');
tagsContainer.innerHTML = selectedCommand.tags
.map(tag => `<span class="command-tag">${tag}</span>`)
.join('');
// GitHub link
const githubLink = document.getElementById('modal-github-link');
githubLink.href = `https://github.com/kiliczsh/claude-cmd/blob/main/commands/${selectedCommand.filePath}`;
// Dates
const createdDate = new Date(selectedCommand.created_at).toLocaleDateString();
const updatedDate = new Date(selectedCommand.updated_at).toLocaleDateString();
document.getElementById('modal-created-date').textContent = createdDate;
document.getElementById('modal-updated-date').textContent = updatedDate;
// Show modal
modal.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
function closeCommandModal() {
const modal = document.getElementById('command-modal');
modal.style.display = 'none';
document.body.style.overflow = 'auto';
selectedCommand = null;
}
function copyCommandId() {
if (selectedCommand) {
copyToClipboard(selectedCommand.id);
}
}
// Close modal when clicking outside
document.addEventListener('click', (e) => {
const modal = document.getElementById('command-modal');
if (e.target === modal) {
closeCommandModal();
}
});
// Make functions globally accessible
window.copyToClipboard = copyToClipboard;
window.showCommandDetails = showCommandDetails;
window.closeCommandModal = closeCommandModal;
window.copyCommandId = copyCommandId;
// Load commands when page loads
document.addEventListener('DOMContentLoaded', loadCommands);
// Enhanced keyboard navigation for accessibility
document.addEventListener('keydown', (e) => {
// Escape key to close FAQ items and modal
if (e.key === 'Escape') {
document.querySelectorAll('.faq-item.active').forEach(item => {
item.classList.remove('active');
});
// Close modal if open
const modal = document.getElementById('command-modal');
if (modal && modal.style.display === 'flex') {
closeCommandModal();
}
}
// Enter/Space to toggle theme
if ((e.key === 'Enter' || e.key === ' ') && e.target === themeToggle) {
e.preventDefault();
themeToggle.click();
}
// Arrow keys for filter navigation
if (e.target.classList.contains('tag-filter')) {
const filters = Array.from(document.querySelectorAll('.tag-filter'));
const currentIndex = filters.indexOf(e.target);
if (e.key === 'ArrowRight' && currentIndex < filters.length - 1) {
e.preventDefault();
filters[currentIndex + 1].focus();
} else if (e.key === 'ArrowLeft' && currentIndex > 0) {
e.preventDefault();
filters[currentIndex - 1].focus();
}
}
// Enter/Space to trigger copy buttons
if ((e.key === 'Enter' || e.key === ' ') && e.target.classList.contains('copy-btn')) {
e.preventDefault();
e.target.click();
}
});
// Error boundary for better error handling
window.addEventListener('error', (e) => {
console.error('Global error:', e.error);
// Could implement error reporting here
});
// Performance monitoring
if ('performance' in window) {
window.addEventListener('load', () => {
const loadTime = performance.now();
console.log(`Page loaded in ${loadTime.toFixed(2)}ms`);
// Log Core Web Vitals if available
if ('web-vitals' in window) {
// This would require the web-vitals library
console.log('Web Vitals monitoring enabled');
}
});
}
// Add subtle hover effects for better UX
document.addEventListener('DOMContentLoaded', () => {
// Add hover effect to command cards
const commandCards = document.querySelectorAll('.command-card');
commandCards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.style.transform = 'translateY(-4px)';
});
card.addEventListener('mouseleave', () => {
card.style.transform = 'translateY(0)';
});
});
});
// Preload critical resources
document.addEventListener('DOMContentLoaded', () => {
// Preload the commands JSON file
const link = document.createElement('link');
link.rel = 'prefetch';
link.href = './commands/commands.json';
document.head.appendChild(link);
});
// Add support for reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
if (prefersReducedMotion.matches) {
// Disable animations for users who prefer reduced motion
document.documentElement.style.setProperty('--transition', 'none');
// Remove animation classes
document.addEventListener('DOMContentLoaded', () => {
const animatedElements = document.querySelectorAll('.use-case-card, .command-card, .install-card');
animatedElements.forEach(el => {
el.style.animation = 'none';
el.style.opacity = '1';
el.style.transform = 'none';
});
});
}