كود سكريبت
export default {
async fetch(request) {
const url = new URL(request.url);
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;
// **هنا نقوم بإرجاع رابط proxy/segment كما قبل**
// لكن لاحقًا سنقوم بإعادة التوجيه 301 بدلاً من جلب المحتوى
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 → إعادة توجيه 301
// ============================
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 });
// إعادة توجيه مباشر
return Response.redirect(original, 301);
}
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://www.123tv.fun") &&
!origin.includes("https://www.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://www.123tv.fun",
},
});
},
};
............
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
const target = url.searchParams.get('url')
if (!target) return new Response('No URL provided', { status: 400 })
const resp = await fetch(target, {
method: request.method,
headers: request.headers
})
const newHeaders = new Headers(resp.headers)
newHeaders.set('Access-Control-Allow-Origin', '*')
newHeaders.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
newHeaders.set('Access-Control-Allow-Headers', '*')
return new Response(resp.body, {
status: resp.status,
statusText: resp.statusText,
headers: newHeaders
})
}