JonnyPaes

Download Button

Mar 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getUrlParameters(parameter, staticURL, decode){
  2.  
  3.     var currLocation = (staticURL.length)? staticURL : window.location.search,
  4.      parArr = currLocation.split("?")[1].split("&"),
  5.      returnBool = true;
  6.  
  7.     for(var i = 0; i < parArr.length; i++){
  8.    parr = parArr[i].split("=");
  9.    if(parr[0] == parameter){
  10.     return (decode) ? decodeURIComponent(parr[1]) : parr[1];
  11.     returnBool = true;
  12.    }else{
  13.     returnBool = false;            
  14.    }
  15.     }
  16.  
  17.     if(!returnBool) return false;  
  18.  }
  19.  
  20.  $("#url").attr("href",url);
  21.  var url = getUrlParameters("url", "", true);
  22.  var data = window.atob(url);
  23.  
  24.  //alert(data);
  25.  //alert(url);
  26.  
  27.  var downloadButton = document.getElementById("espera");
  28.  var url = document.getElementById("url").href=("http://")+data;
  29.  var counter = 10;
  30.  var newElement = document.createElement("p");
  31.  newElement.innerHTML = "Você poderá baixar seu arquivo em 10 segundos.";
  32.  var id;
  33.  
  34.  downloadButton.parentNode.replaceChild(newElement, downloadButton);
  35.  
  36.  id = setInterval(function() {
  37.   counter--;
  38.   if(counter < 0) {
  39.    newElement.parentNode.replaceChild(downloadButton, newElement);
  40.    clearInterval(id);
  41.   } else {
  42.    newElement.innerHTML = "Você poderá baixar seu arquivo em " + counter.toString() + " segundos.";
  43.   }
  44.  }, 1000);
Add Comment
Please, Sign In to add comment