|
1 | 1 | // Huntarr.io Documentation JavaScript |
2 | 2 |
|
3 | 3 | document.addEventListener('DOMContentLoaded', function() { |
4 | | - // Add copy functionality to code blocks |
| 4 | + // Get all code blocks |
5 | 5 | const codeBlocks = document.querySelectorAll('pre code'); |
| 6 | + |
6 | 7 | if (codeBlocks.length > 0) { |
| 8 | + // First pass: detect and enhance terminal command blocks |
| 9 | + codeBlocks.forEach(function(codeBlock) { |
| 10 | + const content = codeBlock.textContent.trim(); |
| 11 | + const pre = codeBlock.parentNode; |
| 12 | + |
| 13 | + // Detect if this is likely a terminal command (common CLI commands, starts with $, etc) |
| 14 | + const isTerminalCommand = ( |
| 15 | + content.match(/^(git|npm|yarn|docker|curl|wget|cd|ls|mkdir|touch|rm|cp|mv|sudo|apt|brew)\s/) || |
| 16 | + content.startsWith('$') || |
| 17 | + content.includes('clone') || |
| 18 | + content.includes('install') || |
| 19 | + content.includes('://') && (content.includes('curl') || content.includes('wget')) |
| 20 | + ); |
| 21 | + |
| 22 | + if (isTerminalCommand) { |
| 23 | + // Add terminal styling to this code block |
| 24 | + pre.classList.add('terminal'); |
| 25 | + |
| 26 | + // If it's a single-line command, add the command prompt |
| 27 | + if (!content.includes('\n')) { |
| 28 | + codeBlock.classList.add('command-prompt'); |
| 29 | + } |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + // Second pass: add copy functionality to all code blocks |
7 | 34 | codeBlocks.forEach(function(codeBlock) { |
8 | 35 | const copyButton = document.createElement('button'); |
9 | 36 | copyButton.className = 'copy-button'; |
|
0 commit comments