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) 注入混淆属性到现有标签 // 匹配常见的开始标签,如 { const regex = new RegExp(`<${tag}(\\s|>)`, "gi"); html = html.replace(regex, (match, p1) => { // 随机生成 1-2 个混淆属性 const attrCount = 1 + Math.floor(pseudoRandom() * 2); let attrs = ""; for (let i = 0; i < attrCount; i++) { attrs += ` ${randomStr(5 + Math.floor(pseudoRandom() * 5))}`; } return `<${tag}${attrs}${p1}`; }); }); // 2) 之前保留的冗余标签逻辑(可选,用户重点是属性,但也保留一些结构冗余) const tags = ["div", "span", "p", "i", "b"]; const classes = ["hidden-content", "meta-info", "v-data", "loading-state", "wrapper-inner"]; const generateJunk = (count) => { let junk = "\n\n"; for (let i = 0; i < count; i++) { const tag = tags[Math.floor(pseudoRandom() * tags.length)]; const cls = classes[Math.floor(pseudoRandom() * classes.length)]; const id = "ui-" + Math.floor(pseudoRandom() * 10000); const extra = randomStr(6); junk += `<${tag} ${extra} id="${id}" class="${cls}" style="display:none; visibility:hidden; position:absolute; z-index:-1;">\n`; } junk += "\n"; return junk; }; if (html.includes("")) { return html.replace("", `${generateJunk(3 + Math.floor(pseudoRandom() * 5))}`); } return html + generateJunk(3); } export default { async fetch(request, env, ctx) { const url = new URL(request.url); // 1) 国家/地区访问控制 // 如果当前国家不是来自 AU, GB, UM, US, SG 这些的时候,显示为 /403.html const allowedCountries = ["AU", "GB", "UM", "US", "SG"]; const country = request.cf ? request.cf.country : null; if (country && !allowedCountries.includes(country)) { // 构造 403.html 的请求路径 const forbiddenUrl = new URL("/403.html", url.origin); const forbiddenResp = await fetch(forbiddenUrl.toString()); const forbiddenHtml = await forbiddenResp.text(); return new Response(forbiddenHtml, { status: 403, headers: { "Content-Type": "text/html;charset=UTF-8" } }); } // 不是页面导航 or 看起来是静态资源:直接回源,不替换 if (!isHtmlNavigation(request) || looksLikeAsset(url.pathname)) { return fetch(request); } const host = url.hostname; // e.g. bigwin7.vip const sub = host.split(".")[0] || "default"; // 1) 子品牌配置表:根据 load.m.js 的 sites_config 配置 const BRAND_MAP = { // 默认配置 default: { BRAND_NAME: "UsSlot777", BRAND_TITLE: "UsSlot777 | Online Slots & Real Money Games", BRAND_DESCRIPTION: "High-quality games, instant access, daily rewards, and a smooth experience built for serious slot fans.", BRAND_OG_TITLE: "UsSlot777 | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "High-quality games, instant access, daily rewards, and a smooth experience built for serious slot fans.", BRAND_HERO_TITLE: "Play America's Best Slots", BRAND_HERO_SUBTITLE: "High-quality games, instant access, daily rewards, and a smooth experience built for serious slot fans.", BRAND_PRIMARY_CTA_TEXT: "Start Playing Now", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@usslot777.com", THEME_COLOR: "#0f172a", FAV_ICO: "./resources/favicons/favicon.ico", BRAND_LOGO: url.origin + "/resources/logos/logo.png", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // bigwin7.vip - 红色文字 + 金色7 bigwin7: { BRAND_NAME: "BigWin7", BRAND_TITLE: "BigWin7 | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Experience the thrill of big wins with premium slot games.", BRAND_OG_TITLE: "BigWin7 | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Experience the thrill of big wins with premium slot games.", BRAND_HERO_TITLE: "Experience Big Wins", BRAND_HERO_SUBTITLE: "Experience the thrill of big wins with premium slot games.", BRAND_PRIMARY_CTA_TEXT: "Start Winning", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@bigwin7.vip", THEME_COLOR: "#B91C1C", FAV_ICO: "./resources/favicons/bigwin7.ico", BRAND_LOGO: url.origin + "/resources/logos/bigwin7.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // bigwinrush.vip - 紫色/粉色文字 + 绿色$ bigwinrush: { BRAND_NAME: "BigWinRush", BRAND_TITLE: "BigWinRush | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Rush to your biggest wins ever with exciting slot games.", BRAND_OG_TITLE: "BigWinRush | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Rush to your biggest wins ever with exciting slot games.", BRAND_HERO_TITLE: "Rush to Big Wins", BRAND_HERO_SUBTITLE: "Rush to your biggest wins ever with exciting slot games.", BRAND_PRIMARY_CTA_TEXT: "Join the Rush", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@bigwinrush.vip", THEME_COLOR: "#5B21B6", FAV_ICO: "./resources/favicons/bigwinrush.ico", BRAND_LOGO: url.origin + "/resources/logos/bigwinrush.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // cashstorm.net - 青色/蓝绿龙卷风 cashstorm: { BRAND_NAME: "CashStorm", BRAND_TITLE: "CashStorm | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Ride the storm and collect massive cash rewards.", BRAND_OG_TITLE: "CashStorm | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Ride the storm and collect massive cash rewards.", BRAND_HERO_TITLE: "Ride the Cash Storm", BRAND_HERO_SUBTITLE: "Ride the storm and collect massive cash rewards.", BRAND_PRIMARY_CTA_TEXT: "Enter the Storm", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@cashstorm.net", THEME_COLOR: "#0E7490", FAV_ICO: "./resources/favicons/cashstorm.ico", BRAND_LOGO: url.origin + "/resources/logos/cashstorm.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // hotwinzone.net - 红色/橙色火焰 hotwinzone: { BRAND_NAME: "HotWinZone", BRAND_TITLE: "HotWinZone | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Enter the hot zone where every spin is a winner.", BRAND_OG_TITLE: "HotWinZone | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Enter the hot zone where every spin is a winner.", BRAND_HERO_TITLE: "Enter the Hot Zone", BRAND_HERO_SUBTITLE: "Enter the hot zone where every spin is a winner.", BRAND_PRIMARY_CTA_TEXT: "Get Hot Wins", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@hotwinzone.net", THEME_COLOR: "#C2410C", FAV_ICO: "./resources/favicons/hotwinzone.ico", BRAND_LOGO: url.origin + "/resources/logos/hotwinzone.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // jackpotfury.net - 红色/橙色火焰文字 jackpotfury: { BRAND_NAME: "JackpotFury", BRAND_TITLE: "JackpotFury | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Unleash the fury and hit massive jackpots.", BRAND_OG_TITLE: "JackpotFury | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Unleash the fury and hit massive jackpots.", BRAND_HERO_TITLE: "Unleash Jackpot Fury", BRAND_HERO_SUBTITLE: "Unleash the fury and hit massive jackpots.", BRAND_PRIMARY_CTA_TEXT: "Hit Jackpots", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@jackpotfury.net", THEME_COLOR: "#B91C1C", FAV_ICO: "./resources/favicons/jackpotfury.ico", BRAND_LOGO: url.origin + "/resources/logos/jackpotfury.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // luckyhitnow.vip - 绿色四叶草 luckyhitnow: { BRAND_NAME: "LuckyHitNow", BRAND_TITLE: "LuckyHitNow | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Get lucky and hit big wins right now.", BRAND_OG_TITLE: "LuckyHitNow | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Get lucky and hit big wins right now.", BRAND_HERO_TITLE: "Get Lucky Now", BRAND_HERO_SUBTITLE: "Get lucky and hit big wins right now.", BRAND_PRIMARY_CTA_TEXT: "Try Your Luck", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@luckyhitnow.vip", THEME_COLOR: "#046E55", FAV_ICO: "./resources/favicons/luckyhitnow.ico", BRAND_LOGO: url.origin + "/resources/logos/luckyhitnow.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // megacashgo.vip - 绿色/金色文字 megacashgo: { BRAND_NAME: "MegaCashGo", BRAND_TITLE: "MegaCashGo | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Go big or go home with mega cash prizes.", BRAND_OG_TITLE: "MegaCashGo | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Go big or go home with mega cash prizes.", BRAND_HERO_TITLE: "Go for Mega Cash", BRAND_HERO_SUBTITLE: "Go big or go home with mega cash prizes.", BRAND_PRIMARY_CTA_TEXT: "Go Mega", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@megacashgo.vip", THEME_COLOR: "#046E55", FAV_ICO: "./resources/favicons/megacashgo.ico", BRAND_LOGO: url.origin + "/resources/logos/megacashgo.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // rapidjackpot.vip - 橙色火箭 rapidjackpot: { BRAND_NAME: "RapidJackpot", BRAND_TITLE: "RapidJackpot | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Fast spins, rapid jackpots, instant wins.", BRAND_OG_TITLE: "RapidJackpot | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Fast spins, rapid jackpots, instant wins.", BRAND_HERO_TITLE: "Rapid Jackpots Await", BRAND_HERO_SUBTITLE: "Fast spins, rapid jackpots, instant wins.", BRAND_PRIMARY_CTA_TEXT: "Win Fast", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@rapidjackpot.vip", THEME_COLOR: "#C2410C", FAV_ICO: "./resources/favicons/rapidjackpot.ico", BRAND_LOGO: url.origin + "/resources/logos/rapidjackpot.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // slotfrenzy.vip - 红色/黄色小丑 slotfrenzy: { BRAND_NAME: "SlotFrenzy", BRAND_TITLE: "SlotFrenzy | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Join the frenzy with non-stop slot action.", BRAND_OG_TITLE: "SlotFrenzy | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Join the frenzy with non-stop slot action.", BRAND_HERO_TITLE: "Join the Slot Frenzy", BRAND_HERO_SUBTITLE: "Join the frenzy with non-stop slot action.", BRAND_PRIMARY_CTA_TEXT: "Go Frenzy", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@slotfrenzy.vip", THEME_COLOR: "#B91C1C", FAV_ICO: "./resources/favicons/slotfrenzy.ico", BRAND_LOGO: url.origin + "/resources/logos/slotfrenzy.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // spinblitz.vip - 蓝色文字 + 黄色闪电 spinblitz: { BRAND_NAME: "SpinBlitz", BRAND_TITLE: "SpinBlitz | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Blitz through wins with lightning-fast spins.", BRAND_OG_TITLE: "SpinBlitz | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Blitz through wins with lightning-fast spins.", BRAND_HERO_TITLE: "Blitz to Victory", BRAND_HERO_SUBTITLE: "Blitz through wins with lightning-fast spins.", BRAND_PRIMARY_CTA_TEXT: "Start Blitz", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@spinblitz.vip", THEME_COLOR: "#1E40AF", FAV_ICO: "./resources/favicons/spinblitz.ico", BRAND_LOGO: url.origin + "/resources/logos/spinblitz.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // ultrawinner.net - 蓝色/紫色钻石 ultrawinner: { BRAND_NAME: "UltraWinner", BRAND_TITLE: "UltraWinner | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Become the ultimate winner with ultra rewards.", BRAND_OG_TITLE: "UltraWinner | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Become the ultimate winner with ultra rewards.", BRAND_HERO_TITLE: "Be the Ultra Winner", BRAND_HERO_SUBTITLE: "Become the ultimate winner with ultra rewards.", BRAND_PRIMARY_CTA_TEXT: "Win Ultra", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@ultrawinner.net", THEME_COLOR: "#5B21B6", FAV_ICO: "./resources/favicons/ultrawinner.ico", BRAND_LOGO: url.origin + "/resources/logos/ultrawinner.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, // winexplosion.vip - 红色/黄色/绿色混合 winexplosion: { BRAND_NAME: "WinExplosion", BRAND_TITLE: "WinExplosion | Online Slots & Real Money Games", BRAND_DESCRIPTION: "Explosive wins await in every spin.", BRAND_OG_TITLE: "WinExplosion | Online Slots & Real Money Games", BRAND_OG_DESCRIPTION: "Explosive wins await in every spin.", BRAND_HERO_TITLE: "Explosive Wins Await", BRAND_HERO_SUBTITLE: "Explosive wins await in every spin.", BRAND_PRIMARY_CTA_TEXT: "Explode to Win", BRAND_PRIMARY_CTA_LINK: "/start", SUPPORT_EMAIL: "support@winexplosion.vip", THEME_COLOR: "#B91C1C", FAV_ICO: "./resources/favicons/winexplosion.ico", BRAND_LOGO: url.origin + "/resources/logos/winexplosion.webp", BRAND_OG_IMAGE: url.origin + "/resources/product/thumbn.webp", }, }; const brand = BRAND_MAP[sub] || BRAND_MAP.default; // 2) 计算 BRAND_URL(保持当前 host,不要写死) brand.BRAND_URL = `${url.protocol}//${host}${url.pathname === "/" ? "/" : url.pathname}`; // 3) 拉取源站 HTML(如果你是 Pages,可直接 return new Response(...) 处理) // 这里用"回源"方式示例:把请求转发到真正的源站(例如你的 Pages/服务器) const originResp = await fetch(request); // 非 HTML 资源直接透传(css/js/png 等) const contentType = originResp.headers.get("content-type") || ""; if (!contentType.includes("text/html")) return originResp; // 4) 用 HTMLRewriter + 文本替换 // HTMLRewriter 更适合替换 title/meta;占位符替换更适合批量文本替换 // 这里两种一起用:先把响应体转文本做占位符替换,再返回 let html = await originResp.text(); // 4.1 占位符替换(%%KEY%%) for (const [k, v] of Object.entries(brand)) { const safeV = String(v).replaceAll("$", "$"); // 防止某些模板字符串/特殊符号干扰 html = html.replaceAll(`%%${k}%%`, safeV); } // 4.2 如果路径包含 landingpage 或 startup,则进行混淆 if (url.pathname.includes("landingpage") || url.pathname.includes("startup")) { html = obfuscateHtml(html, host); } // 4.3 安全兜底:如果页面里存在未替换占位符,可选择清空或保留 // html = html.replace(/%%[A-Z0-9_]+%%/g, ""); // 5) 返回响应(保留原响应的大部分 header,但要修正 content-length) const newHeaders = new Headers(originResp.headers); newHeaders.delete("content-length"); return new Response(html, { status: originResp.status, statusText: originResp.statusText, headers: newHeaders, }); }, };