Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const input = document.getElementById('input');
+ const output = document.getElementById('output');
+ const processBtn = document.getElementById('process-btn');
+ const clearBtn = document.getElementById('clear-btn');
+ const downloadBtn = document.getElementById('download-btn');
+ const toolBtns = document.querySelectorAll('.tool-btn');
+ let currentTool = 'extract';
+
+ toolBtns.forEach(btn => {
+ btn.addEventListener('click', () => {
+ toolBtns.forEach(b => b.classList.remove('active'));
+ btn.classList.add('active');
+ currentTool = btn.dataset.tool;
+ processText();
+ });
+ });
+
+ processBtn.addEventListener('click', processText);
+ clearBtn.addEventListener('click', clearAll);
+ downloadBtn.addEventListener('click', downloadResults);
+ input.addEventListener('input', updateStats);
+
+ function processText() {
+ const text = input.value;
+ let result = '';
+
+ switch(currentTool) {
+ case 'extract':
+ result = extractDomainsAndIPs(text);
+ break;
+ case 'replace':
+ result = text; // Implement find/replace functionality
+ break;
+ case 'case':
+ result = convertCase(text);
+ break;
+ case 'duplicates':
+ result = removeDuplicates(text);
+ break;
+ case 'encode':
+ result = encodeText(text);
+ break;
+ case 'count':
+ result = countWords(text);
+ break;
+ case 'format':
+ result = formatText(text);
+ break;
+ }
+
+ output.textContent = result;
+ updateStats();
+ toggleDownloadButton(result);
+ }
+
+ function extractDomainsAndIPs(text) {
+ const domainRegex = /[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}/g;
+ const ipRegex = /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g;
+
+ const domains = text.match(domainRegex) || [];
+ const ips = text.match(ipRegex) || [];
+
+ return [...new Set([...domains, ...ips])].join('\n');
+ }
+
+ function convertCase(text) {
+ return text.toUpperCase(); // Implement more cases
+ }
+
+ function removeDuplicates(text) {
+ return [...new Set(text.split('\n'))].join('\n');
+ }
+
+ function encodeText(text) {
+ return btoa(text); // Basic Base64 encoding
+ }
+
+ function countWords(text) {
+ const words = text.trim().split(/\s+/).length;
+ const chars = text.length;
+ return `Words: ${words}\nCharacters: ${chars}`;
+ }
+
+ function formatText(text) {
+ return text.replace(/\s+/g, ' ').trim();
+ }
+
+ function clearAll() {
+ input.value = '';
+ output.textContent = '';
+ updateStats();
+ downloadBtn.classList.add('hidden');
+ }
+
+ function updateStats() {
+ const text = input.value;
+ const words = text.trim().split(/\s+/).length;
+ const chars = text.length;
+
+ document.getElementById('word-count').textContent = `Words: ${words}`;
+ document.getElementById('char-count').textContent = `Characters: ${chars}`;
+ document.getElementById('stats').classList.remove('hidden');
+ }
+
+ function toggleDownloadButton(result) {
+ const lines = result.split('\n');
+ downloadBtn.classList.toggle('hidden', lines.length <= 50);
+ }
+
+ function downloadResults() {
+ const blob = new Blob([output.textContent], {type: 'text/plain'});
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = 'textkit-results.txt';
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ }
+ });