mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-25 01:06:16 -04:00
Added more help topics and added filetype detection to the 'save output' button
This commit is contained in:
parent
4c7fe147bc
commit
7419009745
3 changed files with 63 additions and 40 deletions
|
@ -270,23 +270,36 @@ class BindingsWaiter {
|
|||
* Shows contextual help message based on where the mouse pointer is
|
||||
*/
|
||||
contextualHelp() {
|
||||
const hoveredHelpEls = document.querySelectorAll(":hover[data-help]");
|
||||
const hoveredHelpEls = document.querySelectorAll(":hover[data-help],:hover[data-help-proxy]");
|
||||
if (!hoveredHelpEls.length) return;
|
||||
|
||||
if (hoveredHelpEls.length) {
|
||||
const helpEl = hoveredHelpEls[hoveredHelpEls.length - 1],
|
||||
helpText = helpEl.getAttribute("data-help");
|
||||
let helpTitle = helpEl.getAttribute("data-help-title");
|
||||
|
||||
if (helpTitle)
|
||||
helpTitle = "<span class='text-muted'>Help topic:</span> " + helpTitle;
|
||||
else
|
||||
helpTitle = "<span class='text-muted'>Help topic</span>";
|
||||
|
||||
document.querySelector("#help-modal .modal-body").innerHTML = helpText;
|
||||
document.querySelector("#help-modal #help-title").innerHTML = helpTitle;
|
||||
|
||||
$("#help-modal").modal();
|
||||
let helpEl = hoveredHelpEls[hoveredHelpEls.length - 1];
|
||||
const helpElSelector = helpEl.getAttribute("data-help-proxy");
|
||||
if (helpElSelector) {
|
||||
// A hovered element is directing us to another element for its help text
|
||||
helpEl = document.querySelector(helpElSelector);
|
||||
}
|
||||
this.displayHelp(helpEl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the help pane populated with help text associated with the given element
|
||||
*
|
||||
* @param {Element} el
|
||||
*/
|
||||
displayHelp(el) {
|
||||
const helpText = el.getAttribute("data-help");
|
||||
let helpTitle = el.getAttribute("data-help-title");
|
||||
|
||||
if (helpTitle)
|
||||
helpTitle = "<span class='text-muted'>Help topic:</span> " + helpTitle;
|
||||
else
|
||||
helpTitle = "<span class='text-muted'>Help topic</span>";
|
||||
|
||||
document.querySelector("#help-modal .modal-body").innerHTML = helpText;
|
||||
document.querySelector("#help-modal #help-title").innerHTML = helpTitle;
|
||||
|
||||
$("#help-modal").modal();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import Utils, {debounce} from "../../core/Utils.mjs";
|
||||
import Dish from "../../core/Dish.mjs";
|
||||
import {detectFileType} from "../../core/lib/FileType.mjs";
|
||||
import FileSaver from "file-saver";
|
||||
import ZipWorker from "worker-loader?inline=no-fallback!../workers/ZipWorker.mjs";
|
||||
|
||||
|
@ -765,13 +766,22 @@ class OutputWaiter {
|
|||
this.app.alert("Could not find any output data to download. Has this output been baked?", 3000);
|
||||
return;
|
||||
}
|
||||
const fileName = window.prompt("Please enter a filename: ", "download.dat");
|
||||
|
||||
const data = await dish.get(Dish.ARRAY_BUFFER);
|
||||
let ext = ".dat";
|
||||
|
||||
// Detect file type automatically
|
||||
const types = detectFileType(data);
|
||||
if (types.length) {
|
||||
ext = `.${types[0].extension.split(",", 1)[0]}`;
|
||||
}
|
||||
|
||||
const fileName = window.prompt("Please enter a filename: ", `download${ext}`);
|
||||
|
||||
// Assume if the user clicks cancel they don't want to download
|
||||
if (fileName === null) return;
|
||||
|
||||
const data = await dish.get(Dish.ARRAY_BUFFER),
|
||||
file = new File([data], fileName);
|
||||
const file = new File([data], fileName);
|
||||
FileSaver.saveAs(file, fileName, {autoBom: false});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue