Skip to content

Instantly share code, notes, and snippets.

@Sensirex
Forked from raineorshine/memrise-export.js
Created March 4, 2018 08:00
Show Gist options
  • Select an option

  • Save Sensirex/93dee15e1963aa7cf49e02ad656ae16f to your computer and use it in GitHub Desktop.

Select an option

Save Sensirex/93dee15e1963aa7cf49e02ad656ae16f to your computer and use it in GitHub Desktop.
Export Memrise course words to CSV
/*
Export Memrise course words to CSV.
1. Log into memrise.com
2. Navigate to course home page (e.g. http://www.memrise.com/course/335725/comprehensive-german-duolingo-vocabulary/)
3. Open Developer Console
4. Paste below script and hit enter
5. After all urls have been fetched, copy final word list into spreadsheet.
*/
(() => {
function getWords(courseId, level) {
const url = `https://www.memrise.com/ajax/session/?course_id=${courseId}&level_index=${level}&session_slug=preview`
console.log('Fetching words from ' + url)
return fetch(url, { credentials: 'same-origin' })
// parse response
.then(res => {
return res.status === 200
? res.json()
// map results
.then(data => {
return Object.keys(data.learnables).map(key => ({
learnable_id: data.learnables[key].learnable_id,
thing_id: data.learnables[key].thing_id,
original: data.learnables[key].item.value,
translation: data.learnables[key].definition.value
}))
})
.then(words => {
return getWords(courseId, level + 1)
.then(words.concat.bind(words))
})
: []
})
.catch(err => {
console.error(err)
return []
})
}
// fetch
const start = 1
const courseId = location.href.slice(30).match(/\d+/)[0]
getWords(courseId, start)
// format as csv
.then(words => {
var data_table="learnable_id;thing_id;original;translation\n";
for(var i in words){
data_table+=`${words[i].learnable_id};${words[i].thing_id};${words[i].original};${words[i].translation}\n`;
}
var link = window.document.createElement("a");
link.setAttribute("href", "data:text/csv;charset=utf-8,%EF%BB%BF" + encodeURI(data_table));
link.setAttribute("download", "words.csv");
link.click();
setTimeout(function(){link.remove()},1000);
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment