diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-19 22:30:16 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-10-19 22:30:16 -0400 |
commit | d9ae34821ca5e0189248c015c2f30b88a8a6a7b2 (patch) | |
tree | 0e670d53f4364830468ebfa71a0d2cc6a9805cf1 /ext/bg/js/api.js | |
parent | dbec4bffda00615fe768f66c1eb5d895aea05585 (diff) |
Add support for middle clicks opening new tabs on the context buttons
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r-- | ext/bg/js/api.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index a33ff94f..7b806e27 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -144,28 +144,30 @@ async function apiTemplateRender(template, data, dynamic) { } } -async function apiCommandExec(command) { +async function apiCommandExec(command, params) { const handlers = apiCommandExec.handlers; if (handlers.hasOwnProperty(command)) { const handler = handlers[command]; - handler(); + handler(params); } } apiCommandExec.handlers = { - search: async () => { + search: async (params) => { const url = chrome.extension.getURL('/bg/search.html'); - try { - const tab = await apiFindTab(1000, (url2) => ( - url2 !== null && - url2.startsWith(url) && - (url2.length === url.length || url2[url.length] === '?' || url2[url.length] === '#') - )); - if (tab !== null) { - await apiFocusTab(tab); - return; + if (!(params && params.newTab)) { + try { + const tab = await apiFindTab(1000, (url2) => ( + url2 !== null && + url2.startsWith(url) && + (url2.length === url.length || url2[url.length] === '?' || url2[url.length] === '#') + )); + if (tab !== null) { + await apiFocusTab(tab); + return; + } + } catch (e) { + // NOP } - } catch (e) { - // NOP } chrome.tabs.create({url}); }, |