Spaces:
Running
Running
File size: 4,826 Bytes
6a2da3c ddb34b2 6a2da3c ddb34b2 6a2da3c ddb34b2 6a2da3c ddb34b2 6a2da3c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
document.addEventListener('DOMContentLoaded', () => {
const browserFrame = document.getElementById('browser-frame');
const proxyForm = document.querySelector('custom-proxy-form');
// Default page to load
loadUrl('https://www.google.com');
// Handle URL loading
function loadUrl(url, useProxy = false) {
try {
browserFrame.classList.add('loading');
// Validate URL
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = 'https://' + url;
}
// Create new URL object to validate
new URL(url);
if (useProxy) {
// Use a reliable proxy service (cors-anywhere requires activation)
const proxyUrl = `https://api.allorigins.win/get?url=${encodeURIComponent(url)}`;
fetch(proxyUrl)
.then(response => response.json())
.then(data => {
const proxyDocument = browserFrame.contentDocument || browserFrame.contentWindow.document;
proxyDocument.open();
proxyDocument.write(data.contents);
proxyDocument.close();
document.querySelector('.proxy-indicator').classList.remove('hidden');
})
.catch(error => {
console.error('Proxy error:', error);
browserFrame.src = url; // Fallback to direct load
document.querySelector('.proxy-indicator').classList.add('hidden');
});
} else {
browserFrame.src = url;
document.querySelector('.proxy-indicator').classList.add('hidden');
}
// Remove loading class when page is loaded
browserFrame.onload = () => {
browserFrame.classList.remove('loading');
};
browserFrame.onerror = () => {
browserFrame.classList.remove('loading');
browserFrame.srcdoc = `
<html><body style="color:white;padding:2rem;">
<h1>Failed to load page</h1>
<p>Could not load ${url}</p>
<p>Try enabling proxy or check your connection</p>
</body></html>
`;
};
} catch (error) {
console.error('URL loading error:', error);
browserFrame.classList.remove('loading');
browserFrame.srcdoc = `
<html><body style="color:white;padding:2rem;">
<h1>Invalid URL</h1>
<p>${url} is not a valid web address</p>
<p>Please enter a complete URL like "https://example.com"</p>
</body></html>
`;
}
}
// Handle proxy form submission
proxyForm.addEventListener('proxy-submit', (e) => {
const { url, useProxy } = e.detail;
loadUrl(url, useProxy);
});
// Handle quick link clicks
document.addEventListener('quick-link-click', (e) => {
loadUrl(e.detail.url, e.detail.useProxy);
});
// VPN toggle functionality
const toggleVpnButtons = document.querySelectorAll('#toggle-vpn');
let vpnActive = false;
toggleVpnButtons.forEach(button => {
button.addEventListener('click', () => {
vpnActive = !vpnActive;
const indicator = document.querySelector('.proxy-indicator');
if (vpnActive) {
indicator.classList.remove('hidden');
indicator.innerHTML = `<i data-feather="shield" class="proxy-icon"></i> VPN Active`;
feather.replace();
} else {
indicator.classList.add('hidden');
}
});
});
// Clear data functionality
const clearDataButtons = document.querySelectorAll('#clear-data');
clearDataButtons.forEach(button => {
button.addEventListener('click', () => {
try {
// Attempt to clear browser data
if (confirm('Clear all browsing data (cookies, cache, etc.)?')) {
const browserFrame = document.getElementById('browser-frame');
browserFrame.src = 'about:blank';
setTimeout(() => {
loadUrl('https://www.google.com');
alert('Browser data cleared!');
}, 500);
}
} catch (e) {
alert('Could not clear data due to browser restrictions');
}
});
});
// Initialize feather icons
feather.replace();
});
|