-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.html
More file actions
266 lines (241 loc) · 13.3 KB
/
Copy pathsolution.html
File metadata and controls
266 lines (241 loc) · 13.3 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Code Viewer - CP Archive</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&family=JetBrains+Mono:wght@500;700&display=swap" rel="stylesheet">
<link id="prism-theme" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/app.css">
<script src="assets/app.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
</head>
<body>
<div class="page-shell">
<header class="site-header">
<div class="container header-inner">
<button class="brand brand-button" type="button" onclick="window.history.back()" aria-label="Back to previous page">
<span class="brand-mark" aria-hidden="true">
<svg width="25" height="25" viewBox="0 0 24 24" fill="none">
<path d="M19 12H5M11 6l-6 6 6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
<span class="brand-copy">
<span class="brand-title" id="header-title">Loading solution</span>
<span class="brand-subtitle">Code viewer</span>
</span>
</button>
<div class="header-actions">
<a class="text-button hide-mobile" href="index.html">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M3 10.5 12 3l9 7.5V21h-6v-6H9v6H3V10.5Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
</svg>
Home
</a>
<button class="icon-button theme-toggle" type="button" data-theme-toggle aria-label="Toggle light and dark mode">
<svg class="sun-icon" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12 3v2M12 19v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M3 12h2M19 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42M16.5 12a4.5 4.5 0 1 1-9 0 4.5 4.5 0 0 1 9 0Z" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<svg class="moon-icon" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M21 14.5A8.5 8.5 0 0 1 9.5 3 7 7 0 1 0 21 14.5Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
</div>
</div>
</header>
<main class="page-main">
<div class="container">
<section class="page-heading">
<div>
<p class="eyebrow">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M16 18 22 12 16 6M8 6 2 12l6 6M14 4l-4 16" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Source archive
</p>
<h1 class="compact-title" id="problem-title">Loading problem</h1>
</div>
<div class="toolbar" id="solution-toolbar" style="display: flex; gap: 10px; align-items: center;">
<button class="text-button toggle-sidebar-btn" type="button" aria-label="Toggle notes sidebar">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" style="stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; width: 16px; height: 16px;">
<path d="M15 19l-7-7 7-7"/>
</svg>
Toggle Notes
</button>
</div>
</section>
<section class="solution-layout">
<aside class="solution-card">
<div class="card-header">
<h2 class="card-title">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M12 17h.01M12 13a3 3 0 1 0-3-3M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
Problem notes
</h2>
</div>
<div id="readme-content" class="problem-info markdown-body custom-scrollbar">
<div class="loading-state">Loading README...</div>
</div>
</aside>
<section class="solution-card code-window">
<div class="card-header">
<div class="window-dots" aria-hidden="true">
<span></span>
<span></span>
<span></span>
</div>
<span class="filename" id="filename-display">solution.cpp</span>
<button class="text-button" type="button" onclick="copyCode()" aria-label="Copy solution code">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M8 8V6a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2M6 8h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"/>
</svg>
<span id="copy-label">Copy</span>
</button>
</div>
<div class="code-body custom-scrollbar">
<pre><code id="code-content" class="language-cpp">Loading solution...</code></pre>
</div>
</section>
</section>
</div>
</main>
<footer class="site-footer">
<div class="container footer-inner">
<span><strong>CP Submission Archive</strong> solution view.</span>
<span data-theme-label>Theme</span>
</div>
</footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-c.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-cpp.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-python.min.js"></script>
<script>
const GITHUB_USERNAME = "LIGHTUNCHARGED";
const REPO_NAME = "Competitive-Programming";
const BRANCH = "main";
let rawCode = "";
async function fetchFirst(urls) {
let lastError;
for (const url of urls) {
try {
const response = await fetch(url);
if (response.ok) return response;
lastError = new Error(`${response.status} ${response.statusText}`);
} catch (error) {
lastError = error;
}
}
throw lastError || new Error("No sources available.");
}
document.addEventListener("DOMContentLoaded", async () => {
const urlParams = new URLSearchParams(window.location.search);
const folderPath = urlParams.get("path");
const codeEl = document.getElementById("code-content");
const readmeEl = document.getElementById("readme-content");
const titleEl = document.getElementById("problem-title");
const headerTitleEl = document.getElementById("header-title");
const { escapeHtml, formatProblemName, encodePath } = window.CPArchive;
// Collapsible sidebar logic
const toggleBtn = document.querySelector(".toggle-sidebar-btn");
const layout = document.querySelector(".solution-layout");
if (toggleBtn && layout) {
toggleBtn.addEventListener("click", () => {
layout.classList.toggle("sidebar-collapsed");
const aside = layout.querySelector("aside");
if (layout.classList.contains("sidebar-collapsed")) {
aside.style.display = "none";
layout.style.gridTemplateColumns = "minmax(0, 1fr)";
} else {
aside.style.display = "block";
layout.style.gridTemplateColumns = "minmax(280px, 0.74fr) minmax(0, 1.26fr)";
}
});
}
// Sync Prism style with root site theme
const observer = new MutationObserver(() => updatePrismTheme());
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
function updatePrismTheme() {
const theme = document.documentElement.dataset.theme || "light";
const prismThemeLink = document.getElementById("prism-theme");
if (prismThemeLink) {
if (theme === "dark") {
prismThemeLink.href = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css";
} else {
prismThemeLink.href = "https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css";
}
}
}
updatePrismTheme();
if (!folderPath) {
titleEl.textContent = "Missing problem path";
headerTitleEl.textContent = "Missing path";
codeEl.textContent = "// Error: No problem path provided in the URL.";
readmeEl.innerHTML = `<div class="error-state">No problem path was provided.</div>`;
return;
}
const folderName = formatProblemName(folderPath.split("/").pop());
const encodedPath = encodePath(folderPath);
const rawBaseUrl = `https://raw.githubusercontent.com/${GITHUB_USERNAME}/${REPO_NAME}/${BRANCH}/${encodedPath}`;
titleEl.textContent = folderName;
headerTitleEl.textContent = folderName;
try {
const readmeRes = await fetchFirst([
`${encodedPath}/README.md`,
`${rawBaseUrl}/README.md`
]);
const markdown = await readmeRes.text();
readmeEl.innerHTML = window.marked ? marked.parse(markdown) : `<pre>${escapeHtml(markdown)}</pre>`;
} catch (error) {
console.error("Failed to fetch README", error);
readmeEl.innerHTML = `<p class="muted">No README.md was found for this problem.</p>`;
}
try {
const candidates = [
{ filename: "solution.cpp", lang: "cpp" },
{ filename: "solution.py", lang: "python" },
{ filename: "solution.c", lang: "c" }
];
let loaded = null;
for (const candidate of candidates) {
try {
const response = await fetchFirst([
`${encodedPath}/${candidate.filename}`,
`${rawBaseUrl}/${candidate.filename}`
]);
loaded = { ...candidate, source: await response.text() };
break;
} catch (error) {
loaded = null;
}
}
if (!loaded) {
codeEl.textContent = "// Error: Could not find solution.cpp, solution.py, or solution.c in this folder.";
return;
}
rawCode = loaded.source;
codeEl.className = `language-${loaded.lang}`;
codeEl.textContent = rawCode;
document.getElementById("filename-display").textContent = loaded.filename;
if (window.Prism) Prism.highlightElement(codeEl);
} catch (error) {
console.error("Failed to fetch code", error);
codeEl.textContent = "// Error: Failed to load the solution source.";
}
});
function copyCode() {
if (!rawCode) return;
navigator.clipboard.writeText(rawCode).then(() => {
const label = document.getElementById("copy-label");
label.textContent = "Copied";
setTimeout(() => {
label.textContent = "Copy";
}, 1800);
});
}
</script>
</body>
</html>