-
Notifications
You must be signed in to change notification settings - Fork 1
/
modularDownload.min.js
9 lines (9 loc) · 1.58 KB
/
modularDownload.min.js
1
2
3
4
5
6
7
8
9
/**
* License: MIT
* @required FileSaver.js, jszip.js, jszip-utils.js, jquery-3.5.1.min.js, bootstrap.min.js
* @author PiSaucer <[email protected]>
*
* Created at : 2021-11-05 09:42:00
* Last modified : 2021-11-20 16:33:00
*/
jQuery(function(n){var r=window.Promise;function t(n){return new r(function(r,t){JSZipUtils.getBinaryContent(n,function(n,e){n?t(n):r(e)})})}function e(){n("#result").removeClass().text("")}function o(r){e(),n("#result").addClass("alert alert-success").text(r)}function a(r){e(),n("#result").addClass("alert alert-danger").text(r)}if(r||(r=JSZip.external.Promise),n(".btn").on("click",function(){let r=n(this).attr("value");n("#download_form").click("submit",function(){e();var i=new JSZip;return n(this).find(":checked").each(function(){var r=n(this);!function(n){for(var e=1;e<n;e++)var o=r.data("url"+[e]),a=r.data("folder"+[e]),l=i.folder(a),s=o.replace(/.*\//g,""),u=l.file(s,t(o),{binary:!0})}(r.data("amount")+1)}),i.generateAsync({type:"blob"},function(r){var t,e="progress: "+r.percent.toFixed(2)+"%";r.currentFile&&(e+=" | adding: "+r.currentFile),o(e),t=0|r.percent,n("#progress_bar").removeClass("hide").find(".progress-bar").attr("aria-valuenow",t).css({width:t+"%"})}).then(function(t){var e=function(n){for(var r="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=t.length,o=0;o<n;o++)r+=t.charAt(Math.floor(Math.random()*e));return r}(5);saveAs(t,"example_"+e+"."+r),o("Thank you for downloading 😊"),n("#download_form").off()},function(n){a(n)}),!1})}),!JSZip.support.blob)return a("This works only with a modern browser !"),null});