-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
43 lines (38 loc) · 955 Bytes
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
console.log('popup.js loaded')
/**
* Load constants than run listener script
* @param {string} script
* @returns
*/
const loadAndRunScript = (script) => {
return (tabId) => {
console.log('loadAndRunScript.callback', { script, tabId })
chrome.scripting.executeScript({
target: { tabId },
files: ['/scripts', script].join('/').split(),
})
}
}
/**
*
* @param {string} id
* @param {string} script
*/
const addBtnListener = (id, script) => {
document.getElementById(id).addEventListener('click', () => {
chrome.tabs.query(
{
active: true,
lastFocusedWindow: true,
},
([tab]) => loadAndRunScript(script)(tab.id)
)
})
}
const run = () => {
addBtnListener('add-checkbox', 'add-checkbox.js')
addBtnListener('remove-checkbox', 'remove-checkbox.js')
addBtnListener('toggle-checkbox', 'toggle-checkbox.js')
addBtnListener('bulk-delete', 'delete-conversations.js')
}
run()