-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
239 lines (211 loc) · 7.65 KB
/
index.html
File metadata and controls
239 lines (211 loc) · 7.65 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GitHub .codecanvas Preview</title>
<meta name="description" content="Instantly preview .codecanvas files from any GitHub repository. CodeCanvas Preview renders interactive visual project documentation in your browser, no download required.">
<meta name="keywords" content="codecanvas, github preview, visual documentation, project visualization, interactive code, open source, github pages">
<meta property="og:title" content="GitHub .codecanvas Preview">
<meta property="og:description" content="Preview .codecanvas files directly from GitHub repositories. Interactive visual documentation for code projects.">
<meta property="og:image" content="https://opengraph.githubassets.com/d14a5989440d943d4225ea26c30c3c1437ddbdb3b29232bc1e4b0bdcd6f62b61/codecanvaspreview/codecanvaspreview.github.com">
<meta property="og:url" content="https://codecanvaspreview.github.io">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="GitHub .codecanvas Preview">
<meta name="twitter:description" content="Render .codecanvas files from GitHub in your browser. Visual project documentation made interactive.">
<meta name="twitter:image" content="https://opengraph.githubassets.com/d14a5989440d943d4225ea26c30c3c1437ddbdb3b29232bc1e4b0bdcd6f62b61/codecanvaspreview/codecanvaspreview.github.com">
<link rel="icon" href="https://cdn.sdappnet.cloud/rtx/images/codecanvas.png" type="image/png">
<style>
body {
font: 12px 'Helvetica Neue', Helvetica, Arial, freesans, clean, sans-serif;
color: #333;
margin: 0;
padding: 0;
height: 100vh;
overflow: hidden;
}
h1 {
font-size: 20px;
}
a {
color: #666;
}
#previewform {
display: none;
padding: 20px;
text-align: center;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
strong {
color: #333;
background-color: #FAFFA6;
padding: 0.1em;
}
#footer {
margin: 20px 0;
font-size: 10px;
color: #666;
}
#preview-container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: none;
width: 100%;
height: 100%;
display: none;
}
.error-message {
color: #ff3b30;
padding: 20px;
text-align: center;
max-width: 600px;
margin: 100px auto;
background: #fff3f3;
border: 1px solid #ffcccb;
border-radius: 8px;
}
.cache-bust-note {
font-size: 11px;
color: #666;
margin-top: 10px;
font-style: italic;
}
</style>
</head>
<body>
<form id="previewform"
onsubmit="location.href=window.location.pathname+'?'+encodeURIComponent(this.file.value);return false">
<h1>GitHub .codecanvas Preview</h1>
<p>
Enter URL of the .codecanvas file to preview:
<input type="url" id="file" value=""
placeholder="e.g. https://cdn.sdappnet.cloud/rtx/code/openjkdf2.codecanvas" size="60" autofocus>
<input type="submit" value="Preview">
</p>
<p>or prepend to the URL:
<code><strong>https://codecanvaspreview.github.io/?</strong>https://cdn.sdappnet.cloud/rtx/code/openjkdf2.codecanvas</code>
</p>
<p class="cache-bust-note">✨ Tip: Add <code>&t=</code> with a timestamp to force refresh:
<code>&t=1700000000000</code>
</p>
<p id="footer">Developed in 2026 | Contribute on <a
href="https://github.com/codecanvaspreview/codecanvaspreview.github.com">GitHub</a></p>
</form>
<!-- Iframe for previewing .codecanvas files -->
<iframe id="preview-container" sandbox="allow-scripts allow-same-origin allow-popups allow-forms"></iframe>
<script>
(function () {
var previewForm = document.getElementById('previewform');
var previewContainer = document.getElementById('preview-container');
// Get the base path for this app
var basePath = window.location.pathname;
// Get URL from query string
var url = location.search.substring(1);
// Check for cache-busting timestamp parameter
var timestampParam = '';
var hasTimestamp = false;
// Extract timestamp if it exists in the format ?url&t=timestamp
if (url.includes('&t=')) {
// Extract the actual URL part (before &t=)
var urlParts = url.split('&t=');
url = urlParts[0];
timestampParam = '&t=' + urlParts[1];
hasTimestamp = true;
} else if (url.includes('?t=')) {
// Handle ?url?t=timestamp format (for direct .codecanvas URLs with timestamp)
var urlParts = url.split('?t=');
url = urlParts[0];
timestampParam = '?t=' + urlParts[1];
hasTimestamp = true;
}
// Handle encoded URLs (if they contain :// they should be encoded)
if (url && !url.includes('://')) {
// Try to decode the URL if it's encoded
try {
var decodedUrl = decodeURIComponent(url);
if (decodedUrl.startsWith('http://') || decodedUrl.startsWith('https://')) {
url = decodedUrl;
}
} catch (e) {
// If decoding fails, keep the original
}
}
// Process the URL - handle both raw URLs and GitHub URLs
if (url) {
// Check if it's a GitHub URL and convert to raw
if (url.includes('github.com') && url.includes('/blob/')) {
url = url.replace(/\/\/github\.com/, '//raw.githubusercontent.com').replace(/\/blob\//, '/');
}
}
var fetchProxy = function (url, options, i) {
var proxy = [
'', // try without proxy first
'https://api.codetabs.com/v1/proxy/?quest='
];
// Add cache-busting parameter to the fetch URL
var fetchUrl = proxy[i] + url;
if (timestampParam) {
// If we already have a timestamp from the main URL, use it
fetchUrl += timestampParam;
} else {
// Otherwise add fresh timestamp to bypass cache
var separator = url.includes('?') ? '&' : '?';
fetchUrl += separator + '_t=' + Date.now();
}
return fetch(fetchUrl, options).then(function (res) {
if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText);
return res.text();
}).catch(function (error) {
if (i === proxy.length - 1)
throw error;
return fetchProxy(url, options, i + 1);
})
};
// Check if we have a valid URL to load
if (url && (url.startsWith('http://') || url.startsWith('https://')) && url.indexOf(window.location.hostname) < 0) {
// Check if this is a .codecanvas file
if (url.toLowerCase().endsWith('.codecanvas')) {
// Show the preview container
previewForm.style.display = 'none';
previewContainer.style.display = 'block';
// Load the .codecanvas file in an iframe
fetchProxy(url, null, 0)
.then(function (htmlContent) {
// Create a blob URL for the content
const blob = new Blob([htmlContent], { type: 'text/html' });
const blobUrl = URL.createObjectURL(blob);
// Load it in the iframe
previewContainer.src = blobUrl;
// Clean up blob URL after loading
previewContainer.onload = function () {
URL.revokeObjectURL(blobUrl);
};
})
.catch(function (error) {
console.error(error);
previewForm.style.display = 'block';
previewForm.innerHTML = '<p class="error-message">Error loading .codecanvas file: ' + error.message + '</p><p><a href="' + basePath + '">Try again</a></p>';
});
} else {
// Not a .codecanvas file, show error
previewForm.style.display = 'block';
previewForm.innerHTML = '<p class="error-message">Only .codecanvas files are supported. Please provide a .codecanvas file URL.</p><p><a href="' + basePath + '">Try again</a></p>';
}
} else {
// Show the form
previewForm.style.display = 'block';
// If there's a URL in the input, pre-fill it
if (url) {
document.getElementById('file').value = url;
}
}
})();
</script>
</body>
</html>