UNPKG

ignitetnt

Version:

IGNITE OS — Advanced proxy-enabled gaming platform with comprehensive filter bypass system

231 lines (196 loc) • 6.79 kB
// Service Worker for Ignite OS Proxy System // Intercepts network requests and routes them through proxy servers to bypass filters const CACHE_NAME = 'ignite-proxy-v1'; const PROXY_ENDPOINTS = [ 'https://proxy1.ignite-os.workers.dev', 'https://proxy2.ignite-os.vercel.app/api/proxy', 'https://proxy3.ignite-os.netlify.app/.netlify/functions/proxy', 'https://cors-anywhere.herokuapp.com', 'https://api.allorigins.win/raw?url=', 'https://thingproxy.freeboard.io/fetch/' ]; // URLs that should be proxied const PROXY_DOMAINS = [ 'gms.parcoil.com', 'drive.google.com', 'docs.google.com', 'githubusercontent.com' ]; // Base64 encode with URL-safe characters function encodeUrl(url) { return btoa(url) .replace(/\+/g, '-') .replace(/\//g, '_') .replace(/=/g, ''); } // Base64 decode with URL-safe characters function decodeUrl(encoded) { // Add padding if needed while (encoded.length % 4) { encoded += '='; } return atob(encoded.replace(/-/g, '+').replace(/_/g, '/')); } // Check if URL should be proxied function shouldProxy(url) { try { const urlObj = new URL(url); return PROXY_DOMAINS.some(domain => urlObj.hostname.includes(domain) || urlObj.hostname.endsWith(domain) ); } catch { return false; } } // Get working proxy endpoint async function getWorkingProxy() { const storedProxy = localStorage.getItem('workingProxy'); const lastCheck = localStorage.getItem('proxyLastCheck'); const now = Date.now(); // Use cached proxy if checked within last 5 minutes if (storedProxy && lastCheck && (now - parseInt(lastCheck)) < 300000) { return storedProxy; } // Test proxy endpoints for (const proxy of PROXY_ENDPOINTS) { try { const testUrl = proxy.includes('?url=') ? `${proxy}https://httpbin.org/status/200` : `${proxy}?url=${encodeURIComponent('https://httpbin.org/status/200')}`; const response = await fetch(testUrl, { method: 'HEAD', signal: AbortSignal.timeout(3000) }); if (response.ok) { localStorage.setItem('workingProxy', proxy); localStorage.setItem('proxyLastCheck', now.toString()); return proxy; } } catch (error) { console.warn(`Proxy ${proxy} failed:`, error); continue; } } // Fallback to first endpoint if none work return PROXY_ENDPOINTS[0]; } // Create proxy URL async function createProxyUrl(originalUrl) { const proxy = await getWorkingProxy(); const encodedUrl = encodeUrl(originalUrl); if (proxy.includes('?url=')) { return `${proxy}${encodeURIComponent(originalUrl)}`; } else if (proxy.includes('allorigins.win')) { return `${proxy}${encodeURIComponent(originalUrl)}`; } else if (proxy.includes('thingproxy.freeboard.io')) { return `${proxy}${encodeURIComponent(originalUrl)}`; } else { return `${proxy}?target=${encodedUrl}&origin=${encodeURIComponent(location.origin)}`; } } // Handle fetch events self.addEventListener('fetch', event => { const url = event.request.url; // Skip non-HTTP requests and same-origin requests if (!url.startsWith('http') || url.startsWith(self.location.origin)) { return; } if (shouldProxy(url)) { event.respondWith(handleProxyRequest(event.request)); } }); // Handle proxy request async function handleProxyRequest(request) { const originalUrl = request.url; try { // Try cache first const cache = await caches.open(CACHE_NAME); const cachedResponse = await cache.match(request); if (cachedResponse && (Date.now() - new Date(cachedResponse.headers.get('date')).getTime()) < 300000) { return cachedResponse; } // Create proxy request const proxyUrl = await createProxyUrl(originalUrl); const proxyRequest = new Request(proxyUrl, { method: request.method, headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'Accept': request.headers.get('accept') || '*/*', 'Accept-Language': 'en-US,en;q=0.9', 'Referer': 'https://www.google.com/', 'Origin': 'https://www.google.com' } }); // Add request body for POST requests if (request.method !== 'GET' && request.method !== 'HEAD') { proxyRequest.body = await request.blob(); } const response = await fetch(proxyRequest); if (!response.ok) { throw new Error(`Proxy failed with status ${response.status}`); } // Create new response with CORS headers const responseHeaders = new Headers(response.headers); responseHeaders.set('Access-Control-Allow-Origin', '*'); responseHeaders.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); responseHeaders.set('Access-Control-Allow-Headers', '*'); responseHeaders.delete('x-frame-options'); responseHeaders.delete('content-security-policy'); const newResponse = new Response(response.body, { status: response.status, statusText: response.statusText, headers: responseHeaders }); // Cache successful responses if (response.status === 200 && request.method === 'GET') { cache.put(request, newResponse.clone()); } return newResponse; } catch (error) { console.error('Proxy request failed:', error); // Try direct request as fallback try { return await fetch(request); } catch (directError) { return new Response('Proxy service unavailable', { status: 503, headers: { 'Content-Type': 'text/plain' } }); } } } // Handle service worker installation self.addEventListener('install', event => { console.log('Ignite OS Proxy Service Worker installed'); self.skipWaiting(); }); // Handle service worker activation self.addEventListener('activate', event => { console.log('Ignite OS Proxy Service Worker activated'); event.waitUntil( caches.keys().then(cacheNames => { return Promise.all( cacheNames.filter(cacheName => cacheName.startsWith('ignite-') && cacheName !== CACHE_NAME ).map(cacheName => caches.delete(cacheName)) ); }) ); return self.clients.claim(); }); // Handle messages from main thread self.addEventListener('message', event => { if (event.data && event.data.type === 'SKIP_WAITING') { self.skipWaiting(); } if (event.data && event.data.type === 'TEST_PROXY') { getWorkingProxy().then(proxy => { event.ports[0].postMessage({ proxy }); }); } if (event.data && event.data.type === 'CLEAR_CACHE') { caches.delete(CACHE_NAME).then(() => { event.ports[0].postMessage({ success: true }); }); } });