Skip to content

Instantly share code, notes, and snippets.

@Geekfish
Forked from fbecart/Leo-Anki.js
Last active February 8, 2019 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Geekfish/f0e54bd1f2ea1e67332ecc66a1f72227 to your computer and use it in GitHub Desktop.
Save Geekfish/f0e54bd1f2ea1e67332ecc66a1f72227 to your computer and use it in GitHub Desktop.
Bookmarklet to export Leo Trainer words to an Anki deck.
/**
* This bookmarklet makes it possible to transfer words from Leo Trainer to Anki.
* It only works for fr-de translations. Contact me for 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 http://ted.mielczarek.org/code/mozilla/bookmarklet.html
* 2. Run the bookmarklet on this page https://dict.leo.org/trainer/manageFolder.php?lp=frde&lang=de
* 3. Import the downloaded file in Anki using \t as field separator and allowing HTML in fields
**/
function extractVocabulary() {
var output = [];
var matches = document.body.querySelectorAll('.tblf2 > tbody > tr');
for (var index = 0; index < matches.length; index++) {
let item = matches[index];
output.push([
item.querySelector('td[lang=en]').innerHTML,
item.querySelector('td[lang=de]').innerHTML,
]);
}
return output;
}
function downloadTsvFile(filename, content) {
var tsv = content.reduce(function(acc, cur) {
return acc + cur.join('\t') + '\n';
}, "");
var 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();
}
var manageFolderUrl = 'https://dict.leo.org/trainer/manageFolder.php?lp=ende&lang=de';
if (location != manageFolderUrl)
location = manageFolderUrl;
else
downloadTsvFile('vokabeln.csv', extractVocabulary());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment