Changed around line 1
+ // Menu Toggle
+ document.querySelector('.menu-toggle').addEventListener('click', () => {
+ document.querySelector('.nav-links').classList.toggle('active');
+ });
+
+ // Hash Generator
+ async function generateHash() {
+ const input = document.getElementById('hashInput').value;
+ const hashType = document.getElementById('hashType').value;
+ const encoder = new TextEncoder();
+ const data = encoder.encode(input);
+
+ try {
+ let hash;
+ switch(hashType) {
+ case 'md5':
+ // Note: Web Crypto API doesn't support MD5, this is a placeholder
+ document.getElementById('hashOutput').value = 'MD5 not supported in Web Crypto API';
+ return;
+ case 'sha1':
+ hash = await crypto.subtle.digest('SHA-1', data);
+ break;
+ case 'sha256':
+ hash = await crypto.subtle.digest('SHA-256', data);
+ break;
+ }
+
+ const hashArray = Array.from(new Uint8Array(hash));
+ const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
+ document.getElementById('hashOutput').value = hashHex;
+ } catch(error) {
+ console.error('Hash generation failed:', error);
+ }
+ }
+
+ // Port Scanner (Note: This is a mock implementation as browser-based port scanning is limited)
+ function scanPorts() {
+ const host = document.getElementById('hostInput').value;
+ const portRange = document.getElementById('portRange').value;
+ const results = document.getElementById('scanResults');
+
+ results.innerHTML = 'Port scanning is limited in browser environment. Consider using a server-side implementation.';
+ }
+
+ // Text Encoder
+ function encodeText() {
+ const input = document.getElementById('encodeInput').value;
+ const type = document.getElementById('encodeType').value;
+ let output = '';
+
+ switch(type) {
+ case 'base64':
+ output = btoa(input);
+ break;
+ case 'uri':
+ output = encodeURIComponent(input);
+ break;
+ case 'hex':
+ output = Array.from(input).map(c => c.charCodeAt(0).toString(16)).join('');
+ break;
+ }
+
+ document.getElementById('encodeOutput').value = output;
+ }
+
+ function decodeText() {
+ const input = document.getElementById('encodeInput').value;
+ const type = document.getElementById('encodeType').value;
+ let output = '';
+
+ try {
+ switch(type) {
+ case 'base64':
+ output = atob(input);
+ break;
+ case 'uri':
+ output = decodeURIComponent(input);
+ break;
+ case 'hex':
+ output = input.match(/.{1,2}/g)?.map(byte => String.fromCharCode(parseInt(byte, 16))).join('') || '';
+ break;
+ }
+
+ document.getElementById('encodeOutput').value = output;
+ } catch(error) {
+ document.getElementById('encodeOutput').value = 'Invalid input for selected encoding';
+ }
+ }