From 5d7309ed5474a9fb67b9cae1b1176bc10bde6115 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 31 Mar 2021 20:07:11 -0400 Subject: Log Anki data (#1579) * Remove unused modifierPost * Add _getModifier * Add _getModifiedData * Add getModifiedData * Add getRenderingData * Update logging to also log anki note data * Fix dangling comma --- ext/js/display/display.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'ext/js/display') diff --git a/ext/js/display/display.js b/ext/js/display/display.js index 7ded1e09..3f56e081 100644 --- a/ext/js/display/display.js +++ b/ext/js/display/display.js @@ -757,9 +757,7 @@ class Display extends EventDispatcher { _onDebugLogClick(e) { const link = e.currentTarget; const index = this._getClosestDefinitionIndex(link); - if (index < 0 || index >= this._definitions.length) { return; } - const definition = this._definitions[index]; - console.log(definition); + this._logDefinitionData(index); } _onDocumentElementMouseUp(e) { @@ -1375,6 +1373,7 @@ class Display extends EventDispatcher { } _replaceHistoryStateNoNavigate(state, content) { + console.trace('_replaceHistoryStateNoNavigate', state); const historyChangeIgnorePre = this._historyChangeIgnore; try { this._historyChangeIgnore = true; @@ -1866,4 +1865,32 @@ class Display extends EventDispatcher { const queryPostProcessor = this._queryPostProcessor; return typeof queryPostProcessor === 'function' ? queryPostProcessor(query) : query; } + + async _logDefinitionData(index) { + if (index < 0 || index >= this._definitions.length) { return; } + const definition = this._definitions[index]; + let ankiNoteData; + let ankiNoteDataException; + try { + const context = this._getNoteContext(); + const {general: {resultOutputMode, glossaryLayoutMode, compactTags}} = this._options; + ankiNoteData = await this._ankiNoteBuilder.getRenderingData({ + definition, + mode: 'test', + context, + resultOutputMode, + glossaryLayoutMode, + compactTags, + injectedMedia: null, + marker: 'test' + }); + } catch (e) { + ankiNoteDataException = e; + } + const result = {definition, ankiNoteData}; + if (typeof ankiNoteDataException !== 'undefined') { + result.ankiNoteDataException = ankiNoteDataException; + } + console.log(result); + } } -- cgit v1.2.3