mirror of
https://github.com/He4eT/tabswitcher.git
synced 2026-05-05 01:17:23 +00:00
pages/search: add actionbox handlers
This commit is contained in:
parent
3e770a0d65
commit
45cf56e255
3 changed files with 83 additions and 2 deletions
69
pages/search/modules/actionboxHandlers.js
Normal file
69
pages/search/modules/actionboxHandlers.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
export const actionboxHandlers = (commandQuery, store, flush) => {
|
||||
const command = commandQuery.slice(0, 1)
|
||||
const label = commandQuery.slice(1)
|
||||
|
||||
const noop = (command) => () => {
|
||||
if (command) {
|
||||
console.log('Unsupported command:', command)
|
||||
}
|
||||
}
|
||||
|
||||
({
|
||||
'?': openHelp,
|
||||
'x': closeCurrentTab,
|
||||
'r': reloadCurrentTab,
|
||||
/* */
|
||||
'f': switchToTab,
|
||||
'd': closeTab,
|
||||
'c': duplicateTab,
|
||||
}[command] ?? noop(command))(store, label, flush)
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
function openHelp () {
|
||||
|
||||
}
|
||||
|
||||
function closeCurrentTab () {
|
||||
window.close()
|
||||
}
|
||||
|
||||
function reloadCurrentTab () {
|
||||
location.reload()
|
||||
}
|
||||
|
||||
/* */
|
||||
|
||||
const getTabByLabel = (store, label) => {
|
||||
const tabs = store.getCurrentState().tabs
|
||||
return tabs.find(tab => tab.label === label)
|
||||
}
|
||||
|
||||
function switchToTab (store, label) {
|
||||
const tab = getTabByLabel(store, label)
|
||||
if (tab) {
|
||||
store.actions.goToTab(tab.id)
|
||||
flush()
|
||||
closeCurrentTab()
|
||||
}
|
||||
}
|
||||
|
||||
function closeTab (store, label, flush) {
|
||||
const tab = getTabByLabel(store, label)
|
||||
if (tab) {
|
||||
store.actions.closeTab(tab.id)
|
||||
flush()
|
||||
}
|
||||
}
|
||||
|
||||
function duplicateTab (store, label, flush) {
|
||||
const tab = getTabByLabel(store, label)
|
||||
if (tab) {
|
||||
browser.tabs.create({
|
||||
active: false,
|
||||
url: tab.url,
|
||||
}).then(store.actions.updateState)
|
||||
flush()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue