2023-08-10 22:47:28 +01:00
|
|
|
import API from "./API";
|
2023-08-10 14:19:11 +01:00
|
|
|
import UI from "./UI";
|
2023-08-10 22:47:28 +01:00
|
|
|
import Input from "./Input";
|
2023-08-11 17:15:21 +01:00
|
|
|
import Author from "./Author";
|
2023-09-24 17:03:06 +01:00
|
|
|
import BlogPost from "./BlogPost";
|
2023-08-10 04:56:12 +01:00
|
|
|
|
2023-08-10 14:36:51 +01:00
|
|
|
declare const Handlebars: any;
|
2023-08-10 23:28:23 +01:00
|
|
|
declare const Prism: any;
|
2023-08-04 12:55:16 +01:00
|
|
|
|
|
|
|
(() => {
|
2023-08-10 23:28:23 +01:00
|
|
|
Prism.languages.extend('markup', {});
|
2023-08-14 00:58:32 +01:00
|
|
|
Prism.languages.hex = {
|
|
|
|
'number': {
|
2023-08-16 15:17:05 +01:00
|
|
|
pattern: /(?:[a-fA-F0-9]{3}){1,2}\b/i,
|
2023-08-14 00:58:32 +01:00
|
|
|
lookbehind: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Prism.languages.binary = {
|
|
|
|
'number': {
|
|
|
|
pattern: /[10]+/i,
|
|
|
|
lookbehind: true
|
|
|
|
}
|
|
|
|
};
|
2023-08-10 23:28:23 +01:00
|
|
|
Prism.languages.insertBefore('custom', 'tag', {
|
|
|
|
'mark': {
|
|
|
|
pattern: /<\/?mark(?:\s+\w+(?:=(?:"[^"]*"|'[^']*'|[^\s'">=]+))?\s*|\s*)\/?>/,
|
|
|
|
greedy: true
|
|
|
|
}
|
|
|
|
});
|
2023-08-11 02:08:48 +01:00
|
|
|
|
2023-09-24 17:15:40 +01:00
|
|
|
Handlebars.registerHelper("urlEncode", encodeURIComponent);
|
|
|
|
|
2023-09-24 17:03:06 +01:00
|
|
|
function getQueryVariable(variable: string): string {
|
|
|
|
const query = window.location.search.substring(1);
|
|
|
|
const vars = query.split("&");
|
|
|
|
for (const element of vars) {
|
|
|
|
const pair = element.split("=");
|
|
|
|
if (pair[0] == variable) {
|
|
|
|
return pair[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-10 22:47:28 +01:00
|
|
|
Input.registerShortcut(Input.KONAMI_CODE, () => {
|
|
|
|
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
|
|
|
|
});
|
|
|
|
|
2023-08-13 17:33:54 +01:00
|
|
|
const blogPost = UI.blogPost;
|
|
|
|
if (blogPost) {
|
|
|
|
const id = blogPost.dataset.blogId;
|
|
|
|
API.getBlogPost(id).then((post) => {
|
|
|
|
blogPost.innerHTML = post.content;
|
|
|
|
UI.updateUI(blogPost);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-10 14:19:11 +01:00
|
|
|
const blogPostContainer = UI.blogPostContainer;
|
2023-08-10 04:56:12 +01:00
|
|
|
if (blogPostContainer) {
|
2023-08-11 17:15:21 +01:00
|
|
|
const authors = [];
|
2023-08-10 14:36:51 +01:00
|
|
|
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);
|
2023-08-10 04:56:12 +01:00
|
|
|
API.getBlogPostCount().then(async (count) => {
|
2023-08-13 15:24:24 +01:00
|
|
|
for (let i = 0; i <= count / 10; i++) {
|
2023-09-24 17:03:06 +01:00
|
|
|
let posts: BlogPost[];
|
|
|
|
|
|
|
|
const tag = getQueryVariable("tag");
|
2023-09-24 18:39:21 +01:00
|
|
|
if (tag !== null && tag !== "") {
|
|
|
|
posts = await API.getBlogPostsByTag(decodeURIComponent(tag), i);
|
2023-09-24 17:03:06 +01:00
|
|
|
} else {
|
|
|
|
posts = await API.getBlogPosts(i);
|
|
|
|
}
|
|
|
|
|
2023-08-10 04:56:12 +01:00
|
|
|
for (const post of posts) {
|
2023-08-11 17:15:21 +01:00
|
|
|
let author: Author;
|
|
|
|
if (authors[post.authorId]) {
|
|
|
|
author = authors[post.authorId];
|
|
|
|
} else {
|
|
|
|
author = await API.getAuthor(post.authorId);
|
|
|
|
authors[post.authorId] = author;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:18:24 +01:00
|
|
|
const card = UI.createBlogPostCard(template, post, author);
|
2023-08-10 04:56:12 +01:00
|
|
|
blogPostContainer.appendChild(card);
|
2023-08-10 15:31:51 +01:00
|
|
|
UI.updateUI(card);
|
2023-08-10 04:56:12 +01:00
|
|
|
}
|
|
|
|
}
|
2023-08-10 04:57:17 +01:00
|
|
|
|
2023-08-10 16:14:30 +01:00
|
|
|
document.body.appendChild(UI.createDisqusCounterScript());
|
|
|
|
|
2023-08-10 14:32:56 +01:00
|
|
|
const spinner = document.querySelector("#blog-loading-spinner");
|
2023-08-10 04:56:12 +01:00
|
|
|
if (spinner) {
|
|
|
|
spinner.classList.add("removed");
|
2023-08-11 02:08:48 +01:00
|
|
|
setTimeout(() => spinner.remove(), 1000);
|
2023-08-10 04:56:12 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-10 15:15:06 +01:00
|
|
|
UI.updateUI();
|
2024-02-19 22:44:28 +00:00
|
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
const countdown = document.querySelector("#usa-countdown p");
|
|
|
|
const start = new Date().getTime();
|
|
|
|
const end = Date.UTC(2024, 2, 7, 13, 20);
|
|
|
|
const diff = end - start;
|
|
|
|
let days = Math.floor(diff / (1000 * 60 * 60 * 24));
|
|
|
|
let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
|
|
|
let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
|
|
|
let seconds = Math.floor((diff % (1000 * 60)) / 1000);
|
|
|
|
|
|
|
|
if (days < 0) days = 0
|
|
|
|
if (hours < 0) hours = 0;
|
|
|
|
if (minutes < 0) minutes = 0;
|
|
|
|
if (seconds < 0) seconds = 0;
|
|
|
|
|
|
|
|
countdown.innerHTML = `${days.toString().padStart(2, '0')} : ${hours.toString().padStart(2, '0')} : ${minutes.toString().padStart(2, '0')} : ${seconds.toString().padStart(2, '0')}`;
|
|
|
|
}, 1000);
|
2023-08-04 12:55:16 +01:00
|
|
|
})();
|