File size: 1,298 Bytes
3711b12
 
 
 
 
 
 
8a95070
3711b12
 
 
6464fdf
3711b12
 
 
 
a6d3732
 
3711b12
6464fdf
 
 
 
 
 
 
 
 
 
 
a6d3732
 
 
 
 
 
 
 
 
 
3711b12
6464fdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const textGenForm = document.querySelector(".text-gen-form");

const translateText = async (text) => {
  const inferResponse = await fetch(`predict?domain=${text}`);
  const inferJson = await inferResponse.json();
  console.log(inferResponse);
  console.log(inferJson);
  const res = `domain:"${text}",probDGA:${inferJson.probability},isDGA?:${inferJson.class}`;
  return res
};


textGenForm.addEventListener("submit", async (event) => {
  event.preventDefault();

  const textGenInput = document.getElementById("text-gen-input");
  const textGenParagraph = document.querySelector(".text-gen-output"); 
  const copyButton = document.querySelector('.copy-icon');

  // Split the inputted text into separate domains
  const domains = textGenInput.value.trim().split('\n');
  
  let output = '';
  
  // Loop over each domain and submit it to the URL one at a time
  for (let i = 0; i < domains.length; i++) {
    output += await translateText(domains[i]) + '\n';
  }
  
  textGenParagraph.textContent = output;
  copyButton.addEventListener('click', () => {
	      const textarea = document.createElement('textarea');
	      textarea.value = output;
	      document.body.appendChild(textarea);
	      textarea.select();
	      document.execCommand('copy');
	      textarea.remove();
	    });


});