diff --git a/patches/patch_license.js b/patches/patch_license.js index b22c23a..53b3644 100644 --- a/patches/patch_license.js +++ b/patches/patch_license.js @@ -9,7 +9,7 @@ */ const FS = require("fs"); const CP = require("child_process"); -const VERSION = process.env.PATCH_VERSION || "fixed35"; +const VERSION = process.env.PATCH_VERSION || "fixed36"; const log = (...a) => console.log("[PATCH-LICENSE]", ...a); let failures = []; function checkFile(p) { @@ -120,34 +120,71 @@ function writeChecked(p, s) { 'let ov=null,dead=!1;', '(0,u.useEffect)(()=>{const T=setTimeout(()=>{fetch("/api/license-config",{cache:"no-store"}).then(r=>r.json()).then(j=>{if(dead||!j||200!==j.code||!j.data)return;const d=j.data;let ann=null;try{const seen=JSON.parse(localStorage.getItem("hub_seen")||"{}");if(d.announcement&&!seen["a"+d.announcement.id])ann=d.announcement}catch(e){}let upd=null;try{upd=(d.update_available&&localStorage.getItem("hub_ver_dismiss")!==String(d.latest||""))?d:null}catch(e){}if(!ann&&!upd)return;ov=document.createElement("div");ov.className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4";ov.style.backdropFilter="blur(4px)";const card=document.createElement("div");card.className="bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full max-h-[80vh] flex flex-col overflow-hidden";const head=document.createElement("div");head.className="flex items-center justify-between px-6 pt-5 pb-3";const h3=document.createElement("h3");h3.className="text-base font-bold text-gray-900 dark:text-gray-100 truncate mr-2";h3.textContent=ann?String(ann.title||"📢 公告"):"发现新版本 v"+String(upd&&upd.latest||"");const xb=document.createElement("button");xb.className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-lg leading-none flex-shrink-0";xb.textContent="✕";head.appendChild(h3);head.appendChild(xb);const bd=document.createElement("div");bd.className="px-6 pb-2 overflow-y-auto text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap";bd.textContent=ann?String(ann.content||""):String(upd&&upd.changelog||"").slice(0,600);const ver=document.createElement("div");ver.className="mt-3 text-xs text-gray-400 dark:text-gray-500";ver.textContent="当前版本 v"+String(upd&&upd.version||"");bd.appendChild(ver);card.appendChild(head);card.appendChild(bd);const closeAnn=()=>{try{if(ann){const s=JSON.parse(localStorage.getItem("hub_seen")||"{}");s["a"+ann.id]=1;localStorage.setItem("hub_seen",JSON.stringify(s))}}catch(e){}if(ov&&ov.parentNode)ov.parentNode.removeChild(ov)};xb.onclick=closeAnn;if(upd||ann&&ann.link_url){const foot=document.createElement("div");foot.className="px-6 py-4 bg-gray-50 dark:bg-gray-700/50 flex items-center justify-end gap-2";if(ann&&ann.link_url){const la=document.createElement("a");la.href=ann.link_url;la.target="_blank";la.rel="noopener";la.className="px-3 py-1.5 rounded-lg text-xs font-medium text-purple-600 dark:text-purple-400 hover:bg-purple-500/10";la.textContent="查看详情 →";foot.appendChild(la)}if(upd){const ok=document.createElement("button");ok.className="px-4 py-1.5 rounded-lg text-xs font-medium text-white bg-purple-600 hover:bg-purple-700";ok.textContent="我知道了";ok.onclick=()=>{try{localStorage.setItem("hub_ver_dismiss",String(upd.latest||""))}catch(e){}if(ov&&ov.parentNode)ov.parentNode.removeChild(ov)};foot.appendChild(ok)}else{const cb=document.createElement("button");cb.className="px-3 py-1.5 rounded-lg text-xs font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600";cb.textContent="关闭";cb.onclick=closeAnn;foot.appendChild(cb)}card.appendChild(foot)}ov.appendChild(card);ov.onclick=(e)=>{if(e.target===ov)closeAnn()};document.body.appendChild(ov)}).catch(()=>{})},1200);return()=>{dead=!0;if(ov&&ov.parentNode)ov.parentNode.removeChild(ov)}},[]);', 'return null}', + 'function mvModal(t,b,l){const ov=document.createElement("div");ov.className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/50 p-4";ov.style.backdropFilter="blur(4px)";const card=document.createElement("div");card.className="bg-white dark:bg-gray-800 rounded-2xl shadow-2xl max-w-md w-full max-h-[80vh] flex flex-col overflow-hidden";const head=document.createElement("div");head.className="flex items-center justify-between px-6 pt-5 pb-3";const h3=document.createElement("h3");h3.className="text-base font-bold text-gray-900 dark:text-gray-100 truncate mr-2";h3.textContent=t;const xb=document.createElement("button");xb.className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 text-lg leading-none flex-shrink-0";xb.textContent="✕";head.appendChild(h3);head.appendChild(xb);const bd=document.createElement("div");bd.className="px-6 pb-4 overflow-y-auto text-sm text-gray-700 dark:text-gray-300 whitespace-pre-wrap";bd.textContent=b;card.appendChild(head);card.appendChild(bd);const foot=document.createElement("div");foot.className="px-6 py-4 bg-gray-50 dark:bg-gray-700/50 flex items-center justify-end gap-2";const kb=document.createElement("button");kb.className="px-3 py-1.5 rounded-lg text-xs font-medium text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-600";kb.textContent="我知道了";foot.appendChild(kb);if(l){const la=document.createElement("a");la.href=l;la.target="_blank";la.rel="noopener";la.className="px-3 py-1.5 rounded-lg text-xs font-medium text-purple-600 dark:text-purple-400 hover:bg-purple-500/10";la.textContent="查看详情 →";foot.insertBefore(la,kb)}card.appendChild(foot);const close=()=>{if(ov&&ov.parentNode)ov.parentNode.removeChild(ov)};xb.onclick=close;kb.onclick=close;ov.onclick=(ev)=>{if(ev.target===ov)close()};ov.appendChild(card);document.body.appendChild(ov)}', + 'function HubBell(){(0,u.useEffect)(()=>{const T=setTimeout(()=>{fetch("/api/license-config",{cache:"no-store"}).then(r=>r.json()).then(j=>{try{const a=j&&j.data&&j.data.announcement;if(!a)return;const seen=JSON.parse(localStorage.getItem("hub_seen")||"{}");if(!seen["a"+a.id]){const d=document.querySelector(".mv-bell-dot");if(d)d.style.display="block"}}catch(e){}}).catch(()=>{})},1500);return()=>{clearTimeout(T)}},[]);return(0,a.jsxs)("button",{onClick:()=>{fetch("/api/license-config",{cache:"no-store"}).then(r=>r.json()).then(j=>{const a=j&&j.data&&j.data.announcement;mvModal(a?String(a.title||"📢 公告"):"通知",a?String(a.content||""):"暂无新公告",a?String(a.link_url||""):"")}).catch(()=>{})},title:"公告通知",className:"relative hidden md:flex items-center justify-center w-8 h-8 rounded-lg text-base text-gray-500 hover:text-purple-600 hover:bg-purple-500/10 dark:text-gray-400 dark:hover:text-purple-400 transition-colors duration-200",children:[(0,a.jsx)("span",{className:"leading-none",children:"🔔"}),(0,a.jsx)("span",{className:"mv-bell-dot absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full",style:{display:"none"}})]})}', '' ].join("\n"); - // 3a) 先剥离旧注入(修 bug 后可整块重打,幂等) + // 3a) 剥离旧注入(v36 门控三件套 / v34-35 裸徽章+锚点 / 组件定义)——幂等重打 const anchorI = "let I=()=>{let e=(0,x.useRouter)()"; const anchorOpen = '(0,a.jsx)("a",{href:"https://github.com/katelya77/KatelyaTV"'; + const gateOpen = '"'+String.fromCharCode(47)+'"===(e.activePath||"/")&&(0,a.jsxs)("span",{className:"hidden md:flex items-center gap-1.5"'; + const gateEnd = 'children:"'+String.fromCharCode(11088)+' 开源地址"})]})'; + let gi = s.indexOf(gateOpen); + while (gi >= 0) { + const ge = s.indexOf(gateEnd, gi); + if (ge < 0) { failures.push("gated strip end missing"); return; } + let st = gi; + while (st > 0 && s[st - 1] === ",") st--; + s = s.slice(0, st) + "," + s.slice(ge + gateEnd.length); + log("chunk: stripped gated trio"); + gi = s.indexOf(gateOpen); + } + const bs = s.indexOf('(0,a.jsx)("span",{className:"hidden lg:inline-flex'); + if (bs >= 0) { + const ao = s.indexOf(anchorOpen, bs); + if (ao < 0) { failures.push("legacy badge strip: anchor missing"); return; } + s = s.slice(0, bs) + s.slice(ao); + const aend = 'children:"⭐ 开源地址"})'; + const ae = s.indexOf(anchorOpen); + if (ae >= 0) { + const ee = s.indexOf(aend, ae); + if (ee < 0) { failures.push("legacy anchor strip end missing"); return; } + s = s.slice(0, ae) + s.slice(ee + aend.length); + } + log("chunk: stripped legacy badge+anchor"); + } const hi = s.indexOf("function HubNotice(){"); if (hi >= 0) { const ai = s.indexOf(anchorI, hi); if (ai < 0) { failures.push("reinject: anchorI missing after HubNotice"); return; } s = s.slice(0, hi) + s.slice(ai); - log("chunk: stripped old HubNotice"); + log("chunk: stripped old defs"); } - const bs = s.indexOf('(0,a.jsx)("span",{className:"hidden lg:inline-flex'); - if (bs >= 0) { - const ao = s.indexOf(anchorOpen, bs); - if (ao < 0) { failures.push("reinject: anchorOpen missing after badge"); return; } - s = s.slice(0, bs) + s.slice(ao); - log("chunk: stripped old badge"); - } - // 3b) 组件定义放在 let I=()=>{ 前(模块作用域,u/a 绑定可用),角标+弹窗渲染在开源地址按钮前 + // 3b) 组件定义放模块作用域(u/a 可用);门控三件套注入 nav O(var _ 前最后一个 p.T,I 组合 = 桌面导航) if (!s.includes(anchorI)) { failures.push("chunk anchor I missing"); return; } s = s.replace(anchorI, comp + "\n" + anchorI); - const badge = '(0,a.jsx)("span",{className:"hidden lg:inline-flex items-center select-none rounded-lg px-2 py-1.5 text-xs font-bold tracking-wide text-purple-600 dark:text-purple-400 bg-purple-500/10 border border-purple-500/20",title:"米视TV 当前版本",children:"v' + VERSION + '"}),(0,a.jsx)(HubNotice,{}),'; - s = s.replace(anchorOpen, badge + anchorOpen); + const combo = '(0,a.jsx)(p.T,{}),(0,a.jsx)(I,{})'; + const oi = s.indexOf("var _="); + const ci = oi >= 0 ? s.lastIndexOf(combo, oi) : -1; + if (ci < 0) { failures.push("nav combo anchor missing"); return; } + const gated = '"/"===(e.activePath||"/")&&(0,a.jsxs)("span",{className:"hidden md:flex items-center gap-1.5",children:[(0,a.jsx)("span",{className:"hidden lg:inline-flex items-center select-none rounded-lg px-2 py-1.5 text-xs font-bold tracking-wide text-purple-600 dark:text-purple-400 bg-purple-500/10 border border-purple-500/20",title:"米视TV 当前版本",children:"v' + VERSION + '"}),(0,a.jsx)(HubBell,{}),(0,a.jsx)(HubNotice,{}),(0,a.jsx)("a",{href:"https://github.com/katelya77/KatelyaTV",target:"_blank",rel:"noopener",className:"hidden lg:flex items-center rounded-lg px-3 py-2 text-sm font-medium text-gray-700 hover:bg-purple-100/30 hover:text-purple-600 dark:text-gray-300 dark:hover:bg-purple-500/10 transition-colors duration-200",children:"⭐ 开源地址"})]}),'; + s = s.slice(0, ci) + gated + s.slice(ci); + log("chunk: injected gated trio (home only)"); writeChecked(target, s); })(); +// ---------- 5) live 页移除开源地址按钮(只留 TVBOX 接入) ---------- +(function () { + const p = "/app/.next/server/app/api/tvbox/route.js"; + let s = FS.readFileSync(p, "utf8"); + const gh = '⭐ 开源地址'; + if (s.indexOf(gh) < 0) { log("tvbox: live ghLink absent (skip)"); return; } + s = s.split(gh).join(""); + writeChecked(p, s); + log("tvbox: live page ghLink removed"); +})(); + // ---------- 4) tvbox 配置:notice/version/update_url ---------- (function () { const p = "/app/.next/server/app/api/tvbox/route.js";