Skip to content

Instantly share code, notes, and snippets.

@wlib
Last active February 24, 2017 14:55
Show Gist options
  • Save wlib/39f87ca54c0ce6c2f61fae55dfde3266 to your computer and use it in GitHub Desktop.
Save wlib/39f87ca54c0ce6c2f61fae55dfde3266 to your computer and use it in GitHub Desktop.
Get all your duolingo vocab words, then import them to quizlet as a set
// You must run this on the website because of the
// authentication method and CORS
// We get the definitions here
function callback(defs) {
window.quizlet = "";
for (let word in defs) {
quizlet += (word + "\t" + defs[word].join(", ") + "\n");
}
console.log(quizlet);
}
function getDefs(words) {
const script = document.createElement("script");
script.async = "async";
script.src = "https://d2.duolingo.com/api/1/dictionary/hints/de/en?callback=callback&tokens=" + encodeURIComponent( JSON.stringify(words) );
document.head.appendChild(script);
script.onload = script.onreadystatechange = function() {
if ( /loaded|complete/.test(script.readyState) ) {
script.parent.removeChild(script);
}
}
}
window.words = {};
function parse(obj) {
const out = {};
const wordList = obj.vocab_overview;
for (let i in wordList) {
let wordObj = wordList[i];
let word = wordObj.word_string;
out[word] = {};
out[word].pos = wordObj.pos;
out[word].gender = wordObj.gender;
out[word].skill = wordObj.skill;
}
return window.words = out;
}
function getWordList() {
const xhr = new XMLHttpRequest();
xhr.open("GET", "/vocabulary/overview", true);
xhr.onreadystatechange = function() {
if ( xhr.readyState === 4 && xhr.status === 200 ) {
const obj = JSON.parse(xhr.responseText);
const parsedObj = parse(obj);
const wordList = Object.keys( window.words );
getDefs(wordList);
}
}
xhr.send();
}
getWordList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment