function looksLikeAsset(pathname) { // 末段包含 .xxx 扩展名就当资源(.js/.css/.png/.map 等) return /\.[a-zA-Z0-9]{1,8}$/.test(pathname); } function isHtmlNavigation(request) { const method = request.method.toUpperCase(); if (method !== "GET" && method !== "HEAD") return false; const accept = request.headers.get("accept") || ""; // 浏览器访问页面通常会带 text/html if (!accept.includes("text/html")) return false; return true; } /** * 混淆 HTML,给标签增加随机冗余属性 * @param {string} html 原始 HTML * @param {string} seed 用于随机的种子(如域名) * @returns {string} 混淆后的 HTML */ function obfuscateHtml(html, seed) { // 简单的伪随机函数 let hash = 0; for (let i = 0; i < seed.length; i++) { hash = (hash << 5) - hash + seed.charCodeAt(i); hash |= 0; } const pseudoRandom = () => { hash = (hash * 16807) % 2147483647; return (hash - 1) / 2147483646; }; const randomStr = (len) => { const chars = "abcdefghijklmnopqrstuvwxyz"; let str = ""; for (let i = 0; i < len; i++) { str += chars[Math.floor(pseudoRandom() * chars.length)]; } return str; }; // 1) 注入混淆属性到现有标签 // 匹配常见的开始标签,如