From 94ece4bfd1787707229e7d3eef2e42f12ef5bd70 Mon Sep 17 00:00:00 2001 From: richrobber2 Date: Wed, 12 Jun 2024 03:18:51 -0700 Subject: [PATCH] Converted the createTooltip function to an arrow function. Used destructuring in the map and filter callbacks to simplify the access to properties. Removed the redundant return keyword in the map callback by using implicit return. --- javascript/canvas-zoom.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/javascript/canvas-zoom.js b/javascript/canvas-zoom.js index 4ac2233..7c97ad8 100644 --- a/javascript/canvas-zoom.js +++ b/javascript/canvas-zoom.js @@ -483,7 +483,7 @@ onUiLoaded(async () => { }); } - function createTooltip() { + const createTooltip = () => { const toolTipElemnt = targetElement.querySelector(".image-container") || targetElement.querySelector("div[data-testid='image']"); const tooltip = document.createElement("div"); @@ -510,37 +510,36 @@ onUiLoaded(async () => { { configKey: "canvas_zoom_hotkey_transparency", action: "Transparency mode" }, ]; - const hotkeys = hotkeysInfo.map((info) => { - const configValue = hotkeysConfig[info.configKey]; - + const hotkeys = hotkeysInfo.map(({ configKey, action, keySuffix, keyPrefix }) => { + const configValue = hotkeysConfig[configKey]; let key = configValue.slice(-1); - if (info.keySuffix) { - key = `${configValue}${info.keySuffix}`; + if (keySuffix) { + key = `${configValue}${keySuffix}`; } - if (info.keyPrefix && info.keyPrefix !== "None + ") { - key = `${info.keyPrefix}${configValue[3]}`; + if (keyPrefix && keyPrefix !== "None + ") { + key = `${keyPrefix}${configValue[3]}`; } return { key, - action: info.action, + action, disabled: configValue === "disable", }; }); hotkeys - .filter(hotkey => !hotkey.disabled) - .forEach(hotkey => { + .filter(({ disabled }) => !disabled) + .forEach(({ key, action }) => { const p = document.createElement("p"); - p.innerHTML = `${hotkey.key} - ${hotkey.action}`; + p.innerHTML = `${key} - ${action}`; tooltipContent.appendChild(p); }); tooltip.append(info, tooltipContent); toolTipElemnt.appendChild(tooltip); - } + }; /** * Function to create fullscreen and dropper buttons and attach them to the target element