summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoraltaf-creator <athaalaa@gmail.com>2023-07-25 09:45:30 +0700
committeraltaf-creator <athaalaa@gmail.com>2023-07-25 09:45:30 +0700
commite71f6203faf13574ef45bf80e23a546ac7866d5d (patch)
tree2ef9f32f6c7feeb50096e0141eb1002a4e3e807a /scripts
Initial commit
Diffstat (limited to 'scripts')
-rw-r--r--scripts/sidebar.js33
-rw-r--r--scripts/toc.js46
2 files changed, 79 insertions, 0 deletions
diff --git a/scripts/sidebar.js b/scripts/sidebar.js
new file mode 100644
index 0000000..3aaaef8
--- /dev/null
+++ b/scripts/sidebar.js
@@ -0,0 +1,33 @@
+function toggleNav() {
+ const sidebar = document.getElementById("sidebar");
+ const sStyle = window.getComputedStyle(sidebar);
+
+ if (sStyle.visibility == "hidden") {
+ if (document.body.clientWidth >= 700) {
+ document.getElementById("main").style.marginLeft = "360px";
+
+ try {
+ document.getElementById("banner").style.marginLeft = "300px";
+ document.getElementById("backbtn").style.marginLeft = "360px";
+ }
+ catch {
+
+ }
+ }
+
+ document.getElementById("sidebar").style.visibility = "visible";
+ document.getElementById("sidebar").style.opacity = "1";
+ } else {
+ document.getElementById("main").style.marginLeft = "0";
+ document.getElementById("sidebar").style.visibility = "hidden";
+ document.getElementById("sidebar").style.opacity = "0";
+
+ try {
+ document.getElementById("banner").style.marginLeft = "0";
+ document.getElementById("backbtn").style.marginLeft = "70px";
+ }
+ catch {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/scripts/toc.js b/scripts/toc.js
new file mode 100644
index 0000000..bfdfe42
--- /dev/null
+++ b/scripts/toc.js
@@ -0,0 +1,46 @@
+// i am a C# developer
+// trying javascript
+
+window.onload = function() {
+ const tocDiv = document.getElementById("toc");
+ const content = document.getElementById("main");
+ const headers = content.querySelectorAll('h1, h2, h3, h4, h5, h6');
+
+ console.log(headers)
+
+ const ul = document.createElement("ul");
+ tocDiv.appendChild(ul)
+
+ for (var i = 0; i < headers.length; i++) {
+ if (headers[i].hasAttribute('id')) {
+ const li = document.createElement("li");
+ var level = headers[i].tagName[1];
+ console.log(level + headers[i].tagName + headers[i].id)
+ if (level == 1) {
+ const a = document.createElement("a");
+ ul.appendChild(li);
+ li.appendChild(a);
+ a.href = "#" + headers[i].id
+ a.textContent = headers[i].textContent
+ }
+ else
+ {
+ var nowUl = document.createElement("ul");
+ ul.appendChild(nowUl);
+
+ for (var j = 0; j < level - 2; j++) {
+ const currentUl = document.createElement("ul");
+ nowUl.appendChild(currentUl);
+ nowUl = currentUl;
+ }
+
+ const currentLi = document.createElement("li");
+ const a = document.createElement("a");
+ nowUl.appendChild(currentLi);
+ currentLi.appendChild(a);
+ a.href = "#" + headers[i].id
+ a.textContent = headers[i].textContent
+ }
+ }
+ }
+} \ No newline at end of file