async function getNpmPackageStats(packageName) { const end = new Date().toJSON().split("T")[0]; return await fetch( `https://api.npmjs.org/downloads/point/last-year/${packageName}` ).then((r) => r.json()); } async function myOwnProjectsRender() { const el = document.getElementById("my-own-projects"); const myOwnProjects = await fetch("/my-own-projects.json").then((res) => res.json() ); const render = () => { let str = ""; myOwnProjects.projects.forEach((project, ind) => { str += `
${project.name.replace(
        /\n/gi,

${project.name.replace( /\n/gi, "
" )}

${project.description.replace(/\n/gi, "
")}

Open
`; }); el.innerHTML = str; }; render(); const npmLibs = myOwnProjects.projects.filter((project) => project.tags?.includes("npm") ); for (const project of npmLibs) { const packageName = project.url.split("/package/")[1]; const stat = await getNpmPackageStats(packageName).catch((err) => { console.error(`Error fetching NPM stats for ${packageName}:`, err); return null; }); if (stat) { project.description = `${ project.description }\n\n📦 NPM Downloads (last year): ${stat.downloads.toLocaleString( "en-US" )}`; } } render(); } async function myParticipationRender() { const el = document.getElementById("my-participation"); const myParticipation = await fetch("/my-participation.json").then((res) => res.json() ); let str = ""; myParticipation.projects.forEach((project, ind) => { str += `

${project.name.replace( /\n/gi, "
" )}

${project.description.replace(/\n/gi, "
")}

Open
`; }); el.innerHTML = str; } async function myTestimonialsRender() { const el = document.getElementById("my-testimonials"); const myTestimonials = await fetch("/my-testimonials.json").then((res) => res.json() ); let str = ""; myTestimonials.testimonials.forEach((testimonial, ind) => { str += `

${testimonial.comment.replace( /\n/gi, "
" )}


`; }); el.innerHTML = str; } class ConsentScreen extends EventTarget { constructor(settings) { super(); this.localStorageKey = settings?.localStorageKey ?? "consent-has-given"; this.elementId = settings?.elementId ?? "consent-screen"; this.privacyPolicyUrl = settings?.privacyPolicyUrl ?? "/privacy_policy"; if (document) this.element = document.getElementById(this.elementId); if (window) window.onstorage = this.consentScreenListener; if (window) window.consentScreen = this; if (localStorage) { const val = localStorage?.getItem(this.localStorageKey); this.updateConsentScreen(val); } } localStorageKey; elementId; privacyPolicyUrl; element; getConsentScreenCode(show) { return `
`; } updateConsentScreen(show) { if (this.element) this.element.innerHTML = this.getConsentScreenCode(show); this.dispatchEvent(new CustomEvent("change", { detail: show })); } consentScreenListener(event) { if ( event?.key === this.localStorageKey && event?.oldValue !== event?.newValue ) { this.updateConsentScreen(!event?.newValue); } } openPrivacyPolicyAction() { if (!window) return; window.open(this.privacyPolicyUrl, "_blank"); } consentAction(isAccepted) { if (!localStorage) return; localStorage?.setItem( this.localStorageKey, (isAccepted ?? false).toString() ); this.updateConsentScreen(isAccepted ?? false); } getConsentInfo() { return localStorage?.getItem(this.localStorageKey) ?? false; } }