aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/data/anki-field-templates-upgrade-v4.handlebars4
-rw-r--r--ext/bg/data/default-anki-field-templates.handlebars4
-rw-r--r--ext/bg/js/anki-note-builder.js4
-rw-r--r--ext/bg/js/backend.js18
-rw-r--r--ext/bg/js/options.js1
-rw-r--r--ext/bg/js/settings/anki-controller.js2
6 files changed, 26 insertions, 7 deletions
diff --git a/ext/bg/data/anki-field-templates-upgrade-v4.handlebars b/ext/bg/data/anki-field-templates-upgrade-v4.handlebars
index a16b5b68..dc88395a 100644
--- a/ext/bg/data/anki-field-templates-upgrade-v4.handlebars
+++ b/ext/bg/data/anki-field-templates-upgrade-v4.handlebars
@@ -3,3 +3,7 @@
<img src="{{definition.clipboardImageFileName}}" />
{{~/if~}}
{{/inline}}
+
+{{#*inline "clipboard-text"}}
+ {{~#if definition.clipboardText~}}{{definition.clipboardText}}{{~/if~}}
+{{/inline}}
diff --git a/ext/bg/data/default-anki-field-templates.handlebars b/ext/bg/data/default-anki-field-templates.handlebars
index 98f6897b..2849ade9 100644
--- a/ext/bg/data/default-anki-field-templates.handlebars
+++ b/ext/bg/data/default-anki-field-templates.handlebars
@@ -282,4 +282,8 @@
{{~/if~}}
{{/inline}}
+{{#*inline "clipboard-text"}}
+ {{~#if definition.clipboardText~}}{{definition.clipboardText}}{{~/if~}}
+{{/inline}}
+
{{~> (lookup . "marker") ~}}
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js
index 141259ce..f04a6bf7 100644
--- a/ext/bg/js/anki-note-builder.js
+++ b/ext/bg/js/anki-note-builder.js
@@ -37,11 +37,11 @@ class AnkiNoteBuilder {
modeOptions: {fields, deck, model},
audioDetails=null,
screenshotDetails=null,
- clipboardImage=false,
+ clipboardDetails=null,
errors=null
}) {
if (anki !== null) {
- await this._injectMedia(anki, definition, fields, mode, audioDetails, screenshotDetails, clipboardImage);
+ await this._injectMedia(anki, definition, fields, mode, audioDetails, screenshotDetails, clipboardDetails);
}
const fieldEntries = Object.entries(fields);
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 2a90e8e1..d071a857 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -452,7 +452,7 @@ class Backend {
return results;
}
- async _onApiInjectAnkiNoteMedia({expression, reading, timestamp, audioDetails, screenshotDetails, clipboardImage}, sender) {
+ async _onApiInjectAnkiNoteMedia({expression, reading, timestamp, audioDetails, screenshotDetails, clipboardDetails}, sender) {
if (isObject(screenshotDetails)) {
const {id: tabId, windowId} = (sender && sender.tab ? sender.tab : {});
screenshotDetails = Object.assign({}, screenshotDetails, {tabId, windowId});
@@ -464,7 +464,7 @@ class Backend {
timestamp,
audioDetails,
screenshotDetails,
- clipboardImage
+ clipboardDetails
);
}
@@ -1512,23 +1512,31 @@ class Backend {
return await this._audioDownloader.downloadAudio(sources, expression, reading, details);
}
- async _injectAnkNoteMedia(ankiConnect, expression, reading, timestamp, audioDetails, screenshotDetails, clipboardImage) {
+ async _injectAnkNoteMedia(ankiConnect, expression, reading, timestamp, audioDetails, screenshotDetails, clipboardDetails) {
const screenshotFileName = (
screenshotDetails !== null ?
await this._injectAnkNoteScreenshot(ankiConnect, expression, reading, timestamp, screenshotDetails) :
null
);
const clipboardImageFileName = (
- clipboardImage ?
+ clipboardDetails !== null && clipboardDetails.image ?
await this._injectAnkNoteClipboardImage(ankiConnect, expression, reading, timestamp) :
null
);
+ let clipboardText = null;
+ try {
+ if (clipboardDetails !== null && clipboardDetails.text) {
+ clipboardText = await this._clipboardReader.getText();
+ }
+ } catch (e) {
+ // NOP
+ }
const audioFileName = (
audioDetails !== null ?
await this._injectAnkNoteAudio(ankiConnect, expression, reading, timestamp, audioDetails) :
null
);
- return {screenshotFileName, clipboardImageFileName, audioFileName};
+ return {screenshotFileName, clipboardImageFileName, clipboardText, audioFileName};
}
async _injectAnkNoteAudio(ankiConnect, expression, reading, timestamp, details) {
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 6026fa07..5b61b870 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -503,6 +503,7 @@ class OptionsUtil {
// Options conditions converted to string representations.
// Added usePopupWindow.
// Updated handlebars templates to include "clipboard-image" definition.
+ // Updated handlebars templates to include "clipboard-text" definition.
// Added hideDelay.
// Added inputs to profileOptions.scanning.
// Added pointerEventsEnabled to profileOptions.scanning.
diff --git a/ext/bg/js/settings/anki-controller.js b/ext/bg/js/settings/anki-controller.js
index c1ba843e..526ddfb2 100644
--- a/ext/bg/js/settings/anki-controller.js
+++ b/ext/bg/js/settings/anki-controller.js
@@ -46,6 +46,7 @@ class AnkiController {
return [
'audio',
'clipboard-image',
+ 'clipboard-text',
'cloze-body',
'cloze-prefix',
'cloze-suffix',
@@ -69,6 +70,7 @@ class AnkiController {
return [
'character',
'clipboard-image',
+ 'clipboard-text',
'cloze-body',
'cloze-prefix',
'cloze-suffix',