Skip to content

Instantly share code, notes, and snippets.

@r2dev2
Last active December 24, 2020 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r2dev2/2e655ef24a6af288d01a8d6d823d5617 to your computer and use it in GitHub Desktop.
Save r2dev2/2e655ef24a6af288d01a8d6d823d5617 to your computer and use it in GitHub Desktop.
WaifuProgrammingBooks
/**
* 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