diff options
Diffstat (limited to 'ext/bg')
| -rw-r--r-- | ext/bg/data/options-schema.json | 7 | ||||
| -rw-r--r-- | ext/bg/js/anki.js | 16 | ||||
| -rw-r--r-- | ext/bg/js/backend.js | 11 | ||||
| -rw-r--r-- | ext/bg/js/options.js | 3 | ||||
| -rw-r--r-- | ext/bg/settings2.html | 12 | 
5 files changed, 47 insertions, 2 deletions
| diff --git a/ext/bg/data/options-schema.json b/ext/bg/data/options-schema.json index 44bff10a..8c00d455 100644 --- a/ext/bg/data/options-schema.json +++ b/ext/bg/data/options-schema.json @@ -739,7 +739,8 @@                                      "kanji",                                      "duplicateScope",                                      "checkForDuplicates", -                                    "fieldTemplates" +                                    "fieldTemplates", +                                    "suspendNewCards"                                  ],                                  "properties": {                                      "enable": { @@ -841,6 +842,10 @@                                      "fieldTemplates": {                                          "type": ["string", "null"],                                          "default": null +                                    }, +                                    "suspendNewCards": { +                                        "type": "boolean", +                                        "default": false                                      }                                  }                              }, diff --git a/ext/bg/js/anki.js b/ext/bg/js/anki.js index 05c07ce2..68d9fc43 100644 --- a/ext/bg/js/anki.js +++ b/ext/bg/js/anki.js @@ -122,6 +122,22 @@ class AnkiConnect {          return await this._invoke('multi', {actions});      } +    async suspendCards(cardIds) { +        if (!this._enabled) { return false; } +        await this._checkVersion(); +        return await this._invoke('suspend', {cards: cardIds}); +    } + +    async findCards(query) { +        if (!this._enabled) { return []; } +        await this._checkVersion(); +        return await this._invoke('findCards', {query}); +    } + +    async findCardsForNote(noteId) { +        return await this.findCards(`nid:${noteId}`); +    } +      getRootDeckName(deckName) {          const index = deckName.indexOf('::');          return index >= 0 ? deckName.substring(0, index) : deckName; diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index 6410b0fc..11a17381 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -97,6 +97,7 @@ class Backend {              ['getAnkiNoteInfo',              {async: true,  contentScript: true,  handler: this._onApiGetAnkiNoteInfo.bind(this)}],              ['injectAnkiNoteMedia',          {async: true,  contentScript: true,  handler: this._onApiInjectAnkiNoteMedia.bind(this)}],              ['noteView',                     {async: true,  contentScript: true,  handler: this._onApiNoteView.bind(this)}], +            ['suspendAnkiCardsForNote',      {async: true,  contentScript: true,  handler: this._onApiSuspendAnkiCardsForNote.bind(this)}],              ['commandExec',                  {async: false, contentScript: true,  handler: this._onApiCommandExec.bind(this)}],              ['getDefinitionAudioInfo',       {async: true,  contentScript: true,  handler: this._onApiGetDefinitionAudioInfo.bind(this)}],              ['downloadDefinitionAudio',      {async: true,  contentScript: true,  handler: this._onApiDownloadDefinitionAudio.bind(this)}], @@ -495,6 +496,16 @@ class Backend {          return await this._anki.guiBrowseNote(noteId);      } +    async _onApiSuspendAnkiCardsForNote({noteId}) { +        const cardIds = await this._anki.findCardsForNote(noteId); +        const count = cardIds.length; +        if (count > 0) { +            const okay = await this._anki.suspendCards(cardIds); +            if (!okay) { return 0; } +        } +        return count; +    } +      _onApiCommandExec({command, params}) {          return this._runCommand(command, params);      } diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js index 0d3e42a1..cbc390da 100644 --- a/ext/bg/js/options.js +++ b/ext/bg/js/options.js @@ -687,6 +687,8 @@ class OptionsUtil {          //  Added sentenceParsing.enableTerminationCharacters.          //  Added sentenceParsing.terminationCharacters.          //  Changed general.popupActionBarLocation. +        //  Added inputs.hotkeys. +        //  Added anki.suspendNewCards.          for (const profile of options.profiles) {              profile.options.translation.textReplacements = {                  searchOriginal: true, @@ -731,6 +733,7 @@ class OptionsUtil {                      {action: 'copyHostSelection', key: 'KeyC',      modifiers: ['ctrl'], scopes: ['popup', 'search'], enabled: true}                  ]              }; +            profile.options.anki.suspendNewCards = false;          }          return options;      } diff --git a/ext/bg/settings2.html b/ext/bg/settings2.html index 5b9d702d..f44b7eab 100644 --- a/ext/bg/settings2.html +++ b/ext/bg/settings2.html @@ -1357,7 +1357,7 @@              </div>          </div></div>          <div class="settings-item advanced-only"> -            <div class="settings-item-inner settings-item-inner-wrappable"> +            <div class="settings-item-inner">                  <div class="settings-item-left">                      <div class="settings-item-label">Check for card duplicates</div>                      <div class="settings-item-description">When a card is detected as a duplicate, the add buttons will be disabled.</div> @@ -1435,6 +1435,16 @@                  </div>              </div>          </div></div> + +        <div class="settings-item advanced-only"><div class="settings-item-inner"> +            <div class="settings-item-left"> +                <div class="settings-item-label">Suspend new cards</div> +                <div class="settings-item-description">New cards will be suspended when a note is added.</div> +            </div> +            <div class="settings-item-right"> +                <label class="toggle"><input type="checkbox" data-setting="anki.suspendNewCards"><span class="toggle-body"><span class="toggle-track"></span><span class="toggle-knob"></span></span></label> +            </div> +        </div></div>          <div class="settings-item settings-item-button" data-modal-action="show,anki-cards"><div class="settings-item-inner">              <div class="settings-item-left">                  <div class="settings-item-label">Configure Anki card format…</div> |