Last active
December 24, 2020 05:24
-
-
Save r2dev2/2e655ef24a6af288d01a8d6d823d5617 to your computer and use it in GitHub Desktop.
WaifuProgrammingBooks
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
/** | |
* WaifuProgrammingBooks | |
* | |
* This uses github's api to get images of anime girls holding programming books. | |
* | |
* Usage: | |
* | |
* Add <script src="https://gist.githubusercontent.com/r2dev2bb8/2e655ef24a6af288d01a8d6d823d5617/raw/1bb4db5484247c3d19ae5432168ca31f0e241c78/waifubook.js" /> to your document head | |
* | |
* waifuProgrammingBooks.getLanguages() returns a language object with key: language url | |
* waifuProgrammingBooks.getImages(languageurl) returns an array of image objects of schema: { | |
name: name of image, | |
src: the image src | |
} | |
*/ | |
const waifuProgrammingBooks = { | |
/** | |
* Retrieve an object of language urls. | |
* | |
* @return object with key: url | |
*/ | |
getLanguages: async () => { | |
let langObject = {}; | |
let response = await fetch("https://api.github.com/repos/laynH/Anime-Girls-Holding-Programming-Books/contents").then(r => r.json()); | |
response.filter(e => e.type == "dir").map(lang => { | |
langObject[lang.name] = lang.url; | |
}) | |
return langObject; | |
}, | |
/** | |
* Retrieve an array of images from languages. | |
* | |
* @param langURL the url of the language | |
* @return an array with all the images of the language | |
*/ | |
getImages: async (langURL) => { | |
let response = await fetch(langURL).then(r => r.json()); | |
return response.map(e => { | |
return { | |
name: e.name, | |
src: e.download_url, | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment