File size: 2,661 Bytes
7cf32bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
  <head>
    <title>{{title}}</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">

    <script src="/socket.io/socket.io.js"></script>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>


  </head>
  <body>
    {{{body}}}
  </body>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-120895783-4"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-120895783-4');
</script>

<script>
  var numberOfFiles = 0;
  const downloadWebsite = document.getElementsByClassName('btn-success')[0];
  // connect to current socket.io server
  var socket = io.connect(document.URL);
  if(!localStorage['token'])
  localStorage['token']=generateToken(20);
  
  // wait for events for this token
  socket.on(localStorage['token'],(event)=>{
  console.log(event)
  document.getElementById('progress').hidden=false;
  if(event.progress=="Converting")
  {
    log.innerHTML=(`<h5>100%! Compressing your website...</h5><br>`)

  }
   else if(event.progress=="Completed")
   {
        document.getElementById('progress').hidden=true;
        log.innerHTML=(`<code>Compressing completed successfully !</code><br>`)
        downloadWebsite.style='display:'
        downloadWebsite.onclick=function()
        {
         window.location='/tmp/'+event.file+".zip";
        }

   }
   else
   {
        const log = document.getElementById('log');
        if(event.progress.includes('200 OK'))
        numberOfFiles++;
        document.getElementById('nFilesP').hidden=false;
        document.getElementById('nFiles').innerHTML=numberOfFiles
        log.innerHTML=(`<code> ${event.progress}</code><br>`)
   }
  })
  
  // Download a website on click
   const downloadBtn =  document.getElementById("download");
   downloadBtn.onclick=()=>{
        var website = document.getElementById('website').value
        console.log("Now downloading the website ... %s",website)
        socket.emit('request', { token: localStorage['token'] , website});
   }





  // Generate token for each user for the first time.
  function generateToken(n) {
    var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    var token = '';
    for(var i = 0; i < n; i++) {
        token += chars[Math.floor(Math.random() * chars.length)];
    }
    return token;
}
</script>


</html>