2022-05-17 20:43:26 +01:00
<!DOCTYPE html>
< html lang = "en" >
< head >
2022-05-18 11:17:35 +01:00
< title > frog_emojis< / title >
< link rel = "icon" type = "image/svg+xml" href = "https://raw.githubusercontent.com/Riesi/frog_emojis/master/svg/U1f438-frog.svg" sizes = "any" >
< link rel = "icon" href = "https://raw.githubusercontent.com/Riesi/frog_emojis/master/png/72/U1f438-frog.png" type = "image/png" >
2022-05-17 20:43:26 +01:00
< meta charset = "UTF-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< meta name = "apple-mobile-web-app-status-bar-style" content = "black-translucent" >
< link rel = "stylesheet" href = "./style.css" >
< title > Document< / title >
< style >
.frog-holder {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
}
img {
width: 256px;
height: auto;
}
< / style >
< / head >
2022-05-18 10:37:05 +01:00
< body style = "background-color:#292929;" >
2022-05-17 20:43:26 +01:00
< header class = "page-header" role = "banner" >
< h1 class = "project-name" > frog_emojis< / h1 >
< h2 class = "project-tagline" > Froggyfied custom emojies and logos< / h2 >
< a href = "https://github.com/Riesi/frog_emojis" class = "btn" > View on GitHub< / a >
< / header >
2022-05-18 11:06:18 +01:00
< div id = "mainholder" style = "text-align:center" > <!-- It's like the hand holder but with frogs -->
2022-05-17 20:43:26 +01:00
< / div >
< script type = "module" >
let cacheInvalidationPeriod = 1000 * 60; // 1 minute should be fine for github api ratelimiting
function frogCache_check() {
if (!window.localStorage) { // Some might have it disabled for privacy reasons
return false;
}
if (window.localStorage.getItem("frogCache_lastCheck") === null) {
return false;
}
let lastCheck = parseInt(window.localStorage.getItem("frogCache_lastCheck"));
let now = Date.now();
if (now - lastCheck > cacheInvalidationPeriod) {
return false;
}
return true;
}
function frogCache_commit(frogs) {
if (!window.localStorage) {
return false;
}
window.localStorage.setItem("frogCache_lastCheck", Date.now().toString());
window.localStorage.setItem("frogCache_frogs", JSON.stringify(frogs));
return true;
}
async function loadFrogs() {
let frogs;
if (!frogCache_check()) {
console.log("Re-fetching frogs");
frogs = await fetch("https://api.github.com/repos/Riesi/frog_emojis/git/trees/master?recursive=1")
2022-05-18 10:37:05 +01:00
.then(res => res.json())
2022-05-17 20:59:34 +01:00
.then(a => a.tree.filter(b => b.path.startsWith("svg/")));
2022-05-17 20:43:26 +01:00
//.then(a => a.filter(b => b.type === "blob"));
frogCache_commit(frogs);
} else {
console.log("Using old frogs");
frogs = JSON.parse(window.localStorage.getItem("frogCache_frogs"));
}
return frogs;
}
2022-05-18 10:37:05 +01:00
function mapFolderToDiv(folderPath) {
let divv = document.createElement("div");
2022-05-18 11:06:18 +01:00
let idstr = folderPath.replaceAll('/','');
2022-05-18 10:37:05 +01:00
divv.id = idstr;
divv.class = "frog-holder";
document.querySelector("#mainholder").appendChild(divv);
let section = document.createElement("h1");
section.textContent = folderPath.replace("svg/","")+":";
document.querySelector("#" + idstr).appendChild(section);
return idstr;
}
function mapFrogToImage(frogs, idstr) {
2022-05-18 11:06:18 +01:00
let folderfroglink = frogs.map(frog => {
2022-05-18 11:17:35 +01:00
let linkimage = document.createElement("a");
linkimage.href = `https://github.com/Riesi/frog_emojis/blob/master/${frog.path}`;
linkimage.target="_blank";
2022-05-18 11:06:18 +01:00
let link = `https://raw.githubusercontent.com/Riesi/frog_emojis/master/${frog.path}`
2022-05-18 10:37:05 +01:00
let image = document.createElement("img");
image.src = link;
2022-05-18 11:09:22 +01:00
image.title = frog.path.replaceAll("/","").replace(idstr,"").replace(".svg","").replaceAll("svg","");
2022-05-18 11:06:18 +01:00
image.style = "width:64px;margin:6px;"
2022-05-18 11:17:35 +01:00
linkimage.appendChild(image);
document.querySelector("#" + idstr).appendChild(linkimage);
2022-05-18 11:06:18 +01:00
});
2022-05-18 10:37:05 +01:00
document.querySelector("#mainholder").appendChild(document.createElement("br"));
}
2022-05-17 20:43:26 +01:00
loadFrogs().then(a => {
2022-05-18 10:37:05 +01:00
2022-05-18 11:09:22 +01:00
//console.log(a);
2022-05-17 20:43:26 +01:00
let frogs = a.filter(b => b.type === "blob"); // get pngs
let folders = a.filter(b => b.type === "tree") // get folders
2022-05-18 10:37:05 +01:00
2022-05-18 11:09:22 +01:00
//console.log(folders);
2022-05-17 20:43:26 +01:00
folders.map(folder => {
2022-05-18 11:09:22 +01:00
//console.log(folder);
2022-05-18 10:37:05 +01:00
let folderfrog = frogs.filter(folderfrog => folderfrog.path.startsWith(folder.path)); // get subfolder frogs
frogs = frogs.filter( ( frog ) => !folderfrog.includes( frog ) ); // remove subfolder frogs from list
2022-05-18 11:09:22 +01:00
//console.log(frogs);
2022-05-18 10:37:05 +01:00
mapFrogToImage(folderfrog, mapFolderToDiv(folder.path));
2022-05-17 20:43:26 +01:00
})
2022-05-18 10:37:05 +01:00
mapFrogToImage(frogs, mapFolderToDiv("root"));
2022-05-17 20:43:26 +01:00
})
< / script >
< footer class = "site-footer" >
2022-05-18 10:37:05 +01:00
< span class = "site-footer-owner" > < a href = "https://github.com/Riesi/frog_emojis" > frog_emojis< / a > is maintained by < a href = "https://github.com/Riesi" > Riesi< / a > and < a href = "https://github.com/Miepee" > Miepee< / a > . JavaScript base by < a href = "https://github.com/rphsoftware" > Rph< / a > < / span >
< / footer >
2022-05-17 20:43:26 +01:00
< / body >
< / html >