|
1 | | -<script> |
2 | | - function getFileName(element) { |
3 | | - const indentSize = 4; |
4 | | - let path = ""; |
5 | | - let prevIndentLevel = null; |
6 | | -
|
7 | | - while (element) { |
8 | | - const line = element.textContent; |
9 | | - const index = line.search(/[a-zA-Z0-9_.-]/); |
10 | | - const indentLevel = index / indentSize; |
11 | | -
|
12 | | - // Stop when we reach or go above the top-level directory |
13 | | - if (indentLevel <= 1) { |
14 | | - break; |
15 | | - } |
16 | | -
|
17 | | - // Only include directories that are one level above the previous |
18 | | - if (prevIndentLevel === null || indentLevel === prevIndentLevel - 1) { |
19 | | - const fileName = line.substring(index).trim(); |
20 | | - path = fileName + path; |
21 | | - prevIndentLevel = indentLevel; |
22 | | - } |
23 | | -
|
24 | | - element = element.previousElementSibling; |
25 | | - } |
26 | | -
|
27 | | - return path; |
28 | | - } |
29 | | -
|
30 | | - function toggleFile(element) { |
31 | | - const patternInput = document.getElementById("pattern"); |
32 | | - const patternFiles = patternInput.value ? patternInput.value.split(",").map(item => item.trim()) : []; |
33 | | -
|
34 | | - const directoryContainer = document.getElementById("directory-structure-container"); |
35 | | - const treeLineElements = Array.from(directoryContainer.children).filter(child => child.tagName === "PRE"); |
36 | | -
|
37 | | - // Skip the first two tree lines (header and repository name) |
38 | | - if (treeLineElements[0] === element || treeLineElements[1] === element) { |
39 | | - return; |
40 | | - } |
41 | | -
|
42 | | - element.classList.toggle('line-through'); |
43 | | - element.classList.toggle('text-gray-500'); |
44 | | -
|
45 | | - const fileName = getFileName(element); |
46 | | - const fileIndex = patternFiles.indexOf(fileName); |
47 | | -
|
48 | | - if (fileIndex !== -1) { |
49 | | - patternFiles.splice(fileIndex, 1); |
50 | | - } else { |
51 | | - patternFiles.push(fileName); |
52 | | - } |
53 | | -
|
54 | | - patternInput.value = patternFiles.join(", "); |
55 | | - } |
56 | | -</script> |
57 | 1 | <div class="mt-10"> |
58 | 2 | <!-- Error Message (hidden by default) --> |
59 | 3 | <div id="results-error" style="display:none"></div> |
|
0 commit comments