Add support for middle clicks opening new tabs on the context buttons

This commit is contained in:
toasted-nutbread 2019-10-19 22:30:16 -04:00
parent dbec4bffda
commit d9ae34821c
4 changed files with 36 additions and 20 deletions

View File

@ -144,16 +144,17 @@ async function apiTemplateRender(template, data, dynamic) {
} }
} }
async function apiCommandExec(command) { async function apiCommandExec(command, params) {
const handlers = apiCommandExec.handlers; const handlers = apiCommandExec.handlers;
if (handlers.hasOwnProperty(command)) { if (handlers.hasOwnProperty(command)) {
const handler = handlers[command]; const handler = handlers[command];
handler(); handler(params);
} }
} }
apiCommandExec.handlers = { apiCommandExec.handlers = {
search: async () => { search: async (params) => {
const url = chrome.extension.getURL('/bg/search.html'); const url = chrome.extension.getURL('/bg/search.html');
if (!(params && params.newTab)) {
try { try {
const tab = await apiFindTab(1000, (url2) => ( const tab = await apiFindTab(1000, (url2) => (
url2 !== null && url2 !== null &&
@ -167,6 +168,7 @@ apiCommandExec.handlers = {
} catch (e) { } catch (e) {
// NOP // NOP
} }
}
chrome.tabs.create({url}); chrome.tabs.create({url});
}, },

View File

@ -181,7 +181,7 @@ Backend.messageHandlers = {
definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext), definitionsAddable: ({definitions, modes, optionsContext}) => apiDefinitionsAddable(definitions, modes, optionsContext),
noteView: ({noteId}) => apiNoteView(noteId), noteView: ({noteId}) => apiNoteView(noteId),
templateRender: ({template, data, dynamic}) => apiTemplateRender(template, data, dynamic), templateRender: ({template, data, dynamic}) => apiTemplateRender(template, data, dynamic),
commandExec: ({command}) => apiCommandExec(command), commandExec: ({command, params}) => apiCommandExec(command, params),
audioGetUrl: ({definition, source, optionsContext}) => apiAudioGetUrl(definition, source, optionsContext), audioGetUrl: ({definition, source, optionsContext}) => apiAudioGetUrl(definition, source, optionsContext),
screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender), screenshotGet: ({options}, sender) => apiScreenshotGet(options, sender),
forward: ({action, params}, sender) => apiForward(action, params, sender), forward: ({action, params}, sender) => apiForward(action, params, sender),

View File

@ -25,6 +25,20 @@ function showExtensionInfo() {
node.textContent = `${manifest.name} v${manifest.version}`; node.textContent = `${manifest.name} v${manifest.version}`;
} }
function setupButtonEvents(selector, command) {
$(selector)
.on('click', (e) => {
if (e.button !== 0) { return; }
apiCommandExec(command, {newTab: e.ctrlKey});
e.preventDefault();
})
.on('auxclick', (e) => {
if (e.button !== 1) { return; }
apiCommandExec(command, {newTab: true});
e.preventDefault();
});
}
$(document).ready(utilAsync(() => { $(document).ready(utilAsync(() => {
showExtensionInfo(); showExtensionInfo();
@ -33,9 +47,9 @@ $(document).ready(utilAsync(() => {
document.documentElement.dataset.mode = (browser === 'firefox-mobile' ? 'full' : 'mini'); document.documentElement.dataset.mode = (browser === 'firefox-mobile' ? 'full' : 'mini');
}); });
$('.action-open-search').click(() => apiCommandExec('search')); setupButtonEvents('.action-open-search', 'search');
$('.action-open-options').click(() => apiCommandExec('options')); setupButtonEvents('.action-open-options', 'options');
$('.action-open-help').click(() => apiCommandExec('help')); setupButtonEvents('.action-open-help', 'help');
const optionsContext = { const optionsContext = {
depth: 0, depth: 0,

View File

@ -49,8 +49,8 @@ function apiAudioGetUrl(definition, source, optionsContext) {
return utilInvoke('audioGetUrl', {definition, source, optionsContext}); return utilInvoke('audioGetUrl', {definition, source, optionsContext});
} }
function apiCommandExec(command) { function apiCommandExec(command, params) {
return utilInvoke('commandExec', {command}); return utilInvoke('commandExec', {command, params});
} }
function apiScreenshotGet(options) { function apiScreenshotGet(options) {