Skip to content

Commit

Permalink
0.1.0.26 save command last download and progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
rostok committed Dec 8, 2020
1 parent 15e689f commit e4e5c77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1631,9 +1631,11 @@ CmdUtils.CreateCommand({
author: "rostok",
icon: "res/icon-128.png",
require: ["https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js", "https://fastcdn.org/FileSaver.js/1.1.20151003/FileSaver.js"],
execute: function execute({text:text}) {
execute: function execute({text:text, _cmd:_cmd}) {
if (text.trim()=="") text = CmdUtils.getClipboard();

_cmd.lastDownload = undefined;
_cmd.lastFile = "";
_cmd.progress = [];
var time = 0;
var delay= 10;
var links = text.trim().split(/\s+/);
Expand All @@ -1644,6 +1646,20 @@ CmdUtils.CreateCommand({
var oReq = new XMLHttpRequest();
oReq.open("GET", l, true);
oReq.responseType = "blob";//"arraybuffer";
oReq.onprogress = (e)=>{
CmdUtils.popupWindow.console.log(e);
_cmd.progress[e.currentTarget.responseURL] = {loaded:e.loaded, total:e.total};
var lt = Object.values(_cmd.progress).reduce( (acc, cur)=>{console.log("a",acc,"c",cur); return {loaded:acc.loaded+cur.loaded,total:acc.total+cur.total}});
if (CmdUtils.popupWindow.ubiq_match_first_command()==_cmd.name) {
var prc = Math.round(lt.loaded*100/lt.total,1);
var s = "";
s += "<progress style='width:530px' value='"+prc+"' max='100'></progress><br><br>";
s += "loaded:"+lt.loaded+" / total:"+lt.total+" ("+prc+"%)<br><br>"
s += _cmd.lastFile;
CmdUtils.setPreview(s);
}
//CmdUtils.popupWindow.console.log("loaded:"+lt.loaded+" / total:"+lt.total+" ("+Math.round(lt.loaded*100/lt.total,1)+"%)");
};
oReq.onload = function(oEvent) {
var arrayBuffer = oReq.response;
var byteArray = new Uint8Array(arrayBuffer);
Expand Down Expand Up @@ -1734,9 +1750,10 @@ CmdUtils.CreateCommand({
zip.file(f, arrayBuffer);
i++;
//l+="<pre>"+JSON.stringify(filename)+"</pre>";
CmdUtils.setPreview(l+"<br>"+f+"<br>file:"+i+"/"+(array.length-1)+" <br>type:"+oReq.response.type);//+" <br>resp type:"+oReq.responseType);
//CmdUtils.setPreview(l+"<br>"+f+"<br>file:"+i+"/"+(array.length-1)+" <br>type:"+oReq.response.type);//+" <br>resp type:"+oReq.responseType);
_cmd.lastFile = l+"("+oReq.response.type+")";
if (i==array.length) {
CmdUtils.setPreview("done");
CmdUtils.setPreview("done!");

zip.generateAsync({type:"blob"})
.then(function (blob) {
Expand All @@ -1745,8 +1762,9 @@ CmdUtils.CreateCommand({
a.download = 'bulk.zip';
a.href = url.createObjectURL(blob);
CmdUtils.setPreview("");
a.textContent = 'done!';
a.textContent = 'save zip';
a.dataset.downloadurl = ['zip', a.download, a.href].join(':');
_cmd.lastDownload = a;
CmdUtils.popupWindow.jQuery("#ubiq-command-preview").append(a);
});
}
Expand All @@ -1755,10 +1773,13 @@ CmdUtils.CreateCommand({
}, time+=delay);
});
},
preview: function preview(pblock, {text:text}) {
preview: function preview(pblock, {text:text,_cmd:_cmd}) {
if (text.trim()=="") text = CmdUtils.getClipboard();
text = text.trim().split(/\s+/).map( (s,a) => { return "<br><a target=_blank href='"+s+"'>"+s+"</a>"; } ).join("");
pblock.innerHTML = "save as zip:" + text;
pblock.innerHTML = "download & zip:" + text;
if(_cmd.lastDownload !== undefined) {
jQuery(pblock).append("<hr>last download: ").append(_cmd.lastDownload);
}
},
});

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"short_name": "UbiChr",
"homepage_url": "https://github.com/rostok/ubichr",
"author": "rostok",
"version": "0.1.0.25",
"version": "0.1.0.26",
"description": "Revived Ubiquity for Chrome",
"content_security_policy": "script-src 'self' 'unsafe-eval' https://maps.googleapis.com https://cdnjs.cloudflare.com; object-src 'self'",
"manifest_version": 2,
Expand Down

0 comments on commit e4e5c77

Please sign in to comment.