Created
February 25, 2018 07:26
-
-
Save echamudi/362428005dcc80b1d00157f186f3e4ac to your computer and use it in GitHub Desktop.
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
// https://www.memrise.com/course/199109/250-most-important-adjectives-japanese/ | |
(() => { | |
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 => { | |
// console.log(data.learnables) | |
let array = []; | |
for (let item of data.learnables) { | |
// console.log(item); | |
let kana = item.item.value | |
let english = item.definition.value | |
let kanji = item.confused_answers[0] ? item.confused_answers[0].value : ""; | |
if(kanji != "") { | |
array.push(kanji + "\n\n(" + kana + ");;;" + english + ";;;;"); | |
} else { | |
array.push(kana + ";;;" + english + ";;;;"); | |
} | |
} | |
return array.join(""); | |
}) : | |
[] | |
}) | |
.catch(err => { | |
console.error(err) | |
return [] | |
}) | |
} | |
// fetch | |
const start = 1 | |
const courseId = location.href.slice(30).match(/\d+/)[0] | |
let final = ""; | |
getWords(courseId, 1) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 2) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 3) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 4) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 5) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 6) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 7) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 8) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 9) | |
}) | |
.then(words => { | |
final = final + words; | |
return getWords(courseId, 10) | |
}) | |
.then(words => { | |
final = final + words; | |
console.log(final); | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment