-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
108 lines (94 loc) · 3.24 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<style>
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#url-input {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 400px;
height: 40px;
padding: 10px;
font-size: 16px;
border: none;
border-radius: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
background-color: #f8f8f8;
color: #333;
outline: none;
transition: box-shadow 0.3s ease;
}
#url-input:focus {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}
#web-view {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<input type="text" id="url-input" placeholder="Enter URL" autofocus>
<iframe id="web-view"></iframe>
<script>
const urlInput = document.getElementById('url-input');
const webView = document.getElementById('web-view');
// Set default language to English
webView.setAttribute('lang', 'en');
const loadWebsite = () => {
const url = urlInput.value;
const proxyUrl = 'https://api.codetabs.com/v1/proxy/?quest=' + url;
// Make an HTTP request through the proxy to fetch the website content
fetch(proxyUrl)
.then(response => response.text())
.then(content => {
// Set the iframe source to display the fetched website content
webView.srcdoc = content;
// Reset the input field
urlInput.value = url;
})
.catch(error => {
console.error('Error fetching website:', error);
});
};
const handleInputKeyPress = event => {
if (event.key === 'Enter') {
loadWebsite();
}
};
urlInput.addEventListener('keypress', handleInputKeyPress);
// Listen for click events on links within the iframe
webView.addEventListener('load', () => {
const links = webView.contentWindow.document.getElementsByTagName('a');
for (let i = 0; i < links.length; i++) {
links[i].addEventListener('click', e => {
e.preventDefault();
const clickedUrl = links[i].getAttribute('href');
const currentUrl = urlInput.value;
let finalUrl = '';
if (clickedUrl.startsWith('http://') || clickedUrl.startsWith('https://')) {
finalUrl = clickedUrl;
} else {
const currentUrlObj = new URL(currentUrl);
finalUrl = currentUrlObj.origin + clickedUrl;
}
urlInput.value = finalUrl;
loadWebsite();
});
}
});
// Initial load
loadWebsite();
</script>
</body>
</html>