PageSourceSearch

https://www.ebpf.top/what-is-ebpf/gitbook/gitbook-plugin-page-toc-button/plugin.js

js ebpf.top collected 2026-10-03 23:19:53 UTC 2,987 bytes, 106 lines download raw bytes

1var gitbook = window.gitbook;
2var options = {};
3
4gitbook.events.bind('start', function(e, config) {
5
6	// Save config data
7    options = config['page-toc-button'] || {};
8	
9});
10
11gitbook.events.on('page.change', function() {
12	
13	// Default config values
14	var _maxTocDepth = 2;
15	var _minTocSize = 2;
16
17	// Read out config data
18	if (options)
19	{
20		_maxTocDepth = options.maxTocDepth ? options.maxTocDepth : _maxTocDepth;
21		_minTocSize = options.minTocSize ? options.minTocSize : _minTocSize;
22	};
23	
24    // Search for headers
25	var headerArray = $(".book .body-inner .markdown-section :header");
26
27    // Init variables
28	var tocArray = [];
29	var tocSize = 0;
30
31    // For each header...
32    for (i = 0; i < headerArray.length; i++) {
33
34		var headerElement = headerArray[i];
35		var header = $(headerElement);
36		var headerId = header.attr("id");
37		
38        if ((typeof headerId !== typeof undefined) && (headerId !== false)) {
39
40			switch(headerElement.tagName){
41				case "H1":
42					tocArray.push({
43						name: header.text(),
44						url: headerId,
45						children: []
46					});
47					tocSize++;
48					break;
49				case "H2":
50					if ((tocArray.length > 0) && (_maxTocDepth >= 1)) {
51						tocArray[tocArray.length-1].children.push({
52							name: header.text(),
53							url: headerId,
54							children: []
55						});
56						tocSize++;
57					};
58					break;
59				case "H3":
60					if ((tocArray.length > 0) && (_maxTocDepth >= 2)) {
61						if (tocArray[tocArray.length-1].children.length > 0) {
62							tocArray[tocArray.length-1].children[tocArray[tocArray.length-1].children.length-1].children.push({
63								name: header.text(),
64								url: headerId,
65								children: []
66							});
67							tocSize++;
68						};
69					};
70					break;
71				default:
72					break;
73			}
74		}	
75    };
76
77    // Cancel if not enough headers to show
78	if ((tocSize == 0) || (tocSize < _minTocSize)) {
79        return;
80	}
81
82    // Generate html for button and menu
83    var html = "<div class='page-toc-button'><i class='fa fa-bars' aria-hidden='true'></i><div class='page-toc-menu'><ul>";
84    for (i = 0; i < tocArray.length; i++) {
85        html += "<li><a href='#"+ tocArray[i].url + "'>" + tocArray[i].name + "</a></li>";
86        if (tocArray[i].children.length > 0) {
87            html += "<ul>"
88            for (j = 0; j < tocArray[i].children.length; j++) {
89                html += "<li><a href='#" + tocArray[i].children[j].url + "'>"+tocArray[i].children[j].name + "</a></li>";
90                if (tocArray[i].children[j].children.length > 0) {
91                    html += "<ul>"
92                    for (k = 0; k < tocArray[i].children[j].children.length; k++) {
93                        html += "<li><a href='#" + tocArray[i].children[j].children[k].url + "'>"+tocArray[i].children[j].children[k].name + "</a></li>";
94                    }
95                    html += "</ul>"
96                }
97            }
98            html += "</ul>"
99        }
100    }
101    html += "</ul></div></div>";
102
103    // Append generated html to page
104	$(".book").append(html)
105	
106});

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.