Add shortcut to disconnect fields (#269)

This commit is contained in:
Federico Brigante 2023-03-16 16:28:04 +08:00 committed by GitHub
parent 034bc379f0
commit a44a1c8edc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -2,13 +2,6 @@ import browser from 'webextension-polyfill';
import oneEvent from 'one-event';
import optionsStorage from './options-storage.js';
function inCurrentTab(callback) {
chrome.tabs.query({
active: true,
currentWindow: true,
}, tabs => callback(tabs[0]));
}
function handleClose(info, tab) {
chrome.tabs.executeScript(tab.id, {
code: 'stopGT()',
@ -140,9 +133,16 @@ function init() {
contexts: ['browser_action'],
onclick: handleClose,
});
chrome.commands.onCommand.addListener(command => {
chrome.commands.onCommand.addListener((command, tab) => {
if (!tab?.id) {
console.warn('No tab information was received for command', {command, tab});
return;
}
if (command === 'open') {
inCurrentTab(handleAction);
handleAction(tab);
} else if (command === 'close') {
handleClose({}, tab);
}
});

View File

@ -47,6 +47,9 @@
"default": "Ctrl+Shift+K",
"linux": "Ctrl+Shift+H"
}
},
"close": {
"description": "Disconnect from GhostText"
}
},
"content_scripts": [