Last active
October 9, 2024 16:59
-
-
Save avrahamappel/9223a84cde2c278237d04708c34ce9f4 to your computer and use it in GitHub Desktop.
Get the smallest story from ReadLang.com for your current 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
(async () => { | |
lang = location.pathname.split('/')[1]; | |
selects = document.querySelectorAll('.customSelect'); | |
level = `${selects[1].value}-${selects[2].value}`; | |
document.querySelector('span.customSelect').click(); | |
setTimeout(async () => { | |
categories = Array.from(document.querySelectorAll('.multiSelectDropdown input')).filter((node) => node.checked).map(node => node.nextSibling.nextSibling.nodeValue).join("|"); | |
bookUrl = await fetch('https://readlang.com/api/books?' + new URLSearchParams({ | |
language: lang, | |
firstLanguage: 'en', | |
categories: categories, | |
'filter[metrics_CEF]': level, | |
public: true, | |
}), { | |
"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')) | |
.sort((a, b) => a.totalWords - b.totalWords) | |
.map(book => `https://readlang.com/library/${book._id}`)[0] | |
); | |
window.open(bookUrl, '_blank'); | |
}, 0); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment