Skip to content

Commit d0ae280

Browse files
author
Vic-Nas
committed
Fixed vicutils display
1 parent f67eef2 commit d0ae280

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

script.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,38 @@ async function renderProblem() {
276276
!f.name.includes('.shortest.')
277277
);
278278

279-
// Check if has HTML - if so, embed it in an iframe
279+
// Check if has HTML - fetch and display it
280280
if (htmlFiles.length > 0) {
281-
const rawUrl = `https://raw.githubusercontent.com/${getRepoPath()}/main/${pathStr}/${htmlFiles[0].name}`;
282-
const problemName = state.currentPath[state.currentPath.length - 1];
283-
const title = problemName.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
284-
const subtitle = state.currentPath.slice(0, -1).map(capitalize).join(' / ');
285-
const githubFileUrl = `https://github.com/${getRepoPath()}/blob/main/${pathStr}/${htmlFiles[0].name}`;
286-
287-
view.innerHTML = `
288-
<div class="problem-header">
289-
<div class="problem-nav">
290-
<button onclick="window.goBack()" class="nav-link nav-button">← Back</button>
291-
<a href="#" class="nav-link">🏠 Home</a>
292-
<a href="${githubFileUrl}" target="_blank" class="nav-link">📂 GitHub File</a>
293-
</div>
294-
<h1 class="problem-title">${title}</h1>
295-
<p class="problem-subtitle">${subtitle}</p>
296-
</div>
297-
<div style="width: 100%; height: calc(100vh - 200px); border: 1px solid #ddd; border-radius: 8px; overflow: hidden;">
298-
<iframe src="${rawUrl}" style="width: 100%; height: 100%; border: none;" sandbox="allow-scripts allow-same-origin"></iframe>
299-
</div>
300-
`;
301-
return;
281+
try {
282+
const res = await fetch(`https://api.github.com/repos/${getRepoPath()}/contents/${pathStr}/${htmlFiles[0].name}`);
283+
if (res.ok) {
284+
const data = await res.json();
285+
const htmlContent = atob(data.content);
286+
287+
const problemName = state.currentPath[state.currentPath.length - 1];
288+
const title = problemName.replace(/-/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
289+
const subtitle = state.currentPath.slice(0, -1).map(capitalize).join(' / ');
290+
const githubFileUrl = `https://github.com/${getRepoPath()}/blob/main/${pathStr}/${htmlFiles[0].name}`;
291+
292+
view.innerHTML = `
293+
<div class="problem-header">
294+
<div class="problem-nav">
295+
<button onclick="window.goBack()" class="nav-link nav-button">← Back</button>
296+
<a href="#" class="nav-link">🏠 Home</a>
297+
<a href="${githubFileUrl}" target="_blank" class="nav-link">📂 GitHub File</a>
298+
</div>
299+
<h1 class="problem-title">${title}</h1>
300+
<p class="problem-subtitle">${subtitle}</p>
301+
</div>
302+
<div style="width: 100%; border: 1px solid #ddd; border-radius: 8px; padding: 2rem; background: white;">
303+
${htmlContent}
304+
</div>
305+
`;
306+
return;
307+
}
308+
} catch (err) {
309+
console.error('Error fetching HTML file:', err);
310+
}
302311
}
303312

304313
// Fetch Python code

0 commit comments

Comments
 (0)