Anki was driving me nuts - it’s hard to replace Anki and their platform is limited for a reason. To keep it free, they had to make some constraints. Nonetheless I am not able to have plugins for Anki mobile, I can’t spin up my custom sync server and I can’t have any API endpoint to retrieve the data. I can write a bot to login to AnkiWeb and read data, but it isn’t nice solution.
I came up with a bit different one to make sure to sync data with beeminder. It should work on every platform and is quite elastic. You can execute JS in a card template. In your card template, you can add a snippet of code in either “back” or “front”:
<script>
(() => {
if (typeof window._skcount === "undefined") {
window._skcount = 0;
}
window._skcount += 1;
const $debug = document.querySelector("#skcount");
$debug.innerHTML = window._skcount;
const SYNC_EVERY_X_CARDS = 10;
const USER = "YOUR_NAME";
const AUTH_TOKEN = "YOUR_TOKEN";
const GOAL = "YOUR_GOAL";
if (window._skcount % SYNC_EVERY_X_CARDS === 0) {
fetch(`https://www.beeminder.com/api/v1/users/${USER}/goals/${GOAL}/datapoints.json?auth_token=${AUTH_TOKEN}`, {
headers: {
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify({ value: SYNC_EVERY_X_CARDS, comment: new Date().toString() }),
})
.then(() => {
$debug.innerHTML = "Saved to Beeminder!";
})
.catch((error) => ($debug.innerHTML = error.message));
}
})();
</script>
Please fill the template with your goal data and also place in your card this snippet: <div id="skcount"></div>
to see which card is it and see syncing status.
This script will add a beeminder data every X cards you review. It works for me on Anki MacOS, AnkiMobile (iOS) and AnkiWeb. Obviously it has a downside if you spread your efforts thin across different decks (20 decks, 5 cards to review in each).
Similarly, we can use JavaScript tricks to beemind beenary goals (did I review at least 1 card today?) or perhaps create “time spent on Anki” goal.