diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-09-01 12:14:24 -0500 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-09-01 12:14:24 -0500 |
| commit | b21858860496fbe0229278ded54a840ad15fddb2 (patch) | |
| tree | fbab086d6a1b8fea5f745b3990f9e1f31d6f6472 /assignment.js | |
all of the things
Diffstat (limited to 'assignment.js')
| -rw-r--r-- | assignment.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/assignment.js b/assignment.js new file mode 100644 index 0000000..7d8a7a5 --- /dev/null +++ b/assignment.js @@ -0,0 +1,82 @@ +function addMetadata() { + // Favicon + const favicon = document.createElement("link"); + favicon.rel = "icon"; + favicon.href = "../Logo.svg"; + favicon.type = "image/svg+xml"; + document.head.appendChild(favicon); + + // UTF-8 charset + const charset = document.createElement("meta"); + charset.setAttribute("charset", "UTF-8"); + document.head.appendChild(charset); + + // Viewport for mobile + const viewport = document.createElement("meta"); + viewport.setAttribute("name", "viewport"); + viewport.setAttribute("content", "width=device-width, initial-scale=1.0"); + document.head.appendChild(viewport); + + // Primary stylesheet + const css = document.createElement("link"); + css.rel = "stylesheet"; + css.href = "../style.css"; + document.head.appendChild(css); +} + +function addHeader() { + const header = document.querySelector("header"); + if (!header) return; + + // Back Link + const backLink = document.createElement("a"); + backLink.href = "../index.html"; + backLink.classList.add("header-logo-link"); + backLink.textContent = "<- Back to Index"; + header.appendChild(backLink); + + // Right-side info container + const info = document.createElement("div"); + info.classList.add("header-info"); + + // Title from document.title + const h1 = document.createElement("h1"); + h1.textContent = document.title; + info.appendChild(h1); + + // Read date from <meta property="article:published_time"> + const metaDate = document.querySelector('meta[property="article:published_time"]'); + if (metaDate) { + const dateString = metaDate.getAttribute("content"); + const displayDate = (new Date(dateString)).toLocaleDateString("en-US", { + month: "short", + day: "numeric", + year: "numeric", + timeZone: "UTC" + }); + + const time = document.createElement("time"); + time.setAttribute("datetime", dateString); + time.textContent = `Updated ${displayDate}`; + info.appendChild(time); + } + + // Read class tag from <meta name="class"> + const metaClass = document.querySelector('meta[name="class"]'); + if (metaClass) { + const classTag = document.createElement("span"); + classTag.classList.add("class-tag"); + classTag.textContent = `Class: ${metaClass.getAttribute("content")}`; + info.appendChild(classTag); + } + + header.appendChild(info); + + const hr = document.createElement("hr"); + header.appendChild(hr); +} + +document.addEventListener("DOMContentLoaded", () => { + addMetadata(); + addHeader(); +}); |
