Skip to content

Commit 4619a51

Browse files
authored
Merge pull request #541 from TheZ3ro/hide-recipe-options
2 parents cc28c6a + 670c370 commit 4619a51

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

src/web/HTMLOperation.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class HTMLOperation {
8585
<div class="recip-icons">
8686
<i class="material-icons breakpoint" title="Set breakpoint" break="false" data-help-title="Setting breakpoints" data-help="Setting a breakpoint on an operation will cause execution of the Recipe to pause when it reaches that operation.">pause</i>
8787
<i class="material-icons disable-icon" title="Disable operation" disabled="false" data-help-title="Disabling operations" data-help="Disabling an operation will prevent it from being executed when the Recipe is baked. Execution will skip over the disabled operation and continue with subsequent operations.">not_interested</i>
88+
<i class="material-icons hide-args-icon" title="Hide operation's arguments" hide-args="false" data-help-title="Hide operation's arguments" data-help="Hiding an operation's argument will save space in the Recipe window. Execution will still take place with the selected argument options.">keyboard_arrow_up</i>
8889
</div>
8990
<div class="clearfix">&nbsp;</div>`;
9091

src/web/Manager.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class Manager {
139139
document.getElementById("load-delete-button").addEventListener("click", this.controls.loadDeleteClick.bind(this.controls));
140140
document.getElementById("load-name").addEventListener("change", this.controls.loadNameChange.bind(this.controls));
141141
document.getElementById("load-button").addEventListener("click", this.controls.loadButtonClick.bind(this.controls));
142+
document.getElementById("hide-icon").addEventListener("click", this.controls.hideRecipeArgsClick.bind(this.recipe));
142143
document.getElementById("support").addEventListener("click", this.controls.supportButtonClick.bind(this.controls));
143144
this.addMultiEventListeners("#save-texts textarea", "keyup paste", this.controls.saveTextChange, this.controls);
144145

@@ -154,6 +155,7 @@ class Manager {
154155
// Recipe
155156
this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe);
156157
this.addDynamicListener(".arg[type=checkbox], .arg[type=radio], select.arg", "change", this.recipe.ingChange, this.recipe);
158+
this.addDynamicListener(".hide-args-icon", "click", this.recipe.hideArgsClick, this.recipe);
157159
this.addDynamicListener(".disable-icon", "click", this.recipe.disableClick, this.recipe);
158160
this.addDynamicListener(".breakpoint", "click", this.recipe.breakpointClick, this.recipe);
159161
this.addDynamicListener("#rec-list li.operation", "dblclick", this.recipe.operationDblclick, this.recipe);

src/web/html/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@
181181
<div class="title no-select">
182182
Recipe
183183
<span class="pane-controls hide-on-maximised-output">
184+
<button type="button" aria-label="Hide arguments" class="btn btn-primary bmd-btn-icon" id="hide-icon" data-toggle="tooltip" title="Hide arguments" hide-args="false" data-help-title="Hiding every Operation's argument view in a Recipe" data-help="Clicking 'Hide arguments' will hide all the argument views for every Operation in the Recipe, to save space when you have too many Operation in your Recipe">
185+
<i class="material-icons">keyboard_arrow_up</i>
186+
</button>
184187
<button type="button" aria-label="Save recipe" class="btn btn-primary bmd-btn-icon" id="save" data-toggle="tooltip" title="Save recipe" data-help-title="Saving a recipe" data-help="<p>Recipes can be represented in a few different formats and saved for use at a later date. You can either copy the Recipe configuration and save it somewhere offline for later use, or use your browser's local storage.</p><ul><li><b>Deep link:</b> The easiest way to share a CyberChef Recipe is to copy the deep link, either from the address bar (which is updated as the Recipe or Input changes), or from the 'Save recipe' pane. When you visit this link, the Recipe and Input should be populated from where you left off.</li><li><b>Chef format:</b> This custom format is designed to be compact and easily readable. It is the format used in CyberChef's URL, so it largely uses characters that do not have to be escaped in URL encoding, making it a little easier to understand what a CyberChef URL contains.</li><li><b>Clean JSON:</b> This JSON format uses whitespace and indentation in a way that makes the Recipe easy to read.</li><li><b>Compact JSON:</b> This is the most compact way that the Recipe can be represented in JSON.</li><li><b>Local storage:</b> Alternatively, you can enter a name into the 'Recipe name' field and save to your browser's local storage. The Recipe will then be available to load from the 'Load Recipe' pane as long as you are using the same browser profile. Be aware that if your browser profile is cleaned, you may lose this data.</li></ul>">
185188
<i class="material-icons" aria-hidden="true">save</i>
186189
</button>

src/web/waiters/ControlsWaiter.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,36 @@ class ControlsWaiter {
345345
}
346346

347347

348+
/**
349+
* Hides the arguments for all the operations in the current recipe.
350+
*/
351+
hideRecipeArgsClick() {
352+
const icon = document.getElementById("hide-icon");
353+
354+
if (icon.getAttribute("hide-args") === "false") {
355+
icon.setAttribute("hide-args", "true");
356+
icon.setAttribute("data-original-title", "Show arguments");
357+
icon.children[0].innerText = "keyboard_arrow_down";
358+
Array.from(document.getElementsByClassName("hide-args-icon")).forEach(function(item) {
359+
item.setAttribute("hide-args", "true");
360+
item.innerText = "keyboard_arrow_down";
361+
item.classList.add("hide-args-selected");
362+
item.parentNode.previousElementSibling.style.display = "none";
363+
});
364+
} else {
365+
icon.setAttribute("hide-args", "false");
366+
icon.setAttribute("data-original-title", "Hide arguments");
367+
icon.children[0].innerText = "keyboard_arrow_up";
368+
Array.from(document.getElementsByClassName("hide-args-icon")).forEach(function(item) {
369+
item.setAttribute("hide-args", "false");
370+
item.innerText = "keyboard_arrow_up";
371+
item.classList.remove("hide-args-selected");
372+
item.parentNode.previousElementSibling.style.display = "grid";
373+
});
374+
}
375+
}
376+
377+
348378
/**
349379
* Populates the bug report information box with useful technical info.
350380
*

src/web/waiters/RecipeWaiter.mjs

+39
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,45 @@ class RecipeWaiter {
215215
window.dispatchEvent(this.manager.statechange);
216216
}
217217

218+
/**
219+
* Handler for hide-args click events.
220+
* Updates the icon status.
221+
*
222+
* @fires Manager#statechange
223+
* @param {event} e
224+
*/
225+
hideArgsClick(e) {
226+
const icon = e.target;
227+
228+
if (icon.getAttribute("hide-args") === "false") {
229+
icon.setAttribute("hide-args", "true");
230+
icon.innerText = "keyboard_arrow_down";
231+
icon.classList.add("hide-args-selected");
232+
icon.parentNode.previousElementSibling.style.display = "none";
233+
} else {
234+
icon.setAttribute("hide-args", "false");
235+
icon.innerText = "keyboard_arrow_up";
236+
icon.classList.remove("hide-args-selected");
237+
icon.parentNode.previousElementSibling.style.display = "grid";
238+
}
239+
240+
const icons = Array.from(document.getElementsByClassName("hide-args-icon"));
241+
if (icons.length > 1) {
242+
// Check if ALL the icons are hidden/shown
243+
const uniqueIcons = icons.map(function(item) {
244+
return item.getAttribute("hide-args");
245+
}).unique();
246+
247+
const controlsIconStatus = document.getElementById("hide-icon").getAttribute("hide-args");
248+
249+
// If all icons are in the same state and the global icon isn't, fix it
250+
if (uniqueIcons.length === 1 && icon.getAttribute("hide-args") !== controlsIconStatus) {
251+
this.manager.controls.hideRecipeArgsClick();
252+
}
253+
}
254+
255+
window.dispatchEvent(this.manager.statechange);
256+
}
218257

219258
/**
220259
* Handler for disable click events.

0 commit comments

Comments
 (0)