mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 17:08:31 +01:00
Files can now be moved from the output to the input
This commit is contained in:
parent
a0aa363203
commit
e81122739b
4 changed files with 27 additions and 24 deletions
|
@ -84,7 +84,7 @@ InputWaiter.prototype.setFile = function(file) {
|
|||
fileOverlay.style.display = "block";
|
||||
fileName.textContent = file.name;
|
||||
fileSize.textContent = file.size.toLocaleString() + " bytes";
|
||||
fileType.textContent = file.type;
|
||||
fileType.textContent = file.type || "unknown";
|
||||
fileLoaded.textContent = "0%";
|
||||
};
|
||||
|
||||
|
|
|
@ -159,7 +159,7 @@ Manager.prototype.initialiseEventListeners = function() {
|
|||
this.addMultiEventListener("#output-html", "mousedown dblclick select", this.highlighter.outputHtmlMousedown, this.highlighter);
|
||||
this.addDynamicListener(".file-switch", "click", this.output.fileSwitch, this.output);
|
||||
this.addDynamicListener("#output-file-download", "click", this.output.downloadFile, this.output);
|
||||
this.addDynamicListener("#output-file-slice", "click", this.output.displayFile, this.output);
|
||||
this.addDynamicListener("#output-file-slice", "click", this.output.displayFileSlice, this.output);
|
||||
document.getElementById("show-file-overlay").addEventListener("click", this.output.showFileOverlayClick.bind(this.output));
|
||||
|
||||
// Options
|
||||
|
|
|
@ -18,6 +18,7 @@ const OutputWaiter = function(app, manager) {
|
|||
this.manager = manager;
|
||||
|
||||
this.dishBuffer = null;
|
||||
this.dishStr = null;
|
||||
};
|
||||
|
||||
|
||||
|
@ -47,7 +48,10 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
|
|||
const inputHighlighter = document.getElementById("input-highlighter");
|
||||
let scriptElements, lines, length;
|
||||
|
||||
if (!preserveBuffer) this.closeFile();
|
||||
if (!preserveBuffer) {
|
||||
this.closeFile();
|
||||
document.getElementById("show-file-overlay").style.display = "none";
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case "html":
|
||||
|
@ -60,6 +64,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
|
|||
outputText.value = "";
|
||||
outputHtml.innerHTML = data;
|
||||
length = data.length;
|
||||
this.dishStr = Utils.stripHtmlTags(data, true);
|
||||
|
||||
// Execute script sections
|
||||
scriptElements = outputHtml.querySelectorAll("script");
|
||||
|
@ -80,6 +85,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
|
|||
outputText.value = "";
|
||||
outputHtml.innerHTML = "";
|
||||
length = data.byteLength;
|
||||
this.dishStr = "";
|
||||
|
||||
this.setFile(data);
|
||||
break;
|
||||
|
@ -96,6 +102,7 @@ OutputWaiter.prototype.set = function(data, type, duration, preserveBuffer) {
|
|||
|
||||
lines = data.count("\n") + 1;
|
||||
length = data.length;
|
||||
this.dishStr = data;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -143,9 +150,9 @@ OutputWaiter.prototype.downloadFile = function() {
|
|||
|
||||
|
||||
/**
|
||||
* Handler for file display events.
|
||||
* Handler for file slice display events.
|
||||
*/
|
||||
OutputWaiter.prototype.displayFile = function() {
|
||||
OutputWaiter.prototype.displayFileSlice = function() {
|
||||
const startTime = new Date().getTime(),
|
||||
showFileOverlay = document.getElementById("show-file-overlay"),
|
||||
sliceFromEl = document.getElementById("output-file-slice-from"),
|
||||
|
@ -233,7 +240,7 @@ OutputWaiter.prototype.adjustWidth = function() {
|
|||
*/
|
||||
OutputWaiter.prototype.saveClick = function() {
|
||||
if (!this.dishBuffer) {
|
||||
this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.app.dishStr)).buffer;
|
||||
this.dishBuffer = new Uint8Array(Utils.strToCharcode(this.dishStr)).buffer;
|
||||
}
|
||||
this.downloadFile();
|
||||
};
|
||||
|
@ -254,14 +261,14 @@ OutputWaiter.prototype.copyClick = function() {
|
|||
textarea.style.height = 0;
|
||||
textarea.style.border = "none";
|
||||
|
||||
textarea.value = this.app.dishStr;
|
||||
textarea.value = this.dishStr;
|
||||
document.body.appendChild(textarea);
|
||||
|
||||
// Select and copy the contents of this textarea
|
||||
let success = false;
|
||||
try {
|
||||
textarea.select();
|
||||
success = textarea.value && document.execCommand("copy");
|
||||
success = this.dishStr && document.execCommand("copy");
|
||||
} catch (err) {
|
||||
success = false;
|
||||
}
|
||||
|
@ -284,7 +291,17 @@ OutputWaiter.prototype.copyClick = function() {
|
|||
OutputWaiter.prototype.switchClick = function() {
|
||||
this.switchOrigData = this.manager.input.get();
|
||||
document.getElementById("undo-switch").disabled = false;
|
||||
this.app.setInput(this.app.dishStr);
|
||||
if (this.dishBuffer) {
|
||||
this.manager.input.setFile(new File([this.dishBuffer], "output.dat"));
|
||||
this.manager.input.handleLoaderMessage({
|
||||
data: {
|
||||
progress: 100,
|
||||
fileBuffer: this.dishBuffer
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.app.setInput(this.dishStr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -378,7 +395,7 @@ OutputWaiter.prototype.setStatusMsg = function(msg) {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
OutputWaiter.prototype.containsCR = function() {
|
||||
return this.app.dishStr.indexOf("\r") >= 0;
|
||||
return this.dishStr.indexOf("\r") >= 0;
|
||||
};
|
||||
|
||||
export default OutputWaiter;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import Utils from "../core/Utils.js";
|
||||
import ChefWorker from "worker-loader?inline&fallback=false!../core/ChefWorker.js";
|
||||
|
||||
/**
|
||||
|
@ -111,19 +110,6 @@ WorkerWaiter.prototype.bakingComplete = function(response) {
|
|||
this.app.handleError(response.error);
|
||||
}
|
||||
|
||||
switch (response.type) {
|
||||
case "html":
|
||||
this.app.dishStr = Utils.stripHtmlTags(response.result, true);
|
||||
break;
|
||||
case "ArrayBuffer":
|
||||
this.app.dishStr = "";
|
||||
break;
|
||||
case "string":
|
||||
default:
|
||||
this.app.dishStr = response.result;
|
||||
break;
|
||||
}
|
||||
|
||||
this.app.progress = response.progress;
|
||||
this.manager.recipe.updateBreakpointIndicator(response.progress);
|
||||
this.manager.output.set(response.result, response.type, response.duration);
|
||||
|
|
Loading…
Reference in a new issue