Last active
July 25, 2025 16:49
-
-
Save fbecart/7abfde329e3f536160c0af1016e02b8b to your computer and use it in GitHub Desktop.
Bookmarklet to export Leo Trainer words to an Anki deck.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This bookmarklet makes it possible to transfer words from Leo Trainer to Anki. | |
| * It is configured for fr-de (French to German) translations, but can easily be | |
| * adapted to other languages. | |
| * | |
| * Prerequisites: | |
| * - a Leo account (http://www.leo.org/) with a few words saved in the trainer | |
| * - an Anki account (https://ankiweb.net/account/register) | |
| * | |
| * 1. Crunch the following code and add it to your bookmarks | |
| * (see http://ted.mielczarek.org/code/mozilla/bookmarklet.html) | |
| * 2. Run the bookmarklet | |
| * (you might have to run it twice, as the first run will lead you to the correct Leo page) | |
| * 3. Import the downloaded file in Anki using \t as field separator and allowing HTML in fields | |
| **/ | |
| // This is where you can adapt the script for other languages. | |
| // `fromLang` is the language you know already, whereas `toLang` is the language you're learning. | |
| const fromLang = 'fr'; | |
| const toLang = 'de'; | |
| function extractVocabulary() { | |
| const output = []; | |
| const lines = document.body.querySelectorAll('.tb-bg-alt-lightgray > tbody > tr'); | |
| for (let i = 0; i < lines.length; i++) { | |
| const line = lines[i]; | |
| output.push([ | |
| line.children[2].innerHTML, | |
| line.children[3].innerHTML, | |
| ]); | |
| } | |
| return output; | |
| } | |
| function downloadTsvFile(filename, content) { | |
| const tsv = content.reduce((acc, cur) => acc + cur.join('\t') + '\n', ''); | |
| const a = document.createElement('a'); | |
| a.setAttribute('href', 'data:text/tab-separated-values;charset=utf-8,' + encodeURIComponent(tsv)); | |
| a.setAttribute('download', filename); | |
| document.body.appendChild(a); | |
| a.click(); | |
| } | |
| const manageFolderUrl = 'https://dict.leo.org/trainer/manageFolder.php' + | |
| `?lp=${fromLang}${toLang}&lang=${toLang}`; | |
| if (location != manageFolderUrl) { | |
| location = manageFolderUrl; | |
| } else { | |
| downloadTsvFile('vokabeln.csv', extractVocabulary()); | |
| } |
Hi @paulwiniecki! Indeed, it looks like Leo has updated their page layout. The script made some assumptions which were not valid anymore.
I got the script working again -- by making different assumptions regarding the page layout. Could you please try it out and report any issue?
It's working for me again @fbecart. Thanks for the quick revisions!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @fbecart it looks there recently was an update to the Leo Trainer site, and the bookmarklet doesn't appear to be working for me anymore. Would you be able to test and let me know if the bookmarklet still works for you?
Thanks so much for all your work on this. I use your bookmarklet so often. It's incredibly helpful!