1function darkmode() { 2 document.documentElement.classList.toggle("dark-mode"); 3} 4// required for Bootstrap Buttons Event 5 6$("#selector button").click(function () { 7 $(this).addClass("active").siblings().removeClass("active"); 8 darkmode(); 9}); 10 11// TOC 12 13let tocString = ""; 14let tocShowing = false; 15 16$(() => { 17 $("#toc").hide(); 18 tocString = generateTOC(); 19 $(tocString).appendTo("#toc"); 20}); 21 22$("#toggle").on("click", () => { 23 if (!tocShowing) fadeIn($("#toc")); 24 else fadeOut($("#toc")); 25 tocShowing = !tocShowing; 26}); 27 28const fadeOut = elem => { 29 const fade = { opacity: 0, transition: "opacity 0.5s" }; 30 elem.css(fade).slideUp(); 31}; 32 33const fadeIn = elem => { 34 const fade = { opacity: 1, transition: "opacity 0.5s" }; 35 elem.css(fade).slideDown(); 36}; 37 38const generateTOC = () => { 39 let htags = document.querySelectorAll("h1, h2"); 40 41 let n = function(node) { 42 if (!node) { 43 return false; 44 } else { 45 return Number(node.tagName.substr(node.tagName.length - 1)); 46 } 47 }; 48 49 let tocString = "<h5>Table of Contents</h5>"; 50 let pn = ""; 51 for (let index = 0; index < htags.length; index++) {
52 let current = htags[index]; 53 let cn = n(current); 54 let tagid = "tag-" + index; 55 let tocItem = '<a href="#' + tagid + '">' + current.innerText + "</a>"; 56 current.setAttribute("id", tagid); 57 58 if (!current.innerText.replace(/\s/g, "").length) { 59 console.log("You have an empty h tag somewhere... we are not putting it in the table of contents, sorry."); 60 } else if (!pn) { 61 for (let index = 0; index < cn; index++) { 62 tocString += "<ol>"; 63 } 64 tocString += "<li>" + tocItem + "</li>"; 65 pn = cn; 66 } else if (cn === pn) { 67 tocString += "<li>" + tocItem + "</li>"; 68 pn = cn; 69 } else if (cn > pn) { 70 tocString = tocString.slice(0, -5); 71 for (let index = 0; index < cn - pn; index++) { 72 tocString; 73 tocString += "<ul>"; 74 } 75 tocString += "<li>" + tocItem + "</li>"; 76 pn = cn; 77 } else if (cn < pn) { 78 for (let index = 0; index < pn - cn; index++) { 79 tocString += "</ul></li>"; 80 } 81 tocString += "<li>" + tocItem + "</li>"; 82 pn = cn; 83 } 84 85 if (htags.length - 1 === index) { 86 let olCount = (tocString.match(/<ol>/g) || []).length; 87 let endolCount = (tocString.match(/<\/ol>/g) || []).length; 88 89 for (let index = 0; index < olCount - endolCount; index++) { 90 tocString += "</ol>"; 91 } 92 } 93 } 94 return tocString; 95};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.