Skip to content

Commit ee84477

Browse files
Modernize code patterns: use forEach and optional chaining
Co-authored-by: PeterDaveHello <[email protected]>
1 parent 0ea8bef commit ee84477

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/background/menus.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ export function refreshMenu() {
8585
}
8686

8787
// Add custom selection tools that are active
88-
for (let i = 0; i < userConfig.customSelectionTools.length; i++) {
89-
const tool = userConfig.customSelectionTools[i]
88+
userConfig.customSelectionTools.forEach((tool, i) => {
9089
if (tool.active && tool.name) {
9190
Browser.contextMenus.create({
9291
id: menuId + 'custom_' + i,
@@ -95,7 +94,7 @@ export function refreshMenu() {
9594
contexts: ['selection'],
9695
})
9796
}
98-
}
97+
})
9998

10099
Browser.contextMenus.onClicked.addListener(onClickMenu)
101100
})

src/content-script/index.jsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,9 @@ async function prepareForRightClickMenu() {
291291
} else if (data.itemId.startsWith('custom_')) {
292292
// Handle custom selection tools from context menu
293293
const customIndex = parseInt(data.itemId.replace('custom_', ''), 10)
294-
if (
295-
!isNaN(customIndex) &&
296-
customIndex >= 0 &&
297-
userConfig.customSelectionTools &&
298-
customIndex < userConfig.customSelectionTools.length
299-
) {
300-
const customTool = userConfig.customSelectionTools[customIndex]
301-
if (customTool.active && customTool.name) {
302-
prompt = customTool.prompt.replace('{{selection}}', data.selectionText)
303-
}
294+
const customTool = userConfig.customSelectionTools?.[customIndex]
295+
if (customTool?.active && customTool?.name) {
296+
prompt = customTool.prompt.replace('{{selection}}', data.selectionText)
304297
}
305298
} else if (data.itemId in menuConfig) {
306299
const menuItem = menuConfig[data.itemId]

0 commit comments

Comments
 (0)