Skip to content

Commit a8e938e

Browse files
authored
Merge pull request #5 from efrat-dev/branch1
Branch1
2 parents af8abac + 1bff724 commit a8e938e

File tree

3 files changed

+244
-145
lines changed

3 files changed

+244
-145
lines changed

docs/index.html

Lines changed: 25 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,28 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
<head>
4-
<meta charset="UTF-8" />
5-
<title>LeetCode Solutions – efrat-dev</title>
6-
<style>
7-
body {
8-
font-family: sans-serif;
9-
margin: 0;
10-
padding: 1rem;
11-
background: #f7f7f7;
12-
}
13-
h1, h2 {
14-
text-align: center;
15-
}
16-
#container {
17-
display: flex;
18-
flex-wrap: wrap;
19-
justify-content: center;
20-
gap: 1rem;
21-
}
22-
.card {
23-
background: white;
24-
border-radius: 10px;
25-
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
26-
padding: 1rem;
27-
width: 200px;
28-
text-align: center;
29-
cursor: pointer;
30-
transition: transform 0.2s;
31-
}
32-
.card:hover {
33-
transform: scale(1.05);
34-
}
35-
#backBtn {
36-
display: none;
37-
margin-bottom: 1rem;
38-
cursor: pointer;
39-
background: #ddd;
40-
border: none;
41-
padding: 0.5rem 1rem;
42-
border-radius: 5px;
43-
}
44-
pre {
45-
background: #1e1e1e;
46-
color: #dcdcdc;
47-
padding: 1rem;
48-
border-radius: 8px;
49-
overflow-x: auto;
50-
white-space: pre-wrap;
51-
}
52-
</style>
53-
<!-- Highlight.js -->
54-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
55-
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
56-
<script>hljs.highlightAll();</script>
57-
</head>
58-
<body>
59-
<h1>LeetCode Solutions</h1>
60-
<h2 id="pathTitle">Click to view solutions</h2>
61-
<button id="backBtn">⬅ Back</button>
62-
<div id="container"></div>
63-
<div id="codeViewer"></div>
64-
65-
<script>
66-
const owner = "efrat-dev";
67-
const repo = "algo-ds-leetcode";
68-
const branch = "main";
69-
const baseUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/`;
70-
71-
let fullTree = {};
72-
let history = [];
73-
74-
fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`)
75-
.then(res => res.json())
76-
.then(data => {
77-
const files = data.tree.filter(item => item.type === "blob" && item.path.endsWith(".cs"));
78-
fullTree = buildTree(files.map(f => f.path));
79-
renderLevel(fullTree, "Click to view solutions");
80-
});
81-
82-
function buildTree(paths) {
83-
const root = {};
84-
for (const path of paths) {
85-
const parts = path.split("/");
86-
let curr = root;
87-
for (let i = 0; i < parts.length; i++) {
88-
const part = parts[i];
89-
if (!curr[part]) {
90-
curr[part] = (i === parts.length - 1) ? path : {};
91-
}
92-
curr = curr[part];
93-
}
94-
}
95-
return root;
96-
}
97-
98-
function renderLevel(level, title) {
99-
const container = document.getElementById("container");
100-
container.innerHTML = "";
101-
document.getElementById("codeViewer").innerHTML = "";
102-
document.getElementById("pathTitle").innerText = title;
103-
document.getElementById("backBtn").style.display = history.length ? "inline-block" : "none";
104-
105-
for (const key in level) {
106-
const card = document.createElement("div");
107-
card.className = "card";
108-
card.innerText = key.replace(/\.cs$/, "");
109-
card.onclick = () => {
110-
if (typeof level[key] === "string") {
111-
loadFile(level[key]);
112-
} else {
113-
history.push({ level, title });
114-
renderLevel(level[key], key);
115-
}
116-
};
117-
container.appendChild(card);
118-
}
119-
}
120-
121-
function loadFile(path) {
122-
const url = baseUrl + path;
123-
fetch(url)
124-
.then(res => res.text())
125-
.then(code => {
126-
document.getElementById("container").innerHTML = "";
127-
document.getElementById("pathTitle").innerText = path;
128-
document.getElementById("codeViewer").innerHTML = `
129-
<pre><code class="language-csharp">${escapeHtml(code)}</code></pre>
130-
`;
131-
hljs.highlightAll();
132-
document.getElementById("backBtn").style.display = "inline-block";
133-
});
134-
}
135-
136-
document.getElementById("backBtn").onclick = () => {
137-
const prev = history.pop();
138-
renderLevel(prev.level, prev.title);
139-
};
140-
141-
function escapeHtml(text) {
142-
return text.replace(/[&<>"']/g, m => ({
143-
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#039;'
144-
})[m]);
145-
}
146-
</script>
147-
</body>
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>LeetCode Solutions – efrat-dev</title>
6+
<link rel="stylesheet" href="style.css" />
7+
<link
8+
rel="stylesheet"
9+
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css"
10+
/>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
12+
<script>
13+
hljs.highlightAll();
14+
</script>
15+
</head>
16+
<body>
17+
<h1>LeetCode Solutions</h1>
18+
<h2 id="pathTitle">Click to view solutions</h2>
19+
<button id="backBtn">⬅ Back</button>
20+
21+
<!-- Search Box -->
22+
<input type="text" id="searchInput" placeholder="Search for a solution..." />
23+
24+
<div id="container"></div>
25+
<div id="codeViewer"></div>
26+
<script src="script.js"></script>
27+
</body>
14828
</html>

