]> git.ardis.lu - ens2hex/commitdiff
Move querySelectors closer to their usage
authorArdis Lu <ardisglu@gmail.com>
Sun, 21 Aug 2022 06:44:35 +0000 (23:44 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 21 Aug 2022 06:44:35 +0000 (23:44 -0700)
index.html

index 7a25b03bb534e63ebe2e62a1e8cb598b4ab2ff3b..7da97cf63cb44fee75bb5e1f82d369418c4ddfef 100644 (file)
       return k.digest();
     }
 
-    const form = document.querySelector('form');
-    const div = document.querySelector('div');
-    const input = document.querySelector('input');
-    const output = document.querySelector('output');
-    const table = document.querySelector('table');
-
     // Implement drag and drop file upload
     window.addEventListener('dragover', e => e.preventDefault());
     window.addEventListener('drop', e => e.preventDefault());
+    const div = document.querySelector('div');
+    const input = document.querySelector('input');
     div.addEventListener('drop', e => input.files = e.dataTransfer.files);
     div.addEventListener('click', _ => input.click());
     input.addEventListener('click', e => e.stopPropagation()); // Prevent 'click' from getting propagated to div (or else there will be two dialogs)
       return [...hash].map(v => v.toString(16).padStart(2, '0')).join(''); // Convert byte array into 0-padded string. Must spread typed array into non-typed array to allow .map() to output strings
     }
 
-    form.addEventListener('submit', async event => {
+    document.querySelector('form').addEventListener('submit', async event => {
       event.preventDefault();
 
       const formData = new FormData(event.target);
         body: JSON.stringify(batchPayload),
       }).then(r => r.json());
 
+      const table = document.querySelector('table');
       table.querySelector('tbody')?.remove(); // Clear previous rows, if any
       const body = table.createTBody();
       for (const [index, name] of cleaned.entries()) {
         address.textContent = `0x${response.result.slice(26)}`;
       }
 
-      output.style.display = 'block';
+      document.querySelector('output').style.display = 'block';
     });
   </script>
 </body>
This page took 0.034083 seconds and 4 git commands to generate.