const bg = "https://i.postimg.cc/Wp5PJbmw/download-(6).jpg";
const PREFIX = "/https/";
const GAME_HOST = "https://gn-math.dev";
const GAME_INDEX = [
{ name: "People Playground", url: "LOCAL:/people-playground" },
{ name: "Run 3", url: "/games/run3" },
{ name: "Drift Hunters", url: "/games/drift-hunters" },
{ name: "Retro Bowl", url: "/games/retro-bowl" },
{ name: "Minecraft Classic", url: "/games/minecraft" },
{ name: "Tunnel Rush", url: "/games/tunnel-rush" },
{ name: "Bitlife", url: "/games/bitlife" },
{ name: "Cookie Clicker", url: "/games/cookie-clicker" }
];
function rewriteHtml(html, target) {
const parsed = new URL(target);
const origin = parsed.origin;
html = html.replace(
/(href|src|action)=["']\/([^"']*)["']/gi,
(match, attr, path) => {
return `${attr}="${PREFIX}${origin}/${path}"`;
}
);
html = html.replace(
/(href|src|action)=["']https?:\/\/([^"']+)["']/gi,
(match, attr, path) => {
return `${attr}="${PREFIX}${path}"`;
}
);
html = html.replace(
/(href|src|action)=["'](?!http|\/|#|data:)([^"']+)["']/gi,
(match, attr, path) => {
return `${attr}="${PREFIX}${origin}/${path}"`;
}
);
html = html.replace(/window\.top/gi, "window");
html = html.replace(/top\.location/gi, "window.location");
return html;
}
const home = `
Snipershot
Ts is so fun to do yet so tedious
SNIPERSHOT :D
Coding type shi
snipershot
Spiderbee if tuff, im tuffer
Nodes
12
Latency
43ms
Status
ONLINE
PROXY
NO GAMES (yet)
SNIPERSHOT
UI
PROXY
NO GAMES (yet)
SNIPERSHOT
UI
🎮 Games
💬 Discord PLEASE JOIN :(
`;
function gamesPage(){
const host = GAME_HOST
.replace("https://","")
.replace("http://","");
return `
Games
🎮 Games
${GAME_INDEX.map(game => `
🎮 ${game.name}
`).join("")}
`;
}
export default {
async fetch(req){
const url = new URL(req.url);
if(url.pathname === "/"){
return new Response(home,{
headers:{
"content-type":"text/html"
}
});
}
if(url.pathname === "/games"){
return new Response(gamesPage(),{
headers:{
"content-type":"text/html"
}
});
}
if(url.pathname === "/people-playground"){
const html = `
People Playground
LOADING...
`;
return new Response(html,{
headers:{
"content-type":"text/html;charset=UTF-8"
}
});
}
if(url.pathname === "/search"){
const q =
url.searchParams.get("q") || "";
return Response.redirect(
new URL(
"/https/https://search.brave.com/search%3Fq%3D" +
encodeURIComponent(q),
req.url
),
302
);
}
if(url.pathname.startsWith("/https/")){
try{
let raw = decodeURIComponent(
url.pathname.replace("/https/","")
);
if(
!raw.startsWith("http://") &&
!raw.startsWith("https://")
){
raw = "https://" + raw;
}
const target =
new URL(raw).toString();
const res = await fetch(target,{
headers:{
"User-Agent":"Mozilla/5.0",
"Accept":
"text/html,application/xhtml+xml",
"Accept-Language":
"en-US,en;q=0.9",
"Cache-Control":
"no-cache"
},
redirect:"follow"
});
const headers =
new Headers(res.headers);
headers.delete("content-security-policy");
headers.delete("x-frame-options");
headers.delete("cross-origin-embedder-policy");
headers.delete("cross-origin-opener-policy");
headers.delete("cross-origin-resource-policy");
headers.delete(
"content-security-policy-report-only"
);
headers.set(
"access-control-allow-origin",
"*"
);
headers.set(
"access-control-allow-headers",
"*"
);
headers.set(
"access-control-expose-headers",
"*"
);
const type =
headers.get("content-type") || "";
if(type.includes("text/html")){
let html =
await res.text();
html =
rewriteHtml(html, target);
return new Response(html,{
status:res.status,
headers
});
}
return new Response(res.body,{
status:res.status,
headers
});
}catch(err){
return new Response(
"Proxy error: " + err.stack,
{
status:500
}
);
}
}
return new Response("404",{
status:404
});
}
};