كود سكريبت كود سكريبت

كود سكريبت

export default { async fetch(request) { const url = new URL(request.url); // ============================ // 🔒 حماية: السماح لموقع 123tv.fun فقط // ============================ const referer = request.headers.get("Referer") || ""; const origin = request.headers.get("Origin") || ""; const allowedDomain = "123tv.fun"; // إذا الطلب ليس من موقعك → بلوك if ( !referer.includes(allowedDomain) && !origin.includes(allowedDomain) ) { return new Response("Access Denied", { status: 403 }); } // ============================ // 1) طلب ملف m3u8 // ============================ if (url.pathname === "/proxy") { const target = url.searchParams.get("url"); if (!target) return new Response("Missing url parameter", { status: 400 }); const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"; const res = await fetch(target, { headers: { "User-Agent": ua }}); let text = await res.text(); const base = target.substring(0, target.lastIndexOf("/") + 1); // إنشاء الخريطة let map = {}; text = text.split("\n").map(line => { if (line.startsWith("#") || line.trim() === "" || line.includes("m3u8")) return line; let fullUrl = line; if (!line.startsWith("http")) fullUrl = base + line; const segNum = fullUrl.split("/").pop().split("?")[0]; map[segNum] = fullUrl; return `/proxy/${segNum}`; }).join("\n"); // تخزين الخريطة const cache = caches.default; const cacheKey = new Request("https://dummy/segment_map"); await cache.put(cacheKey, new Response(JSON.stringify(map))); return new Response(text, { headers: { "Content-Type": "application/vnd.apple.mpegurl", "Access-Control-Allow-Origin": "*" } }); } // ============================ // 2) طلب قطعة TS // ============================ if (url.pathname.startsWith("/proxy/")) { const segNum = url.pathname.split("/").pop(); const cache = caches.default; const cacheKey = new Request("https://dummy/segment_map"); const cached = await cache.match(cacheKey); if (!cached) return new Response("No segment map found", { status: 500 }); const map = await cached.json(); const original = map[segNum]; if (!original) return new Response("Segment not found", { status: 404 }); const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"; const res = await fetch(original, { headers: { "User-Agent": ua } }); return new Response(res.body, { headers: { "Content-Type": "video/MP2T", "Access-Control-Allow-Origin": "*" } }); } return new Response("Not Found", { status: 404 }); } }; ............ export default { async fetch(request) { const referer = request.headers.get("Referer") || ""; const origin = request.headers.get("Origin") || ""; // ❌ منع أي موقع آخر if ( !referer.includes("https://123tv.fun") && !origin.includes("https://123tv.fun") ) { return new Response("Access Denied", { status: 403 }); } const url = new URL(request.url); const target = url.searchParams.get("url"); if (!target) { return new Response("Missing url parameter", { status: 400 }); } const ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"; // جلب الملف الأصلي const res = await fetch(target, { headers: { "User-Agent": ua }, }); let text = await res.text(); const base = target.substring(0, target.lastIndexOf("/") + 1); // تعديل النص text = text .split("\n") .map((line) => { if (line.startsWith("#EXT-X-VERSION")) { return "#EXT-X-VERSION:6"; } if (line.startsWith("#") || line.trim() === "" || line.includes("m3u8")) { return line; } let fullUrl = line.startsWith("http") ? line : base + line; return "https://api.codetabs.com/v1/proxy/?quest=" + fullUrl; }) .join("\n"); return new Response(text, { headers: { "Content-Type": "application/vnd.apple.mpegurl", "Access-Control-Allow-Origin": "https://123tv.fun", }, }); }, };