(function() { // AWS Detection Logic const isAWS = window.location.hostname.includes('cloudfront.net'); // Base URLs for endpoints const primaryBase = 'https://backendapi.rockedu.site'; const secondaryBase = 'https://d3scff8k2pqq6n.cloudfront.net'; // Function to check reachability by testing the actual API endpoint async function checkConnectivity(baseUrl) { try { // Test with a real API call - check if the endpoint works with a simple request const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5000); const response = await fetch(`${baseUrl}/userauth/api.php?action=verifySession&token=test`, { method: 'GET', signal: controller.signal, credentials: 'include' }); clearTimeout(timeoutId); // Check if we got a valid JSON response (even if the token is invalid, // a proper API will return JSON with an error message) const text = await response.text(); // Try to parse as JSON - if it's valid JSON, the API is working try { JSON.parse(text); return true; // API is responding with valid JSON } catch { console.warn(`[AWS] ${baseUrl} returned non-JSON response:`, text.substring(0, 100)); return false; // Not a valid API response } } catch (error) { console.warn(`[AWS] ${baseUrl} connectivity check failed:`, error.message); return false; } } // Selectors for elements to hide const proxySelectors = '#pr0xy-link, .feature-card[data-action="proxy"]'; const allBackendSelectors = [ 'a[href*="edum/index.html"]', '#pr0xy-link', '#ai-chat-link', '#authButtonContainer', 'a[href="login.html"]', '.feature-card[data-url*="edum/index.html"]', '.feature-card[data-action="proxy"]', '.feature-card[data-action="ai-chat"]' ].join(','); // Helper to hide elements persistently function hideElements(selector) { const apply = () => { const elements = document.querySelectorAll(selector); elements.forEach(el => el.style.display = 'none'); }; if (document.body) apply(); else document.addEventListener('DOMContentLoaded', apply); // Observe for dynamic re-additions const observer = new MutationObserver(() => apply()); if (document.body) observer.observe(document.body, { childList: true, subtree: true }); else document.addEventListener('DOMContentLoaded', () => observer.observe(document.body, { childList: true, subtree: true })); } // Helper for the restricted banner function showRestrictedBanner() { if (document.getElementById('aws-restriction-banner')) return; const banner = document.createElement('div'); banner.id = 'aws-restriction-banner'; banner.className = 'fixed top-0 left-0 right-0 bg-red-600 text-white text-center p-2 z-50 font-bold text-sm'; banner.innerHTML = '⚠️ You are on a hyper restricted network. Only Games and Apps are available. You are currently connected to our unblockable AWS Mirror'; if(document.body) { document.body.prepend(banner); document.body.style.marginTop = '40px'; } else { document.addEventListener('DOMContentLoaded', () => { document.body.prepend(banner); document.body.style.marginTop = '40px'; }); } } // Helper for the popup function showPopup(msg) { const modal = document.createElement('div'); modal.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 99999; display: flex; align-items: center; justify-content: center;'; modal.innerHTML = `

Notice

${msg}

`; if(document.body) document.body.appendChild(modal); else document.addEventListener('DOMContentLoaded', () => document.body.appendChild(modal)); } // Helper to inject Ad script function injectAdScript() { const script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://schemecontinuingwinning.com/24/34/c9/2434c97117e15b3356a6f8e03f815b13.js'; // Append to head to ensure it loads if (document.head) document.head.appendChild(script); else document.addEventListener('DOMContentLoaded', () => document.head.appendChild(script)); } if (isAWS) { console.log('[AWS] Detected S3 environment. Initiating connectivity checks...'); injectAdScript(); // 1. Try Primary Backend checkConnectivity(primaryBase) .then((isReachable) => { if (isReachable) { console.log('[AWS] Primary backend reachable.'); // Success: Set overrides to primary window.eduBackendOverride = primaryBase + '/userauth/api.php'; window.eduBackendRoot = primaryBase; // Do NOT hide proxy buttons return; } throw new Error("Primary check failed"); }) .catch(() => { console.warn('[AWS] Primary backend unreachable. Trying secondary (Cloudfront)...'); // 2. Try Secondary Backend (Cloudfront) return checkConnectivity(secondaryBase) .then((isReachable) => { if (isReachable) { console.log('[AWS] Secondary backend connected.'); // Success: Set overrides to secondary window.eduBackendOverride = secondaryBase + '/userauth/api.php'; window.eduBackendRoot = secondaryBase; // Hide Proxy buttons only hideElements(proxySelectors); // Show specific popup showPopup("You are using our anti censorship API endpoint but the proxy is not avalaible, all other services should work tho"); return; } throw new Error("Secondary check failed"); }); }) .catch(() => { console.warn('[AWS] All backends unreachable. Enabling Restricted Mode.'); // 3. Failure: Restricted Mode hideElements(allBackendSelectors); showRestrictedBanner(); }); } })();