mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
Variable names changed from underscore to CamelCase. Eslint rules updated. #64
This commit is contained in:
parent
f8193797fa
commit
e3c977934b
66 changed files with 3176 additions and 3172 deletions
|
@ -19,15 +19,15 @@ var ControlsWaiter = function(app, manager) {
|
|||
* Adjusts the display properties of the control buttons so that they fit within the current width
|
||||
* without wrapping or overflowing.
|
||||
*/
|
||||
ControlsWaiter.prototype.adjust_width = function() {
|
||||
var controls = document.getElementById("controls"),
|
||||
step = document.getElementById("step"),
|
||||
clr_breaks = document.getElementById("clr-breaks"),
|
||||
save_img = document.querySelector("#save img"),
|
||||
load_img = document.querySelector("#load img"),
|
||||
step_img = document.querySelector("#step img"),
|
||||
clr_recip_img = document.querySelector("#clr-recipe img"),
|
||||
clr_breaks_img = document.querySelector("#clr-breaks img");
|
||||
ControlsWaiter.prototype.adjustWidth = function() {
|
||||
var controls = document.getElementById("controls"),
|
||||
step = document.getElementById("step"),
|
||||
clrBreaks = document.getElementById("clr-breaks"),
|
||||
saveImg = document.querySelector("#save img"),
|
||||
loadImg = document.querySelector("#load img"),
|
||||
stepImg = document.querySelector("#step img"),
|
||||
clrRecipImg = document.querySelector("#clr-recipe img"),
|
||||
clrBreaksImg = document.querySelector("#clr-breaks img");
|
||||
|
||||
if (controls.clientWidth < 470) {
|
||||
step.childNodes[1].nodeValue = " Step";
|
||||
|
@ -36,23 +36,23 @@ ControlsWaiter.prototype.adjust_width = function() {
|
|||
}
|
||||
|
||||
if (controls.clientWidth < 400) {
|
||||
save_img.style.display = "none";
|
||||
load_img.style.display = "none";
|
||||
step_img.style.display = "none";
|
||||
clr_recip_img.style.display = "none";
|
||||
clr_breaks_img.style.display = "none";
|
||||
saveImg.style.display = "none";
|
||||
loadImg.style.display = "none";
|
||||
stepImg.style.display = "none";
|
||||
clrRecipImg.style.display = "none";
|
||||
clrBreaksImg.style.display = "none";
|
||||
} else {
|
||||
save_img.style.display = "inline";
|
||||
load_img.style.display = "inline";
|
||||
step_img.style.display = "inline";
|
||||
clr_recip_img.style.display = "inline";
|
||||
clr_breaks_img.style.display = "inline";
|
||||
saveImg.style.display = "inline";
|
||||
loadImg.style.display = "inline";
|
||||
stepImg.style.display = "inline";
|
||||
clrRecipImg.style.display = "inline";
|
||||
clrBreaksImg.style.display = "inline";
|
||||
}
|
||||
|
||||
if (controls.clientWidth < 330) {
|
||||
clr_breaks.childNodes[1].nodeValue = " Clear breaks";
|
||||
clrBreaks.childNodes[1].nodeValue = " Clear breaks";
|
||||
} else {
|
||||
clr_breaks.childNodes[1].nodeValue = " Clear breakpoints";
|
||||
clrBreaks.childNodes[1].nodeValue = " Clear breakpoints";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -62,11 +62,11 @@ ControlsWaiter.prototype.adjust_width = function() {
|
|||
*
|
||||
* @param {boolean} value - The new value for Auto Bake.
|
||||
*/
|
||||
ControlsWaiter.prototype.set_auto_bake = function(value) {
|
||||
var auto_bake_checkbox = document.getElementById("auto-bake");
|
||||
ControlsWaiter.prototype.setAutoBake = function(value) {
|
||||
var autoBakeCheckbox = document.getElementById("auto-bake");
|
||||
|
||||
if (auto_bake_checkbox.checked !== value) {
|
||||
auto_bake_checkbox.click();
|
||||
if (autoBakeCheckbox.checked !== value) {
|
||||
autoBakeCheckbox.click();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -74,7 +74,7 @@ ControlsWaiter.prototype.set_auto_bake = function(value) {
|
|||
/**
|
||||
* Handler to trigger baking.
|
||||
*/
|
||||
ControlsWaiter.prototype.bake_click = function() {
|
||||
ControlsWaiter.prototype.bakeClick = function() {
|
||||
this.app.bake();
|
||||
$("#output-text").selectRange(0);
|
||||
};
|
||||
|
@ -83,7 +83,7 @@ ControlsWaiter.prototype.bake_click = function() {
|
|||
/**
|
||||
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
||||
*/
|
||||
ControlsWaiter.prototype.step_click = function() {
|
||||
ControlsWaiter.prototype.stepClick = function() {
|
||||
this.app.bake(true);
|
||||
$("#output-text").selectRange(0);
|
||||
};
|
||||
|
@ -92,18 +92,18 @@ ControlsWaiter.prototype.step_click = function() {
|
|||
/**
|
||||
* Handler for changes made to the Auto Bake checkbox.
|
||||
*/
|
||||
ControlsWaiter.prototype.auto_bake_change = function() {
|
||||
var auto_bake_label = document.getElementById("auto-bake-label"),
|
||||
auto_bake_checkbox = document.getElementById("auto-bake");
|
||||
ControlsWaiter.prototype.autoBakeChange = function() {
|
||||
var autoBakeLabel = document.getElementById("auto-bake-label"),
|
||||
autoBakeCheckbox = document.getElementById("auto-bake");
|
||||
|
||||
this.app.auto_bake_ = auto_bake_checkbox.checked;
|
||||
this.app.autoBake_ = autoBakeCheckbox.checked;
|
||||
|
||||
if (auto_bake_checkbox.checked) {
|
||||
auto_bake_label.classList.remove("btn-default");
|
||||
auto_bake_label.classList.add("btn-success");
|
||||
if (autoBakeCheckbox.checked) {
|
||||
autoBakeLabel.classList.remove("btn-default");
|
||||
autoBakeLabel.classList.add("btn-success");
|
||||
} else {
|
||||
auto_bake_label.classList.remove("btn-success");
|
||||
auto_bake_label.classList.add("btn-default");
|
||||
autoBakeLabel.classList.remove("btn-success");
|
||||
autoBakeLabel.classList.add("btn-default");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -111,8 +111,8 @@ ControlsWaiter.prototype.auto_bake_change = function() {
|
|||
/**
|
||||
* Handler for the 'Clear recipe' command. Removes all operations from the recipe.
|
||||
*/
|
||||
ControlsWaiter.prototype.clear_recipe_click = function() {
|
||||
this.manager.recipe.clear_recipe();
|
||||
ControlsWaiter.prototype.clearRecipeClick = function() {
|
||||
this.manager.recipe.clearRecipe();
|
||||
};
|
||||
|
||||
|
||||
|
@ -120,8 +120,8 @@ ControlsWaiter.prototype.clear_recipe_click = function() {
|
|||
* Handler for the 'Clear breakpoints' command. Removes all breakpoints from operations in the
|
||||
* recipe.
|
||||
*/
|
||||
ControlsWaiter.prototype.clear_breaks_click = function() {
|
||||
var bps = document.querySelectorAll("#rec_list li.operation .breakpoint");
|
||||
ControlsWaiter.prototype.clearBreaksClick = function() {
|
||||
var bps = document.querySelectorAll("#rec-list li.operation .breakpoint");
|
||||
|
||||
for (var i = 0; i < bps.length; i++) {
|
||||
bps[i].setAttribute("break", "false");
|
||||
|
@ -133,49 +133,49 @@ ControlsWaiter.prototype.clear_breaks_click = function() {
|
|||
/**
|
||||
* Populates the save disalog box with a URL incorporating the recipe and input.
|
||||
*
|
||||
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
||||
* @param {Object[]} [recipeConfig] - The recipe configuration object array.
|
||||
*/
|
||||
ControlsWaiter.prototype.initialise_save_link = function(recipe_config) {
|
||||
recipe_config = recipe_config || this.app.get_recipe_config();
|
||||
ControlsWaiter.prototype.initialiseSaveLink = function(recipeConfig) {
|
||||
recipeConfig = recipeConfig || this.app.getRecipeConfig();
|
||||
|
||||
var include_recipe = document.getElementById("save-link-recipe-checkbox").checked,
|
||||
include_input = document.getElementById("save-link-input-checkbox").checked,
|
||||
save_link_el = document.getElementById("save-link"),
|
||||
save_link = this.generate_state_url(include_recipe, include_input, recipe_config);
|
||||
var includeRecipe = document.getElementById("save-link-recipe-checkbox").checked,
|
||||
includeInput = document.getElementById("save-link-input-checkbox").checked,
|
||||
saveLinkEl = document.getElementById("save-link"),
|
||||
saveLink = this.generateStateUrl(includeRecipe, includeInput, recipeConfig);
|
||||
|
||||
save_link_el.innerHTML = Utils.truncate(save_link, 120);
|
||||
save_link_el.setAttribute("href", save_link);
|
||||
saveLinkEl.innerHTML = Utils.truncate(saveLink, 120);
|
||||
saveLinkEl.setAttribute("href", saveLink);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Generates a URL containing the current recipe and input state.
|
||||
*
|
||||
* @param {boolean} include_recipe - Whether to include the recipe in the URL.
|
||||
* @param {boolean} include_input - Whether to include the input in the URL.
|
||||
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
||||
* @param {boolean} includeRecipe - Whether to include the recipe in the URL.
|
||||
* @param {boolean} includeInput - Whether to include the input in the URL.
|
||||
* @param {Object[]} [recipeConfig] - The recipe configuration object array.
|
||||
* @returns {string}
|
||||
*/
|
||||
ControlsWaiter.prototype.generate_state_url = function(include_recipe, include_input, recipe_config) {
|
||||
recipe_config = recipe_config || this.app.get_recipe_config();
|
||||
ControlsWaiter.prototype.generateStateUrl = function(includeRecipe, includeInput, recipeConfig) {
|
||||
recipeConfig = recipeConfig || this.app.getRecipeConfig();
|
||||
|
||||
var link = window.location.protocol + "//" +
|
||||
window.location.host +
|
||||
window.location.pathname,
|
||||
recipe_str = JSON.stringify(recipe_config),
|
||||
input_str = Utils.to_base64(this.app.get_input(), "A-Za-z0-9+/"); // B64 alphabet with no padding
|
||||
recipeStr = JSON.stringify(recipeConfig),
|
||||
inputStr = Utils.toBase64(this.app.getInput(), "A-Za-z0-9+/"); // B64 alphabet with no padding
|
||||
|
||||
include_recipe = include_recipe && (recipe_config.length > 0);
|
||||
include_input = include_input && (input_str.length > 0) && (input_str.length < 8000);
|
||||
includeRecipe = includeRecipe && (recipeConfig.length > 0);
|
||||
includeInput = includeInput && (inputStr.length > 0) && (inputStr.length < 8000);
|
||||
|
||||
if (include_recipe) {
|
||||
link += "?recipe=" + encodeURIComponent(recipe_str);
|
||||
if (includeRecipe) {
|
||||
link += "?recipe=" + encodeURIComponent(recipeStr);
|
||||
}
|
||||
|
||||
if (include_recipe && include_input) {
|
||||
link += "&input=" + encodeURIComponent(input_str);
|
||||
} else if (include_input) {
|
||||
link += "?input=" + encodeURIComponent(input_str);
|
||||
if (includeRecipe && includeInput) {
|
||||
link += "&input=" + encodeURIComponent(inputStr);
|
||||
} else if (includeInput) {
|
||||
link += "?input=" + encodeURIComponent(inputStr);
|
||||
}
|
||||
|
||||
return link;
|
||||
|
@ -185,10 +185,10 @@ ControlsWaiter.prototype.generate_state_url = function(include_recipe, include_i
|
|||
/**
|
||||
* Handler for changes made to the save dialog text area. Re-initialises the save link.
|
||||
*/
|
||||
ControlsWaiter.prototype.save_text_change = function() {
|
||||
ControlsWaiter.prototype.saveTextChange = function() {
|
||||
try {
|
||||
var recipe_config = JSON.parse(document.getElementById("save-text").value);
|
||||
this.initialise_save_link(recipe_config);
|
||||
var recipeConfig = JSON.parse(document.getElementById("save-text").value);
|
||||
this.initialiseSaveLink(recipeConfig);
|
||||
} catch(err) {}
|
||||
};
|
||||
|
||||
|
@ -196,12 +196,13 @@ ControlsWaiter.prototype.save_text_change = function() {
|
|||
/**
|
||||
* Handler for the 'Save' command. Pops up the save dialog box.
|
||||
*/
|
||||
ControlsWaiter.prototype.save_click = function() {
|
||||
var recipe_config = this.app.get_recipe_config();
|
||||
var recipe_str = JSON.stringify(recipe_config).replace(/},{/g, "},\n{");
|
||||
document.getElementById("save-text").value = recipe_str;
|
||||
ControlsWaiter.prototype.saveClick = function() {
|
||||
var recipeConfig = this.app.getRecipeConfig(),
|
||||
recipeStr = JSON.stringify(recipeConfig).replace(/},{/g, "},\n{");
|
||||
|
||||
document.getElementById("save-text").value = recipeStr;
|
||||
|
||||
this.initialise_save_link(recipe_config);
|
||||
this.initialiseSaveLink(recipeConfig);
|
||||
$("#save-modal").modal();
|
||||
};
|
||||
|
||||
|
@ -209,24 +210,24 @@ ControlsWaiter.prototype.save_click = function() {
|
|||
/**
|
||||
* Handler for the save link recipe checkbox change event.
|
||||
*/
|
||||
ControlsWaiter.prototype.slr_check_change = function() {
|
||||
this.initialise_save_link();
|
||||
ControlsWaiter.prototype.slrCheckChange = function() {
|
||||
this.initialiseSaveLink();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handler for the save link input checkbox change event.
|
||||
*/
|
||||
ControlsWaiter.prototype.sli_check_change = function() {
|
||||
this.initialise_save_link();
|
||||
ControlsWaiter.prototype.sliCheckChange = function() {
|
||||
this.initialiseSaveLink();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handler for the 'Load' command. Pops up the load dialog box.
|
||||
*/
|
||||
ControlsWaiter.prototype.load_click = function() {
|
||||
this.populate_load_recipes_list();
|
||||
ControlsWaiter.prototype.loadClick = function() {
|
||||
this.populateLoadRecipesList();
|
||||
$("#load-modal").modal();
|
||||
};
|
||||
|
||||
|
@ -234,88 +235,88 @@ ControlsWaiter.prototype.load_click = function() {
|
|||
/**
|
||||
* Saves the recipe specified in the save textarea to local storage.
|
||||
*/
|
||||
ControlsWaiter.prototype.save_button_click = function() {
|
||||
var recipe_name = document.getElementById("save-name").value,
|
||||
recipe_str = document.getElementById("save-text").value;
|
||||
ControlsWaiter.prototype.saveButtonClick = function() {
|
||||
var recipeName = document.getElementById("save-name").value,
|
||||
recipeStr = document.getElementById("save-text").value;
|
||||
|
||||
if (!recipe_name) {
|
||||
if (!recipeName) {
|
||||
this.app.alert("Please enter a recipe name", "danger", 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
var saved_recipes = localStorage.saved_recipes ?
|
||||
JSON.parse(localStorage.saved_recipes) : [],
|
||||
recipe_id = localStorage.recipe_id || 0;
|
||||
var savedRecipes = localStorage.savedRecipes ?
|
||||
JSON.parse(localStorage.savedRecipes) : [],
|
||||
recipeId = localStorage.recipeId || 0;
|
||||
|
||||
saved_recipes.push({
|
||||
id: ++recipe_id,
|
||||
name: recipe_name,
|
||||
recipe: recipe_str
|
||||
savedRecipes.push({
|
||||
id: ++recipeId,
|
||||
name: recipeName,
|
||||
recipe: recipeStr
|
||||
});
|
||||
|
||||
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
||||
localStorage.recipe_id = recipe_id;
|
||||
localStorage.savedRecipes = JSON.stringify(savedRecipes);
|
||||
localStorage.recipeId = recipeId;
|
||||
|
||||
this.app.alert("Recipe saved as \"" + recipe_name + "\".", "success", 2000);
|
||||
this.app.alert("Recipe saved as \"" + recipeName + "\".", "success", 2000);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Populates the list of saved recipes in the load dialog box from local storage.
|
||||
*/
|
||||
ControlsWaiter.prototype.populate_load_recipes_list = function() {
|
||||
var load_name_el = document.getElementById("load-name");
|
||||
ControlsWaiter.prototype.populateLoadRecipesList = function() {
|
||||
var loadNameEl = document.getElementById("load-name");
|
||||
|
||||
// Remove current recipes from select
|
||||
var i = load_name_el.options.length;
|
||||
var i = loadNameEl.options.length;
|
||||
while (i--) {
|
||||
load_name_el.remove(i);
|
||||
loadNameEl.remove(i);
|
||||
}
|
||||
|
||||
// Add recipes to select
|
||||
var saved_recipes = localStorage.saved_recipes ?
|
||||
JSON.parse(localStorage.saved_recipes) : [];
|
||||
var savedRecipes = localStorage.savedRecipes ?
|
||||
JSON.parse(localStorage.savedRecipes) : [];
|
||||
|
||||
for (i = 0; i < saved_recipes.length; i++) {
|
||||
for (i = 0; i < savedRecipes.length; i++) {
|
||||
var opt = document.createElement("option");
|
||||
opt.value = saved_recipes[i].id;
|
||||
opt.innerHTML = saved_recipes[i].name;
|
||||
opt.value = savedRecipes[i].id;
|
||||
opt.innerHTML = savedRecipes[i].name;
|
||||
|
||||
load_name_el.appendChild(opt);
|
||||
loadNameEl.appendChild(opt);
|
||||
}
|
||||
|
||||
// Populate textarea with first recipe
|
||||
document.getElementById("load-text").value = saved_recipes.length ? saved_recipes[0].recipe : "";
|
||||
document.getElementById("load-text").value = savedRecipes.length ? savedRecipes[0].recipe : "";
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes the currently selected recipe from local storage.
|
||||
*/
|
||||
ControlsWaiter.prototype.load_delete_click = function() {
|
||||
ControlsWaiter.prototype.loadDeleteClick = function() {
|
||||
var id = parseInt(document.getElementById("load-name").value, 10),
|
||||
saved_recipes = localStorage.saved_recipes ?
|
||||
JSON.parse(localStorage.saved_recipes) : [];
|
||||
savedRecipes = localStorage.savedRecipes ?
|
||||
JSON.parse(localStorage.savedRecipes) : [];
|
||||
|
||||
saved_recipes = saved_recipes.filter(function(r) {
|
||||
savedRecipes = savedRecipes.filter(function(r) {
|
||||
return r.id !== id;
|
||||
});
|
||||
|
||||
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
||||
this.populate_load_recipes_list();
|
||||
localStorage.savedRecipes = JSON.stringify(savedRecipes);
|
||||
this.populateLoadRecipesList();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Displays the selected recipe in the load text box.
|
||||
*/
|
||||
ControlsWaiter.prototype.load_name_change = function(e) {
|
||||
ControlsWaiter.prototype.loadNameChange = function(e) {
|
||||
var el = e.target,
|
||||
saved_recipes = localStorage.saved_recipes ?
|
||||
JSON.parse(localStorage.saved_recipes) : [],
|
||||
savedRecipes = localStorage.savedRecipes ?
|
||||
JSON.parse(localStorage.savedRecipes) : [],
|
||||
id = parseInt(el.value, 10);
|
||||
|
||||
var recipe = saved_recipes.filter(function(r) {
|
||||
var recipe = savedRecipes.filter(function(r) {
|
||||
return r.id === id;
|
||||
})[0];
|
||||
|
||||
|
@ -326,12 +327,12 @@ ControlsWaiter.prototype.load_name_change = function(e) {
|
|||
/**
|
||||
* Loads the selected recipe and populates the Recipe with its operations.
|
||||
*/
|
||||
ControlsWaiter.prototype.load_button_click = function() {
|
||||
ControlsWaiter.prototype.loadButtonClick = function() {
|
||||
try {
|
||||
var recipe_config = JSON.parse(document.getElementById("load-text").value);
|
||||
this.app.set_recipe_config(recipe_config);
|
||||
var recipeConfig = JSON.parse(document.getElementById("load-text").value);
|
||||
this.app.setRecipeConfig(recipeConfig);
|
||||
|
||||
$("#rec_list [data-toggle=popover]").popover();
|
||||
$("#rec-list [data-toggle=popover]").popover();
|
||||
} catch(e) {
|
||||
this.app.alert("Invalid recipe", "danger", 2000);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue