Advertisement
Guest User

File

a guest
Mar 23rd, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tamanho(conexao, arquivo) {
  2.     if (conexao == "56") {
  3.         c = "56 Kbps";
  4.     }
  5.     if (conexao == "128") {
  6.         c = "128 Kbps";
  7.     }
  8.     if (conexao == "256") {
  9.         c = "256 Kbps";
  10.     }
  11.     if (conexao == "512") {
  12.         c = "512 Kbps";
  13.     }
  14.     if (conexao == "1024") {
  15.         c = "1 Mbps";
  16.     }
  17.     if (conexao == "2048") {
  18.         c = "2 Mbps";
  19.     }
  20.     if (conexao == "4096") {
  21.         c = "4 Mbps";
  22.     }
  23.     if (arquivo.match(" B")) {
  24.         d = "1";
  25.     }
  26.     if (arquivo.match(" KB")) {
  27.         d = "1024";
  28.     }
  29.     if (arquivo.match(" MB")) {
  30.         d = "1048576";
  31.     }
  32.     if (arquivo.match(" GB")) {
  33.         d = "1073741824";
  34.     }
  35.     arquivo = arquivo.replace(",", ".");
  36.     arquivo = arquivo.replace(RegExp("B|KB|MB|GB"), "");
  37.     var e = (arquivo * d) / (conexao * 1000 / 8);
  38.     var f = {
  39.         segundo: 60,
  40.         minuto: 60,
  41.         hora: 24,
  42.         dia: 365,
  43.         ano: Number.MAX_VALUE
  44.     };
  45.     var g = '';
  46.     var h = [];
  47.     if (e > 0 && e < .001) {
  48.         g = '1 segundo'
  49.     } else {
  50.         if (e < 1) {
  51.             g = Math.round(e * 1000) + ' segundos'
  52.         } else {
  53.             if (e < 60) {
  54.                 g = e.toFixed(2) + ' segundos'
  55.             } else {
  56.                 e = Math.round(e);
  57.                 for (var unit in f) {
  58.                     var n = e % f[unit];
  59.                     e -= n;
  60.                     e /= f[unit];
  61.                     h.unshift(n + ' ' + unit + (n != 1 ? 's' : ''));
  62.                     if (e == 0) {
  63.                         break
  64.                     }
  65.                 }
  66.                 g = h.slice(0, 3).join(' e ')
  67.             }
  68.         }
  69.     }
  70.     document.write("<b>" + c + "</b> - " + g + "<br>")
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement