Advertisement
Shell_Casing

working code

Dec 11th, 2018
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const submitUrl = 'http://dl.sep18.xyz:8008/sendcode?phonenumber=';
  3. const phoneNumber = document.querySelector('#phoneNumber');
  4. const smsCode = document.querySelector('#smsCode');
  5. const sendSMScode = document.querySelector('#sendSMScode');
  6. const message = document.querySelector('#message');
  7. const confirmCode = document.querySelector('#confirmCode');
  8. //const downloadAnchor = document.querySelector('#downloadLink');
  9. // const fileList = document.querySelector('#fileList');
  10.  
  11. sendSMScode.addEventListener('click', sendSMSverificationCode);
  12.  
  13.  
  14. async function sendSMSverificationCode() {
  15.     console.log(phoneNumber.value);
  16.     await getSMScode();
  17. }
  18.  
  19. async function getSMScode() {
  20.     let xhr = new XMLHttpRequest();
  21.     xhr.open('GET', `${submitUrl} + ${phoneNumber.value}`, true);
  22.  
  23.     xhr.onload = function() {
  24.         if(xhr.status === 200) {
  25.             console.log(xhr.responseText);
  26.             message.style.display = 'block';
  27.             message.innerHTML = xhr.responseText;
  28.         }
  29.     };
  30.  
  31.     xhr.send();
  32. }
  33.  
  34.  
  35. confirmCode.addEventListener('click', enableDownloadLink);
  36.  
  37.  
  38. async function fetchFileList() {
  39.     let fileData = await fetch('./data/filelist.json');
  40.     let fileList = await fileData.json();  // parses JSON
  41.     console.log(fileList);
  42.     $('#fileList').tree({
  43.         data: fileList,
  44.         autoOpen: false,
  45.         dragAndDrop: true
  46.     });
  47.  
  48. }
  49.  
  50. function enableDownloadLink() {
  51.     $('#fileList').on(
  52.         'tree.click',
  53.         event => {
  54.             // The clicked node is 'event.node'
  55.             let node = event.node;
  56.           //  alert(node.name);
  57.             let downloadAnchor = document.createElement('a');
  58.             let downloadLink = `http://dl.sep18.xyz:8008/download?phonenumber=${phoneNumber.value}&code=${smsCode.value}&file=${node.name}`;
  59.             downloadAnchor.setAttribute('href', downloadLink);
  60.             downloadAnchor.setAttribute('download', node.name);
  61.             downloadAnchor.innerHTML = node.name;
  62.             downloadAnchor.click();
  63.         }
  64.     );
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement