Last active
September 6, 2024 18:41
-
-
Save avrahamappel/c5fef18b5f2dcef247815a72b7336f4b to your computer and use it in GitHub Desktop.
Get total read word count for language
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
lang = location.pathname.split('/')[1]; | |
await fetch(`https://readlang.com/api/books?language=${lang}&firstLanguage=en&tag=completed`, { | |
"credentials": "include", | |
"headers": { | |
"Accept": "application/json, text/javascript, */*; q=0.01", | |
"X-Requested-With": "XMLHttpRequest", | |
}, | |
"referrer": `https://readlang.com/${lang}/library`, | |
"method": "GET", | |
"mode": "cors" | |
}) | |
.then(res => res.json()) | |
.then(books => | |
books.filter(book => book.userBook?.tags?.includes('completed')) | |
.map(book => book.totalWords || 0) | |
.reduce((a, b) => a + b, 0) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment