Skip to content

Commit 3e8fb58

Browse files
authored
Update document.html
1 parent f7d5b2c commit 3e8fb58

File tree

1 file changed

+1
-56
lines changed

1 file changed

+1
-56
lines changed

document.html

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,59 +83,4 @@ <h3>Table of Contents</h3>
8383
<ul id="toc"></ul>
8484
</div>
8585

86-
<script>
87-
document.addEventListener("DOMContentLoaded", function() {
88-
const toc = document.getElementById("toc");
89-
const headers = document.querySelectorAll("#content h1, #content h2, #content h3, #content h4, #content h5, #content h6");
90-
91-
headers.forEach(header => {
92-
const li = document.createElement("li");
93-
li.textContent = header.textContent;
94-
li.dataset.target = header.id || header.textContent.replace(/\s+/g, '-').toLowerCase();
95-
header.id = li.dataset.target;
96-
97-
li.addEventListener("click", function() {
98-
document.getElementById(header.id).scrollIntoView({ behavior: "smooth" });
99-
});
100-
101-
const level = parseInt(header.tagName.charAt(1), 10);
102-
if (level === 1) {
103-
toc.appendChild(li);
104-
} else {
105-
let parentLi = toc.querySelector(`li[data-target="${header.parentElement.id}"]`);
106-
if (parentLi) {
107-
let ul = parentLi.querySelector("ul");
108-
if (!ul) {
109-
ul = document.createElement("ul");
110-
parentLi.appendChild(ul);
111-
}
112-
ul.appendChild(li);
113-
}
114-
}
115-
});
116-
117-
const options = {
118-
root: null,
119-
threshold: 0.5,
120-
};
121-
122-
const callback = (entries) => {
123-
entries.forEach(entry => {
124-
const id = entry.target.id;
125-
const li = toc.querySelector(`li[data-target="${id}"]`);
126-
if (entry.isIntersecting) {
127-
if (li) {
128-
li.classList.add("active");
129-
}
130-
} else {
131-
if (li) {
132-
li.classList.remove("active");
133-
}
134-
}
135-
});
136-
};
137-
138-
const observer = new IntersectionObserver(callback, options);
139-
headers.forEach(header => observer.observe(header));
140-
});
141-
</script>
86+
<script type="text/javascript" src="script.js"></script>

0 commit comments

Comments
 (0)