docs/script.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
const owner = "efrat-dev";
2+
const repo = "algo-ds-leetcode";
3+
const branch = "main";
4+
const baseUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${branch}/`;
5+
6+
let fullTree = {};
7+
let allPaths = []; // גם קבצים וגם תיקיות
8+
let history = [];
9+
10+
fetch(`https://api.github.com/repos/${owner}/${repo}/git/trees/${branch}?recursive=1`)
11+
.then(res => res.json())
12+
.then(data => {
13+
const treeItems = data.tree.filter(item => item.type === "blob" || item.type === "tree");
14+
allPaths = treeItems.map(item => item.path);
15+
const filesOnly = treeItems.filter(item => item.type === "blob" && item.path.endsWith(".cs"));
16+
fullTree = buildTree(filesOnly.map(f => f.path));
17+
renderLevel(fullTree, "Click to view solutions");
18+
});
19+
20+
document.getElementById("searchInput").addEventListener("input", function () {
21+
const query = this.value.trim().toLowerCase();
22+
if (query === "") {
23+
renderLevel(fullTree, "Click to view solutions");
24+
} else {
25+
// שלוף רק פריטים ששמם (ולא כל הנתיב) תואם לחיפוש
26+
const results = allPaths.filter(path => {
27+
const parts = path.split("/");
28+
const name = parts[parts.length - 1];
29+
return name.toLowerCase().includes(query);
30+
});
31+
renderFlatResults(results, "Search results");
32+
}
33+
});
34+
function buildTree(paths) {
35+
const root = {};
36+
for (const path of paths) {
37+
const parts = path.split("/");
38+
let curr = root;
39+
for (let i = 0; i < parts.length; i++) {
40+
const part = parts[i];
41+
if (!curr[part]) {
42+
curr[part] = (i === parts.length - 1) ? path : {};
43+
}
44+
curr = curr[part];
45+
}
46+
}
47+
return root;
48+
}
49+
50+
function renderLevel(level, title) {
51+
const container = document.getElementById("container");
52+
container.innerHTML = "";
53+
document.getElementById("codeViewer").innerHTML = "";
54+
document.getElementById("pathTitle").innerText = title;
55+
document.getElementById("backBtn").style.display = history.length ? "inline-block" : "none";
56+
57+
for (const key in level) {
58+
const card = document.createElement("div");
59+
card.className = "card";
60+
card.innerText = key.replace(/\.cs$/, "");
61+
card.onclick = () => {
62+
if (typeof level[key] === "string") {
63+
loadFile(level[key]);
64+
} else {
65+
history.push({ level, title });
66+
renderLevel(level[key], key);
67+
}
68+
};
69+
container.appendChild(card);
70+
}
71+
}
72+
73+
function renderFlatResults(paths, title) {
74+
const container = document.getElementById("container");
75+
container.innerHTML = "";
76+
document.getElementById("codeViewer").innerHTML = "";
77+
document.getElementById("pathTitle").innerText = title;
78+
document.getElementById("backBtn").style.display = "inline-block";
79+
80+
if (paths.length === 0) {
81+
container.innerHTML = "<p>No results found</p>";
82+
return;
83+
}
84+
85+
for (const path of paths) {
86+
const parts = path.split("/");
87+
const name = parts[parts.length - 1].replace(/\.cs$/, "");
88+
89+
const card = document.createElement("div");
90+
card.className = "card";
91+
card.innerText = name;
92+
93+
card.onclick = () => {
94+
if (path.endsWith(".cs")) {
95+
loadFile(path);
96+
} else {
97+
const subtree = getSubTree(fullTree, path.split("/"));
98+
if (subtree) {
99+
history.push({ level: fullTree, title: "Click to view solutions" });
100+
renderLevel(subtree, name);
101+
} else {
102+
alert("Folder not found.");
103+
}
104+
}
105+
};
106+
107+
container.appendChild(card);
108+
}
109+
}
110+
111+
// פונקציה שמקבלת fullTree ונתיב, ומחזירה את הסאב-עץ המתאים
112+
function getSubTree(tree, parts) {
113+
let curr = tree;
114+
for (const part of parts) {
115+
if (curr[part] && typeof curr[part] === "object") {
116+
curr = curr[part];
117+
} else {
118+
return null;
119+
}
120+
}
121+
return curr;
122+
}
123+
124+
125+
126+
function loadFile(path) {
127+
const url = baseUrl + path;
128+
fetch(url)
129+
.then(res => res.text())
130+
.then(code => {
131+
document.getElementById("container").innerHTML = "";
132+
document.getElementById("pathTitle").innerText = path;
133+
document.getElementById("codeViewer").innerHTML = `
134+
<pre><code class="language-csharp">${escapeHtml(code)}</code></pre>
135+
`;
136+
hljs.highlightAll();
137+
document.getElementById("backBtn").style.display = "inline-block";
138+
});
139+
}
140+
141+
document.getElementById("backBtn").onclick = () => {
142+
const prev = history.pop();
143+
if (prev) {
144+
renderLevel(prev.level, prev.title);
145+
} else {
146+
renderLevel(fullTree, "Click to view solutions");
147+
}
148+
};
149+
150+
function escapeHtml(text) {
151+
return text.replace(/[&<>"']/g, m => ({
152+
'&': '&amp;',
153+
'<': '&lt;',
154+
'>': '&gt;',
155+
'"': '&quot;',
156+
"'": '&#039;'
157+
})[m]);
158+
}

