diff options
Diffstat (limited to 'ext/bg/js/anki-note-builder.js')
-rw-r--r-- | ext/bg/js/anki-note-builder.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/ext/bg/js/anki-note-builder.js b/ext/bg/js/anki-note-builder.js index 4afb2d40..19e352f1 100644 --- a/ext/bg/js/anki-note-builder.js +++ b/ext/bg/js/anki-note-builder.js @@ -20,11 +20,12 @@ */ class AnkiNoteBuilder { - constructor({anki, audioSystem, renderTemplate, getClipboardImage=null}) { + constructor({anki, audioSystem, renderTemplate, getClipboardImage=null, getScreenshot=null}) { this._anki = anki; this._audioSystem = audioSystem; this._renderTemplate = renderTemplate; this._getClipboardImage = getClipboardImage; + this._getScreenshot = getScreenshot; } async createNote({ @@ -130,18 +131,23 @@ class AnkiNoteBuilder { async injectScreenshot(definition, fields, screenshot) { if (!this._containsMarker(fields, 'screenshot')) { return; } + const reading = definition.reading; const now = new Date(Date.now()); - let fileName = `yomichan_browser_screenshot_${definition.reading}_${this._dateToString(now)}.${screenshot.format}`; - fileName = AnkiNoteBuilder.replaceInvalidFileNameCharacters(fileName); - const data = screenshot.dataUrl.replace(/^data:[\w\W]*?,/, ''); try { + const {windowId, tabId, ownerFrameId, format, quality} = screenshot; + const dataUrl = await this._getScreenshot(windowId, tabId, ownerFrameId, format, quality); + + let fileName = `yomichan_browser_screenshot_${reading}_${this._dateToString(now)}.${format}`; + fileName = AnkiNoteBuilder.replaceInvalidFileNameCharacters(fileName); + const data = dataUrl.replace(/^data:[\w\W]*?,/, ''); + await this._anki.storeMediaFile(fileName, data); + + definition.screenshotFileName = fileName; } catch (e) { - return; + // NOP } - - definition.screenshotFileName = fileName; } async injectClipboardImage(definition, fields) { |