Skip to content

Commit

Permalink
Add keyboard shortcut
Browse files Browse the repository at this point in the history
Added Ctrl+T to open DeepL.
  • Loading branch information
itagagaki committed Dec 20, 2020
1 parent c270b06 commit 41a0eba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Thunderbird/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ messenger.menus.onClicked.addListener((info, tab) => {
break;
}
});

messenger.commands.onCommand.addListener((command) => {
switch (command) {
case "deepl":
messenger.Helper.getSelectedText().then(text => {
if (text && text.match(/\S/g)) {
goDeepL(text);
}
});
break;
}
});
13 changes: 13 additions & 0 deletions Thunderbird/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

var Helper = class extends ExtensionCommon.ExtensionAPI {
getAPI(context) {
return {
Helper: {
async getSelectedText() {
return Services.wm.getMostRecentWindow("mail:3pane").document.commandDispatcher.focusedWindow.getSelection().toString();
}
}
};
}
};
14 changes: 14 additions & 0 deletions Thunderbird/helper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"namespace": "Helper",
"functions": [
{
"name": "getSelectedText",
"type": "function",
"description": "Get selected text.",
"async": true,
"parameters": []
}
]
}
]
16 changes: 16 additions & 0 deletions Thunderbird/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@
"menus",
"storage"
],
"commands": {
"deepl": {
"suggested_key": { "default": "Ctrl+T" },
"description": "Translate selected text with DeepL"
}
},
"background": {
"scripts": [
"background.js"
]
},
"experiment_apis": {
"Helper": {
"schema": "helper.json",
"parent": {
"scopes": ["addon_parent"],
"paths": [["Helper"]],
"script": "helper.js"
}
}
},
"options_ui": {
"page": "options.html",
"browser_style": true,
Expand Down

0 comments on commit 41a0eba

Please sign in to comment.