Untitled
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Text Converter Tool</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); width: 80%; max-width: 600px; text-align: center; /* Center align text and buttons */ } textarea { width: 100%; height: 150px; padding: 10px; box-sizing: border-box; margin-bottom: 10px; resize: none; } button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 5px; cursor: pointer; margin: 5px; } button:hover { background-color: #0056b3; } .copy-button { background-color: #28a745; } .copy-button:hover { background-color: #218838; } .paste-button { background-color: #17a2b8; } .paste-button:hover { background-color: #117a8b; } </style> </head> <body> <div class="container"> <h1>Random Case Text Converter Tool</h1> <div class="text-box"> <textarea id="text-box" placeholder="Enter your text here..."></textarea> <button onclick="convertToRandomCase()">Convert to Random Case</button> <button class="copy-button" onclick="copyToClipboard()">Copy</button> <button class="paste-button" onclick="pasteFromClipboard()">Paste</button> </div> </div> <script> function convertToRandomCase() { // Get the text area element const textBox = document.getElementById('text-box'); let text = textBox.value; // Convert each character to random case let randomCaseText = text.split('').map(char => { if (char.match(/[a-z]/i)) { // Check if character is a letter return Math.random() < 0.5 ? char.toLowerCase() : char.toUpperCase(); } return char; // Keep non-letter characters unchanged }).join(''); // Set the transformed text back to the text area textBox.value = randomCaseText; } function copyToClipboard() { // Get the text area element const textBox = document.getElementById('text-box'); // Select the text textBox.select(); textBox.setSelectionRange(0, 99999); // For mobile devices // Copy the text document.execCommand('copy'); // Alert the user that the text has been copied alert('Copied to clipboard!'); } function pasteFromClipboard() { // Get the text area element const textBox = document.getElementById('text-box'); // Paste the text from the clipboard navigator.clipboard.readText().then(text => { textBox.value = text; }).catch(err => { console.error('Failed to read clipboard contents: ', err); }); } </script> </body> </html>
Leave a Comment