Skip to content

Commit 557fa69

Browse files
committed
♻️ Refactored background
1 parent 6dac094 commit 557fa69

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

extension/js/background.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const contextMenus = {}
32

43
function findMenuRefItem(theMenuArray, theMenuRef) {
@@ -9,17 +8,6 @@ function findMenuRefItem(theMenuArray, theMenuRef) {
98
}
109
}
1110

12-
for (let actionindex = 0; actionindex < menuActions.length; actionindex++) {
13-
if (menuActions[actionindex].menu === "") {
14-
menuActions[actionindex].id = chrome.contextMenus.create({ "title": menuActions[actionindex].title, "type": "normal", contexts: ["all"] })
15-
} else {
16-
const parentId = findMenuRefItem(menuActions, menuActions[actionindex].menu)
17-
menuActions[actionindex].id = chrome.contextMenus.create({ "title": menuActions[actionindex].title, "type": "normal", contexts: ["all"], "parentId": parentId })
18-
}
19-
}
20-
21-
chrome.contextMenus.onClicked.addListener(contextMenuClickHandler)
22-
2311
function contextMenuClickHandler(info, tab) {
2412

2513
let actionToDo
@@ -39,7 +27,7 @@ function contextMenuClickHandler(info, tab) {
3927
return
4028
}
4129

42-
const errorHandler = function () {
30+
function errorHandler () {
4331
if (chrome.runtime.lastError) {
4432
console.error(chrome.runtime.lastError.message)
4533
}
@@ -81,3 +69,14 @@ function contextMenuClickHandler(info, tab) {
8169
})
8270
}
8371
}
72+
73+
chrome.contextMenus.onClicked.addListener(contextMenuClickHandler)
74+
75+
for (let actionindex = 0; actionindex < menuActions.length; actionindex++) {
76+
if (menuActions[actionindex].menu === "") {
77+
menuActions[actionindex].id = chrome.contextMenus.create({ "title": menuActions[actionindex].title, "type": "normal", contexts: ["all"] })
78+
} else {
79+
const parentId = findMenuRefItem(menuActions, menuActions[actionindex].menu)
80+
menuActions[actionindex].id = chrome.contextMenus.create({ "title": menuActions[actionindex].title, "type": "normal", contexts: ["all"], "parentId": parentId })
81+
}
82+
}

0 commit comments

Comments
 (0)