Anki add-on: Card Reviewer JavaScript API

You can use this add-on to execute JavaScript commands for certain backend functions related to the card reviewer in Anki. To use, call pycmd(string | int) in your JavaScript block. Accepted pycmd Commands: set_card_flag(flag_id) : sets a flag from 0 to 7 (0 resets the flag) get_flag_status : gets the current flag from the Anki database undo_card : undo the last reviewed card go_home : returns to the Deck Browser screen Deprecated (but included) Utilities: pass_card : same as pressing the "Good" button, but via Javascript fail_card : same as pressing the "Again" button, but via Javascript Flag IDs: FLAG_COLORS = { // colorName: flag_id red: 1, orange: 2, green: 3, blue: 4, pink: 5, turquoise: 6, purple: 7, }; Update (July 22 2025): added get_all_flag_labels to fetch the flag labels. ⚠️ Note: This add-on was made to be used only in the Card Reviewer, in other words, when you actually review cards. It won't work if you're previewing the cards, although, this add-on may be updated to support this, i.e. for Flagging Cards while in previewer. This add-on was originally made to be used alongside my modern Anki card template at https://github.com/tyuichis/modern-anki-card-template

GitHub repository: tyuichis/modern-anki-card-template
Repository description: A modern cross-platform Anki card framework that helps build focused cards and improve readability.
Languages: SCSS, EJS, JavaScript, Python
Topics: anki, anki-templates