File size: 3,643 Bytes
6a2da3c
ddb34b2
22be3f8
 
 
 
 
 
 
 
 
 
ddb34b2
22be3f8
 
 
 
ddb34b2
22be3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a2da3c
22be3f8
6a2da3c
22be3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddb34b2
22be3f8
 
 
 
 
 
 
 
 
 
40296ec
22be3f8
 
40296ec
22be3f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
122
123

document.addEventListener('DOMContentLoaded', () => {
  const browserFrame = document.getElementById('browser-frame');
  
  // Proxy configuration
  let proxyEnabled = false;
  let vpnEnabled = false;
  
  // Update status indicators
  function updateStatus() {
    const proxyStatus = document.querySelector('custom-navbar').shadowRoot.getElementById('proxy-status');
    const vpnStatus = document.querySelector('custom-navbar').shadowRoot.getElementById('vpn-status');
    
    proxyStatus.innerHTML = `
      <i data-feather="shield" class="status-icon"></i>
      <span>Proxy: ${proxyEnabled ? 'On' : 'Off'}</span>
    `;
    
    vpnStatus.innerHTML = `
      <i data-feather="lock" class="status-icon"></i>
      <span>VPN: ${vpnEnabled ? 'On' : 'Off'}</span>
    `;
    
    feather.replace();
  }
  
  // Load URL with error handling
  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 || vpnEnabled) {
        // Use a better proxy solution
        const proxyUrl = `https://api.allorigins.win/get?url=${encodeURIComponent(url)}`;
        
        fetch(proxyUrl)
          .then(response => response.json())
          .then(data => {
            if (data.contents) {
              browserFrame.srcdoc = data.contents;
              proxyEnabled = true;
            } else {
              throw new Error('Proxy request failed');
            }
          })
          .catch(() => {
            // Fallback to direct if proxy fails
            browserFrame.src = url;
            proxyEnabled = false;
          });
      } else {
        browserFrame.src = url;
        proxyEnabled = false;
      }
      
      browserFrame.onload = () => {
        browserFrame.classList.remove('loading');
        updateStatus();
      };
      
      browserFrame.onerror = () => {
        browserFrame.classList.remove('loading');
        browserFrame.srcdoc = `
          <html><body style="color:white;padding:2rem;background:#0F0F0F;">
            <h1 style="color:#FF0000;">Failed to load page</h1>
            <p>Could not load ${url}</p>
            <p>Try enabling proxy/VPN or check your connection</p>
          </body></html>
        `;
        updateStatus();
      };
    } catch (error) {
      browserFrame.classList.remove('loading');
      browserFrame.srcdoc = `
        <html><body style="color:white;padding:2rem;background:#0F0F0F;">
          <h1 style="color:#FF0000;">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 navigation from tabs component
  document.addEventListener('navigate', (e) => {
    const { url, useProxy } = e.detail;
    loadUrl(url, useProxy);
  });
  
  // Handle toggle VPN
  document.addEventListener('click', (e) => {
    if (e.target.closest('#toggle-vpn')) {
      vpnEnabled = !vpnEnabled;
      updateStatus();
    }
  });
  
  // Handle clear data
  document.addEventListener('click', (e) => {
    if (e.target.closest('#clear-data')) {
      if (confirm('Clear all browsing data (cookies, cache, etc.)?')) {
        browserFrame.src = 'about:blank';
        setTimeout(() => {
          loadUrl('https://www.google.com');
        }, 500);
      }
    }
  });
  
  // Initialize
  loadUrl('https://www.google.com');
  updateStatus();
  feather.replace();
});