-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharticleHTML.js
More file actions
53 lines (52 loc) · 1.57 KB
/
articleHTML.js
File metadata and controls
53 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
*
* @file plugins/generic/embedHtmlArticleGalleyHeader/js/articleHTML.js
*
* Copyright (c) 2023 Belgorod State University
* Copyright (c) 2023 Eryomin Oleg
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
*/
const heads = document.querySelectorAll("h1, h2, h3, h4, h5, h6");
const imgs = document.getElementById("htmlContainer").querySelectorAll("img");
let paddings = new Map();
let value = 0;
for (i = 1; i <= 6; i++){
let key = "H" + i;
paddings.set(key, value);
value += 20;
}
const ul = document.getElementById("heads");
heads.forEach((h, index) => {
let id = "head" + index;
h.id = id;
let li = document.createElement("li");
li.style = "padding-left:" + paddings.get(h.tagName) + "px";
let a = document.createElement("a");
a.href = "#";
a.id = index;
a.addEventListener("click", function() {
const id = "head" + this.id;
document.getElementById(id).scrollIntoView();
}, false);
if (index !== 0) {
a.innerHTML = h.innerText;
} else {
a.innerHTML = "Article title";
}
if (h.innerText !== "Contents"){
if (h.innerText){
li.append(a);
ul.append(li);
}
}
});
imgs.forEach((img) => {
img.tabIndex = "0";
let a = document.createElement("a");
const icon = document.createElement("img");
icon.src = "https://" + window.location.hostname + "/plugins/generic/embedHtmlArticleGalleyHeader/images/download-icon-30.png"
a.append(icon);
a.href = img.getAttribute("src");
img.parentElement.append(a);
});