Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mikf
GitHub Repository: mikf/gallery-dl
Path: blob/master/docs/links.js
5457 views
1
"use strict";
2
3
4
function add_header_links()
5
{
6
let style = document.createElement("style");
7
style.id = "headerlinks"
8
document.head.appendChild(style);
9
style.sheet.insertRule(
10
"a.headerlink {" +
11
" visibility: hidden;" +
12
" text-decoration: none;" +
13
" font-size: 0.8em;" +
14
" padding: 0 4px 0 4px;" +
15
"}");
16
style.sheet.insertRule(
17
":hover > a.headerlink {" +
18
" visibility: visible;" +
19
"}");
20
21
let headers = document.querySelectorAll("h2, h3, h4, h5, h6");
22
for (let i = 0, len = headers.length; i < len; ++i)
23
{
24
let header = headers[i];
25
26
let id = header.id || header.parentNode.id;
27
if (!id)
28
continue;
29
30
let link = document.createElement("a");
31
link.href = "#" + id;
32
link.className = "headerlink";
33
link.textContent = "¶";
34
35
header.appendChild(link);
36
}
37
}
38
39
40
if (document.readyState !== "loading") {
41
add_header_links();
42
} else {
43
document.addEventListener("DOMContentLoaded", add_header_links);
44
}
45
46