Style: Apply deno lint and deno fmt across codebase

This commit is contained in:
lifeadventurer
2024-10-31 19:56:47 +08:00
parent df772b0bde
commit 778cb316c0
20 changed files with 882 additions and 702 deletions

View File

@@ -1,33 +1,36 @@
// fetch all folder paths of the generators from `folders.json`
let folderPaths = []
let folderPaths = [];
async function fetch_folders() {
await fetch('./folders.json')
.then(response => response.json())
.then(data => {
folderPaths = data.folder_paths;
})
await fetch("./folders.json")
.then((response) => response.json())
.then((data) => {
folderPaths = data.folder_paths;
});
}
async function get_generator_card_footer() {
await fetch_folders()
const repoOwner = 'LifeAdventurer';
const repoName = 'generators';
await fetch_folders();
const repoOwner = "LifeAdventurer";
const repoName = "generators";
for (let folderIndex = 1; folderIndex <= folderPaths.length; folderIndex++) {
const folderPath = folderPaths[folderIndex - 1];
const apiUrl = `https://api.github.com/repos/${repoOwner}/${repoName}/commits?path=${folderPath}`;
const apiUrl =
`https://api.github.com/repos/${repoOwner}/${repoName}/commits?path=${folderPath}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// the latest commit will be at the top of the list
const lastCommit = data[0].commit.author.date;
const commitTimeStamp = new Date(lastCommit).getTime() / 1000;
const currentTimeStamp = Math.floor(new Date().getTime() / 1000);
const timeDifference = currentTimeStamp - commitTimeStamp;
$(`#last-update-${folderIndex}`).html(`Last updated ${format_time_difference(timeDifference)} ago`)
})
.then((response) => response.json())
.then((data) => {
// the latest commit will be at the top of the list
const lastCommit = data[0].commit.author.date;
const commitTimeStamp = new Date(lastCommit).getTime() / 1000;
const currentTimeStamp = Math.floor(new Date().getTime() / 1000);
const timeDifference = currentTimeStamp - commitTimeStamp;
$(`#last-update-${folderIndex}`).html(
`Last updated ${format_time_difference(timeDifference)} ago`,
);
});
// .catch(error => console.error('Error fetching data:', error));
}
}
@@ -39,21 +42,21 @@ function format_time_difference(seconds) {
const days = Math.floor(hours / 24);
if (days > 0) {
return `${days} day${days > 1 ? 's' : ''}`;
} else if(hours > 0) {
return `${hours} hour${hours > 1 ? 's' : ''}`;
} else if(minutes > 0) {
return `${minutes} minute${minutes > 1 ? 's' : ''}`;
return `${days} day${days > 1 ? "s" : ""}`;
} else if (hours > 0) {
return `${hours} hour${hours > 1 ? "s" : ""}`;
} else if (minutes > 0) {
return `${minutes} minute${minutes > 1 ? "s" : ""}`;
} else {
return `${seconds} second${seconds > 1 ? 's' : ''}`;
return `${seconds} second${seconds > 1 ? "s" : ""}`;
}
}
get_generator_card_footer()
get_generator_card_footer();
const darkModeIcon = document.querySelector('#dark-mode-icon');
const darkModeIcon = document.querySelector("#dark-mode-icon");
darkModeIcon.onclick = () => {
darkModeIcon.classList.toggle('bx-sun');
document.body.classList.toggle('dark-mode');
darkModeIcon.classList.toggle("bx-sun");
document.body.classList.toggle("dark-mode");
};