|
|
@ -5,52 +5,46 @@ import KeyQueue from './key-queue'; |
|
|
|
|
|
|
|
|
|
|
|
const queue = new KeyQueue(); |
|
|
|
const queue = new KeyQueue(); |
|
|
|
|
|
|
|
|
|
|
|
const keyPressHandle = (request, sender, sendResponse) => { |
|
|
|
const keyPressHandle = (request, sender) => { |
|
|
|
let action = queue.push({ |
|
|
|
let action = queue.push({ |
|
|
|
code: request.code, |
|
|
|
code: request.code, |
|
|
|
ctrl: request.ctrl |
|
|
|
ctrl: request.ctrl |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (!action) { |
|
|
|
if (!action) { |
|
|
|
return; |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (actions.isBackgroundAction(action[0])) { |
|
|
|
if (actions.isBackgroundAction(action[0])) { |
|
|
|
doBackgroundAction(sender, action); |
|
|
|
return doBackgroundAction(sender, action); |
|
|
|
} else if (actions.isContentAction(action[0])) { |
|
|
|
} else if (actions.isContentAction(action[0])) { |
|
|
|
sendResponse({ |
|
|
|
return Promise.resolve({ |
|
|
|
type: 'response.action', |
|
|
|
type: 'response.action', |
|
|
|
action: action |
|
|
|
action: action |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Promise.resolve(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const doBackgroundAction = (sender, action) => { |
|
|
|
const doBackgroundAction = (sender, action) => { |
|
|
|
switch(action[0]) { |
|
|
|
switch(action[0]) { |
|
|
|
case actions.TABS_CLOSE: |
|
|
|
case actions.TABS_CLOSE: |
|
|
|
tabs.closeTab(sender.tab.id); |
|
|
|
return tabs.closeTab(sender.tab.id); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.TABS_REOPEN: |
|
|
|
case actions.TABS_REOPEN: |
|
|
|
tabs.reopenTab(); |
|
|
|
return tabs.reopenTab(); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.TABS_PREV: |
|
|
|
case actions.TABS_PREV: |
|
|
|
tabs.selectPrevTab(sender.tab.index, actions[1] || 1); |
|
|
|
return tabs.selectPrevTab(sender.tab.index, actions[1] || 1); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.TABS_NEXT: |
|
|
|
case actions.TABS_NEXT: |
|
|
|
tabs.selectNextTab(sender.tab.index, actions[1] || 1); |
|
|
|
return tabs.selectNextTab(sender.tab.index, actions[1] || 1); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.TABS_RELOAD: |
|
|
|
case actions.TABS_RELOAD: |
|
|
|
tabs.reload(sender.tab, actions[1] || false); |
|
|
|
return tabs.reload(sender.tab, actions[1] || false); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.ZOOM_IN: |
|
|
|
case actions.ZOOM_IN: |
|
|
|
zooms.zoomIn(); |
|
|
|
return zooms.zoomIn(); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.ZOOM_OUT: |
|
|
|
case actions.ZOOM_OUT: |
|
|
|
zooms.zoomOut(); |
|
|
|
return zooms.zoomOut(); |
|
|
|
break; |
|
|
|
|
|
|
|
case actions.ZOOM_NEUTRAL: |
|
|
|
case actions.ZOOM_NEUTRAL: |
|
|
|
zooms.neutral(); |
|
|
|
return zooms.neutral(); |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const normalizeUrl = (string) => { |
|
|
|
const normalizeUrl = (string) => { |
|
|
@ -63,10 +57,10 @@ const normalizeUrl = (string) => { |
|
|
|
|
|
|
|
|
|
|
|
const cmdBuffer = (arg) => { |
|
|
|
const cmdBuffer = (arg) => { |
|
|
|
if (isNaN(arg)) { |
|
|
|
if (isNaN(arg)) { |
|
|
|
tabs.selectByKeyword(arg); |
|
|
|
return tabs.selectByKeyword(arg); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let index = parseInt(arg, 10) - 1; |
|
|
|
let index = parseInt(arg, 10) - 1; |
|
|
|
tabs.selectAt(index); |
|
|
|
return tabs.selectAt(index); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -74,28 +68,25 @@ const cmdEnterHandle = (request, sender) => { |
|
|
|
let words = request.text.split(' ').filter((s) => s.length > 0); |
|
|
|
let words = request.text.split(' ').filter((s) => s.length > 0); |
|
|
|
switch (words[0]) { |
|
|
|
switch (words[0]) { |
|
|
|
case 'open': |
|
|
|
case 'open': |
|
|
|
browser.tabs.update(sender.tab.id, { url: normalizeUrl(words[1]) }); |
|
|
|
return browser.tabs.update(sender.tab.id, { url: normalizeUrl(words[1]) }); |
|
|
|
return; |
|
|
|
|
|
|
|
case 'tabopen': |
|
|
|
case 'tabopen': |
|
|
|
browser.tabs.create({ url: normalizeUrl(words[1]) }); |
|
|
|
return browser.tabs.create({ url: normalizeUrl(words[1]) }); |
|
|
|
return; |
|
|
|
|
|
|
|
case 'b': |
|
|
|
case 'b': |
|
|
|
case 'buffer': |
|
|
|
case 'buffer': |
|
|
|
cmdBuffer(words[1]); |
|
|
|
return cmdBuffer(words[1]); |
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
throw new Error(words[0] + ' command is not defined'); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
browser.runtime.onMessage.addListener((request, sender, sendResponse) => { |
|
|
|
browser.runtime.onMessage.addListener((request, sender) => { |
|
|
|
switch (request.type) { |
|
|
|
switch (request.type) { |
|
|
|
case 'event.keypress': |
|
|
|
case 'event.keypress': |
|
|
|
keyPressHandle(request, sender, sendResponse); |
|
|
|
return keyPressHandle(request, sender); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'event.cmd.enter': |
|
|
|
case 'event.cmd.enter': |
|
|
|
cmdEnterHandle(request, sender, sendResponse); |
|
|
|
return cmdEnterHandle(request, sender); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'event.cmd.suggest': |
|
|
|
case 'event.cmd.suggest': |
|
|
|
// TODO make suggestion and return via sendResponse
|
|
|
|
// TODO make suggestion and return
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return Promise.resolve(); |
|
|
|
}); |
|
|
|
}); |
|
|
|