Simple JavaScript to detect leeches

I was browsing through my deck and I found out I had a few leeches that were automatically suspended and I didn’t know about it. So I wondered if it were possible not to exclude leeches from review, but instead keep them in my review queue and notify me whenever they pop up in review. It turns out this is indeed possible and very easy to do so.

The first important step is that you change the leech action in your deck options to “tag only” so that leeches will not get removed from your review queue.

Then add the following piece of code to the front template of your card. It scans the string of tags for the word “leech” and performs an action as specified in the if block.

<script>
	var tags = "{{Tags}}";
	if (tags.search("leech") != -1) {
		// perform action if card is tagged as leech
		window.alert("This card is a leech!");
	}
</script>

This example will create a dialog box whenever you review a card with tag:leech. The appearance of the dialog box will depend on your OS; on my system it looks like this:

anki_leech_pc

If you know a little CSS, you can of course replace the code with something that directly modifies the appearance of the card instead of creating a dialog box. FWIW, dialogs with window.alert() seem to be currently working on Desktop and AnkiMobile but not on AnkiDroid.

5 Likes

Nice idea!
To avoid window alerts, I would place a more subtle

<div id="leechHint">
This card is slowing you down. You might want to adjust its difficulty.
</div>

at the very top, set its display attribute to none in CSS and show it with

document.getElementById("leechHint").style.display = "block";

when your condition is met.

This would work on any client and might be less intrusive :slight_smile:

3 Likes

I’m doing something similare. If the card has an ease below a certain threshold, I use the font sansforgetica

see in my repo : GitHub - thiswillbeyourgithub/Clozolkor: enhancing "cloze one by one" script by iTraveller

It works by creating

then in the styling :

span.ease1300 { font-family: “Sans Forgetica”; }
span.ease1350 { font-family: “Sans Forgetica”; }
span.ease1400 { font-family: “Sans Forgetica”; }
span.ease1500 { font-family: “Sans Forgetica”; }
span.ease1550 { font-family: “Sans Forgetica”; }
span.ease1600 { font-family: “Sans Forgetica”; }
span.ease1650 { font-family: “Sans Forgetica”; }
span.ease1700 { font-family: “Sans Forgetica”; }
span.ease1750 { font-family: “Sans Forgetica”; }
span.ease1800 { font-family: “Sans Forgetica”; }

Just figured you might be interested :slight_smile: Your code for detecting leeches is far clearner than mine… Actually I don’t think I implemented it in the end.

1 Like