docs/style.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
body {
2+
font-family: sans-serif;
3+
margin: 0;
4+
padding: 1rem;
5+
background: #f7f7f7;
6+
}
7+
8+
h1, h2 {
9+
text-align: center;
10+
}
11+
12+
#container {
13+
display: flex;
14+
flex-wrap: wrap;
15+
justify-content: center;
16+
gap: 1rem;
17+
}
18+
19+
.card {
20+
background: white;
21+
border-radius: 10px;
22+
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
23+
padding: 1rem;
24+
width: 200px;
25+
text-align: center;
26+
cursor: pointer;
27+
transition: transform 0.2s;
28+
}
29+
30+
.card:hover {
31+
transform: scale(1.05);
32+
}
33+
34+
#backBtn {
35+
display: none;
36+
margin-bottom: 1rem;
37+
cursor: pointer;
38+
background: #ddd;
39+
border: none;
40+
padding: 0.5rem 1rem;
41+
border-radius: 5px;
42+
}
43+
44+
#searchInput {
45+
width: 100%;
46+
padding: 0.5rem;
47+
margin-bottom: 1rem;
48+
border: 1px solid #ddd;
49+
border-radius: 5px;
50+
box-sizing: border-box;
51+
}
52+
53+
pre {
54+
background: #1e1e1e;
55+
color: #dcdcdc;
56+
padding: 1rem;
57+
border-radius: 8px;
58+
overflow-x: auto;
59+
white-space: pre-wrap;
60+
}
61+

0 commit comments

Comments
 (0)