Core JavaScript Files
functions.js
Utility functions for safe event handling and page load management
quotes.js
Random quote generator with 185+ pop culture quotes and automatic rotation
list-posts.js
Blog post loader using GitHub API and Markdown-to-HTML conversion
Event Handler Utility
TheaddLoadEvent() function safely chains multiple window load handlers without conflicts.
Implementation
File:assets/scripts/functions.js
How It Works
Conditional Assignment
If no existing handler exists (
typeof window.onload != 'function'), directly assigns the new functionThis pattern was common before modern JavaScript frameworks. It ensures multiple scripts can safely add load event handlers without overwriting each other.
Usage Example
Modern applications typically use
addEventListener('DOMContentLoaded', callback) or addEventListener('load', callback) instead, which natively supports multiple listeners.Random Quote System
The quote rotator displays random quotes from a database of 185+ quotes spanning movies, games, TV shows, and pop culture.Quote Database
File:assets/scripts/quotes.js
Quote Categories
Quote Categories
The quote database includes references from:
- Star Wars: 30+ quotes from the original trilogy, prequels, and sequels
- Marvel Cinematic Universe: Avengers, Black Panther, Guardians of the Galaxy
- Video Games: Portal, Bioshock, Metal Gear Solid, The Legend of Zelda, Halo
- Science Fiction: Star Trek, Terminator, Alien, The Matrix
- Fantasy: Lord of the Rings, Harry Potter, Game of Thrones
- Action & Comedy: Various movie and TV references
Core Functions
Function Breakdown
getRandomQuote()
Generates a random index using
Math.random() multiplied by the array length, then floors it to get an integer. Returns the quote object at that index.updateQuote()
Destructures the quote object to extract
quote and author properties, then updates the DOM elements with proper HTML entities for quotation marks (“ and ”) and em dash (—).HTML Integration
The quote system requires specific DOM elements:Blog Post Loader
The legacy blog system dynamically loads Markdown posts from GitHub and renders them as HTML.Configuration
File:old/blog/scripts/list-posts.js
This code depends on Showdown.js, a JavaScript Markdown parser. The library must be loaded before this script executes.
Fetching Post List
Loading Post Content
Workflow
GitHub API Request
Fetches the contents of
old/blog/posts/ directory from the update-urls branch using GitHub’s REST APIRender Post List
Creates a clickable list of post titles (filename without
.md extension), storing each post’s download_url in a data-url attributeEvent Delegation
Attaches a single click handler to the post list container that intercepts clicks on links and loads the corresponding post
Markdown Conversion
Fetches the raw Markdown content from the post’s
download_url and converts it to HTML using Showdown.jsAPI Endpoint Structure
GitHub’s API returns an array of file objects with metadata including
name, path, download_url, and more. The download_url provides direct access to raw file content.Error Handling
Both functions implement try-catch blocks with user-friendly error messages:fetchPostList() Errors
Displays “Error loading posts 😢” if the API request fails or returns non-200 status
loadPostContent() Errors
Shows “Error loading post content 😢” if individual post fetching or Markdown conversion fails
Dependencies
Performance Considerations
Quote System
- Bundle Size: 15.6 KB for 185 quotes (~84 bytes per quote)
- Execution: O(1) random access, instant display
- Memory: All quotes loaded upfront (negligible impact)
Blog System
- Initial Load: Single API request to fetch post list
- Per Post: One fetch request + Markdown parsing
- Optimization: No pagination (assumes small post count)
Browser Compatibility
All JavaScript uses modern ES6+ features:constandletdeclarations- Arrow functions
- Template literals
- Async/await
- Destructuring assignment
fetch()API
These features are supported in all modern browsers (Chrome 55+, Firefox 52+, Safari 11+, Edge 15+). Legacy IE11 support would require transpilation with Babel.
Security Considerations
innerHTML Usage
GitHub API
The blog system makes unauthenticated requests to GitHub’s public API:- Rate Limit: 60 requests/hour per IP for unauthenticated requests
- Public Data: Only accesses publicly available repository content
- No Tokens: Does not require or expose API tokens
