mirror of
https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way.git
synced 2025-12-26 18:14:58 +08:00
add toc
This commit is contained in:
parent
ad5be8241d
commit
467fce2d37
2 changed files with 59 additions and 0 deletions
19
toc.js
Normal file
19
toc.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
(function(window) {
|
||||
String.prototype.repeat = function(num) {
|
||||
return new Array(num + 1).join(this);
|
||||
};
|
||||
var url = document.URL,
|
||||
headers = jQuery("article :header"),
|
||||
result;
|
||||
for (var i = 2; i < headers.length; i++) {
|
||||
var header = headers[i],
|
||||
headerText = header.textContent.trim(),
|
||||
hIndex = parseInt(header.nodeName.substring(1)) - 1,
|
||||
indent = " ".repeat(hIndex),
|
||||
link = ['<pre>', indent, '* [', headerText, '](', url, '#', headerText, ')', '\n', '</pre>'];
|
||||
result += link.join('');
|
||||
}
|
||||
var win = window.open("", "win");
|
||||
win.document.body.innerHTML = result;
|
||||
|
||||
})(window);
|
||||
Loading…
Add table
Add a link
Reference in a new issue