From ae92e0b3781e27d54cbac2570ba2a1b8a6b11999 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 24 Feb 2021 21:54:58 -0500 Subject: AnkiUtil (#1439) * Add AnkiUtil * Update AnkiConnect to use AnkiUtil * Use AnkiUtil in AnkiNoteBuilder * Replace containsAnyMarker with AnkiUtil.stringContainsAnyFieldMarker * Add AnkiUtil.getFieldMarkers * Add fieldsObjectContainsMarker to AnkiUtil * Remove unused global * Remove unused parameter: enabled * Add cloneFieldMarkerPattern --- ext/js/display/display.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'ext/js/display') diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 517b391d..0e029748 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -17,6 +17,7 @@ /* global * AnkiNoteBuilder + * AnkiUtil * DisplayAudio * DisplayGenerator * DisplayHistory @@ -85,7 +86,7 @@ class Display extends EventDispatcher { }); this._ankiFieldTemplates = null; this._ankiFieldTemplatesDefault = null; - this._ankiNoteBuilder = new AnkiNoteBuilder(true); + this._ankiNoteBuilder = new AnkiNoteBuilder(); this._updateAdderButtonsPromise = Promise.resolve(); this._contentScrollElement = document.querySelector('#content-scroll'); this._contentScrollBodyElement = document.querySelector('#content-body'); @@ -1493,7 +1494,7 @@ class Display extends EventDispatcher { const definitionDetails = this._getDefinitionDetailsForNote(definition); let audioDetails = null; - if (definitionDetails.type !== 'kanji' && this._ankiNoteBuilder.containsMarker(fields, 'audio')) { + if (definitionDetails.type !== 'kanji' && AnkiUtil.fieldsObjectContainsMarker(fields, 'audio')) { const primaryCardAudio = this._displayAudio.getPrimaryCardAudio(definitionDetails.expression, definitionDetails.reading); let preferredAudioIndex = null; let sources2 = sources; @@ -1504,11 +1505,11 @@ class Display extends EventDispatcher { audioDetails = {sources: sources2, preferredAudioIndex, customSourceUrl, customSourceType}; } - const screenshotDetails = (this._ankiNoteBuilder.containsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null); + const screenshotDetails = (AnkiUtil.fieldsObjectContainsMarker(fields, 'screenshot') ? {tabId: this._contentOriginTabId, frameId: this._contentOriginFrameId, format, quality} : null); const clipboardDetails = { - image: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-image'), - text: this._ankiNoteBuilder.containsMarker(fields, 'clipboard-text') + image: AnkiUtil.fieldsObjectContainsMarker(fields, 'clipboard-image'), + text: AnkiUtil.fieldsObjectContainsMarker(fields, 'clipboard-text') }; return await yomichan.api.injectAnkiNoteMedia( -- cgit v1.2.3