-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
215 lines (194 loc) · 9.82 KB
/
Copy pathindex.html
File metadata and controls
215 lines (194 loc) · 9.82 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>View Source Online Tool - Cek Kode Sumber Website</title>
<meta name="description" content="Alat online untuk melihat, memformat, dan menganalisis kode sumber HTML/CSS/JS dari URL manapun dengan fitur kecepatan & ukuran file.">
<meta name="keywords" content="view source, cek kode sumber, html viewer, kode sumber online, analisa website">
<meta name="author" content="Ferry Ayunda">
<meta name="robots" content="index, follow">
<meta property="og:title" content="View Source Tool Profesional | Cek Sumber Kode">
<meta property="og:description" content="Lihat, format, dan unduh kode sumber HTML/CSS dari website manapun secara instan.">
<meta property="og:url" content="https://lihat-sumber.vercel.app/">
<meta property="og:type" content="website">
<meta property="og:site_name" content="View Source Online">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="View Source Tool Profesional | Cek Sumber Kode">
<meta name="twitter:description" content="Lihat, format, dan unduh kode sumber HTML/CSS dari website manapun secara instan.">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon.png">
<link rel="apple-touch-icon" href="/favicon.png">
<link rel="shortcut icon" href="/favicon.png">
<meta name="theme-color" content="#0d1117">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<style>
body {font-family: Arial, sans-serif; margin: 0; padding: 0; background: #0d1117; color: #e6edf3;}
.container {max-width: 900px; margin: 20px auto; padding: 15px;}
h1 {font-size: 22px; margin-bottom: 10px;}
input, button {padding: 10px; border-radius: 6px; border: none; font-size: 15px;}
input[type=text] {flex: 1; background: #161b22; color: #e6edf3; border: 1px solid #30363d;}
button {background: #238636; color: white; cursor: pointer;}
button:hover {background: #2ea043;}
.controls {display: flex; gap: 8px; margin-bottom: 10px;}
.options {margin-bottom: 15px;}
.code-container {position: relative; margin-bottom: 10px;}
pre {background: #2d2d2d; padding: 15px; border-radius: 6px; overflow-x: auto; margin: 0; min-height: 200px; padding-top: 20px;}
pre code.hljs {padding-left: 10px !important; background: #2d2d2d; font-size: 14px;}
.code-actions {position: absolute; top: 8px; right: 8px; display: none; gap: 5px; z-index: 10;}
.code-actions.active {display: flex;}
.code-actions button {background: #30363d; border: 1px solid #8b949e; color: #c9d1d9; padding: 5px 10px; border-radius: 4px; font-size: 14px; transition: background 0.2s;}
.code-actions button:hover {background: #484f58;}
.code-actions button i {margin-right: 5px;}
label {font-size: 14px; margin-right: 10px;}
#status, footer {font-size: 13px; color: #8b949e; margin-top: 8px; margin-bottom: 10px;}
a:link, a:visited, #status a {color: #2ea043; text-decoration: none;}
#status a:hover {text-decoration: underline;}
.hljs-ln-numbers {text-align: right; color: #8b949e; border-right: 1px solid #8b949e; padding-right: 12px !important; user-select: none;}
.hljs-ln-code {padding-left: 12px !important;}
.love { color: #FF0000; font-size: 13px;}
</style>
</head>
<body onload="initializeAndFetch()">
<div class="container">
<h1>View Source Online</h1>
<div class="controls">
<input type="text" id="urlInput" placeholder="https://example.com" value="https://example.com" />
<button id="viewBtn">View Source</button>
</div>
<div class="options">
<label><input type="checkbox" id="useProxy" checked> Gunakan Proxy Statis</label>
<label><input type="checkbox" id="useLocalProxy"> Gunakan Proxy Lokal</label>
</div>
<div id="status"></div>
<div class="code-container">
<div class="code-actions" id="codeActions">
<button id="copyBtn" onclick="copyCode()"><i class="fas fa-copy"></i> Salin</button>
<button id="downloadBtn" onclick="downloadCode()"><i class="fas fa-download"></i> Unduh</button>
</div>
<pre><code id="codeBlock" class="html"></code></pre>
</div>
<footer>View Source dibuat dengan <i class="fa-solid fa-heart love"></i> oleh <a href="https://bungferry.github.io/">Ferry Ayunda</a>.</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.14.0/beautify-html.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<script>
const urlInput = document.getElementById('urlInput');
const codeBlock = document.getElementById('codeBlock');
const viewBtn = document.getElementById('viewBtn');
const status = document.getElementById('status');
const useProxy = document.getElementById('useProxy');
const useLocalProxy = document.getElementById('useLocalProxy');
const codeActions = document.getElementById('codeActions');
const DEFAULT_URL = 'https://example.com';
const FALLBACK_FETCH_PROXY = 'https://api.allorigins.win/raw?url=';
const LOCAL_PROXY_BASE_URL = 'https://viewsources.vercel.app/api/proxy?url=';
let lastBlobUrl = null;
function isValidUrl(url) {
const urlPattern = /^(https?:\/\/.+)|(www\..+)/i;
return urlPattern.test(url);
}
function normalizeUrl(url) {
let normalized = url.trim();
if (normalized.startsWith('www.') && !normalized.startsWith('http')) {
normalized = 'https://' + normalized;
}
return normalized;
}
function showCodeActions(url) {
if (url.trim() !== DEFAULT_URL) codeActions.classList.add('active');
else codeActions.classList.remove('active');
}
function hideCodeActions() { codeActions.classList.remove('active'); }
function copyCode() {
const codeText = codeBlock.textContent;
navigator.clipboard.writeText(codeText)
.then(() => alert('Kode sumber berhasil disalin!'))
.catch(() => alert('Gagal menyalin kode.'));
}
function downloadCode() {
const codeText = codeBlock.textContent;
const url = urlInput.value.trim();
let fileName = 'source.html';
try {
const urlObj = new URL(url);
fileName = urlObj.hostname + '.html';
} catch {}
const blob = new Blob([codeText], { type: 'text/html' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = fileName;
link.click();
}
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
async function fetchSource(url) {
codeBlock.textContent = '';
hideCodeActions();
if (lastBlobUrl) { URL.revokeObjectURL(lastBlobUrl); lastBlobUrl = null; }
let finalFetchUrl = url;
let usedProxyInfo = 'langsung';
if (useProxy.checked) {
finalFetchUrl = FALLBACK_FETCH_PROXY + encodeURIComponent(url);
usedProxyInfo = 'proxy allorigins.win';
} else if (useLocalProxy.checked) {
finalFetchUrl = LOCAL_PROXY_BASE_URL + encodeURIComponent(url);
usedProxyInfo = 'proxy lokal';
}
const startTime = performance.now();
try {
status.textContent = `Mengambil kode sumber dari ${url} (${usedProxyInfo})...`;
const res = await fetch(finalFetchUrl);
const endTime = performance.now();
const duration = ((endTime - startTime) / 1000).toFixed(6);
if (!res.ok) throw new Error(`Gagal memuat kode: ${res.status} ${res.statusText}`);
const html = await res.text();
const encoder = new TextEncoder();
const byteLength = encoder.encode(html).length;
const formattedSize = formatBytes(byteLength);
const formattedHtml = html_beautify(html, { indent_size: 2, space_in_empty_paren: true, end_with_newline: true });
codeBlock.textContent = formattedHtml;
hljs.highlightElement(codeBlock);
hljs.lineNumbersBlock(codeBlock);
showCodeActions(url);
const blob = new Blob([html], { type: "text/html" });
lastBlobUrl = URL.createObjectURL(blob);
status.innerHTML = `Fetched ${formattedSize} in ${duration}s dari ${usedProxyInfo} <br> Lihat Preview: <a href="${lastBlobUrl}" target="_blank">${url}</a>`;
} catch (err) {
status.textContent = `Error: ${err.message}`;
codeBlock.textContent = 'Gagal memuat konten.';
}
}
function initializeAndFetch() {
// Normalisasi URL sebelum fetching pertama
const initialUrl = normalizeUrl(urlInput.value.trim());
urlInput.value = initialUrl;
fetchSource(initialUrl);
}
viewBtn.addEventListener('click', () => {
let url = urlInput.value.trim();
if (!url) {
status.textContent = 'Masukkan URL valid.';
return;
}
if (!isValidUrl(url)) {
status.textContent = 'URL tidak valid! Harus diawali dengan http://, https://, atau www.';
codeBlock.textContent = '';
hideCodeActions();
return;
}
url = normalizeUrl(url);
urlInput.value = url;
fetchSource(url);
});
</script>
</body>
</html>