From 68343db84c9fb4ee800bedab102385e6ecee245e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E6=A0=91?= Date: Thu, 15 Jan 2026 15:52:44 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=9B=B4=E6=96=B0=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E5=9B=BEAPI=E5=9F=9F=E5=90=8D=E5=B9=B6=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将随机图API域名从pic.acofork.com更新为pic1.acofork.com 移除不再使用的public/js/random.js脚本文件 --- public/js/random.js | 143 ---------------------------- src/content/posts/fenliu.md | 2 +- src/content/posts/other-sites.md | 2 +- src/content/posts/random-url-gen.md | 2 +- 4 files changed, 3 insertions(+), 146 deletions(-) delete mode 100644 public/js/random.js diff --git a/public/js/random.js b/public/js/random.js deleted file mode 100644 index 37b04a33d..000000000 --- a/public/js/random.js +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Static Random Pic API - * Generated by build script - */ -(() => { - var counts = { h: 979, v: 3596 }; - var domain = "https://pic.acofork.com"; - - // State management for session consistency - var sessionRandomH = null; - var sessionRandomV = null; - - // Helper: Get random URL for a type (h or v), persistent per session - function getRandomUrl(type) { - if (!counts[type] || counts[type] === 0) return ""; - - // Return existing session URL if available - if (type === "h" && sessionRandomH) return sessionRandomH; - if (type === "v" && sessionRandomV) return sessionRandomV; - - // Generate new if not exists - var num = Math.floor(Math.random() * counts[type]) + 1; - var url = domain + "/ri/" + type + "/" + num + ".webp"; - - // Save to session state - if (type === "h") sessionRandomH = url; - if (type === "v") sessionRandomV = url; - - return url; - } - - // Expose global functions - window.getRandomPicH = () => getRandomUrl("h"); - window.getRandomPicV = () => getRandomUrl("v"); - - // 1. Logic for Background (Customized based on user request) - function setRandomBackground() { - // Get random URL using the helper (Dynamic count & domain) - const bgUrl = getRandomUrl("h"); - - // Find the background box element - const bgBox = document.getElementById("bg-box"); - - if (bgBox) { - // Preload image - const img = new Image(); - img.onload = () => { - bgBox.style.backgroundImage = `url('${bgUrl}')`; - bgBox.classList.add("loaded"); - console.log("Random background loaded:", bgUrl); - - // Set CSS variables for transparency effects - document.documentElement.style.setProperty( - "--card-bg", - "var(--card-bg-transparent)", - ); - document.documentElement.style.setProperty( - "--float-panel-bg", - "var(--float-panel-bg-transparent)", - ); - }; - img.onerror = () => { - console.error("Failed to load background image:", bgUrl); - }; - img.src = bgUrl; - } else { - // Fallback: If no #bg-box, check for data-random-bg for backward compatibility/other elements - // This keeps the generic functionality available if needed, but prioritizes the user's specific logic above. - initGenericBackgrounds(); - } - } - - // 2. Logic for Image Tags (Generic) - function initImgTags() { - var imgTags = document.getElementsByTagName("img"); - for (var i = 0; i < imgTags.length; i++) { - var img = imgTags[i]; - var alt = img.getAttribute("alt"); - var src = img.getAttribute("src"); - - if (alt === "random:h" || (src && src.indexOf("/random/h") !== -1)) { - img.src = getRandomUrl("h"); - } else if ( - alt === "random:v" || - (src && src.indexOf("/random/v") !== -1) - ) { - img.src = getRandomUrl("v"); - } - } - } - - // Helper for generic data-random-bg (as a backup or secondary feature) - function initGenericBackgrounds() { - var bgElements = document.querySelectorAll("[data-random-bg]"); - bgElements.forEach((el) => { - // Skip if it is the bg-box we already handled (though setRandomBackground handles #bg-box specifically) - if (el.id === "bg-box") return; - - var type = el.getAttribute("data-random-bg"); - if (type === "h" || type === "v") { - var url = getRandomUrl(type); - if (url) { - var img = new Image(); - img.onload = () => { - el.style.backgroundImage = 'url("' + url + '")'; - el.classList.add("loaded"); - }; - img.src = url; - } - } - }); - } - - function init() { - setRandomBackground(); - initImgTags(); - } - - // Run on initial load - if (document.readyState === "loading") { - document.addEventListener("DOMContentLoaded", init); - } else { - init(); - } - - // Swup integration - function setupSwup() { - if (window.swup && window.swup.hooks) { - // Register hook for content replacement - window.swup.hooks.on("content:replace", init); - console.log("Random Pic API: Registered with Swup hooks."); - } - } - - if (window.swup) { - setupSwup(); - } else { - document.addEventListener("swup:enable", setupSwup); - } - - // Legacy Swup support - document.addEventListener("swup:contentReplaced", init); -})(); diff --git a/src/content/posts/fenliu.md b/src/content/posts/fenliu.md index 176168c78..602de3aa2 100644 --- a/src/content/posts/fenliu.md +++ b/src/content/posts/fenliu.md @@ -12,7 +12,7 @@ lang: "" Umami,用于在网站插入一个JS来进行访客统计以及展示访客信息 ::url{href="https://umami.acofork.com/share/CdkXbGgZr6ECKOyK"} 静态随机图,用于置顶文章Cover和整个网站的背景图 -::url{href="https://pic.acofork.com"} +::url{href="https://pic1.acofork.com"} --- 其他: https://acofork.com , https://www.acofork.com diff --git a/src/content/posts/other-sites.md b/src/content/posts/other-sites.md index a199007f6..ff09dccf1 100644 --- a/src/content/posts/other-sites.md +++ b/src/content/posts/other-sites.md @@ -10,7 +10,7 @@ lang: '' ::url{href="https://cover.acofork.com"} ::url{href="https://http.acofork.com"} -::url{href="https://pic.acofork.com"} +::url{href="https://pic1.acofork.com"} ::url{href="https://gallery.acofork.com"} ::url{href="https://img.072103.xyz"} ::url{href="https://eopfapi.acofork.com/pic"} diff --git a/src/content/posts/random-url-gen.md b/src/content/posts/random-url-gen.md index 63702e3cf..a00543ab2 100644 --- a/src/content/posts/random-url-gen.md +++ b/src/content/posts/random-url-gen.md @@ -105,7 +105,7 @@ lang: "" ::github{repo="afoim/Static_RandomPicAPI"} -上线的 API: https://pic.acofork.com +上线的 API: https://pic1.acofork.com # 总结 我们共探索了三种流派