blob: 218207c873b609dddc08b8cdbb4ccbc5c9e0a990 (
plain) (
blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
const preview = document.getElementById("preview");
const modify = document.getElementById("modify");
const content = document.getElementById("content");
const html = document.getElementsByTagName("html")[0];
const body = document.body;
// buttons
const raw = document.getElementById("raw");
const code = document.getElementById("code");
const dark = document.getElementById("dark");
const settings = document.getElementById("settings");
const originalContent = content.innerText;
if (extension === "html") {
preview.src = "data:text/html;charset=utf-8," + encodeURI(originalContent);
preview.style.display = "block";
raw.style.display = "block";
content.style.display = "none";
raw.addEventListener("click", () => {
if (preview.style.display === "block") {
html.style.overflow = "visible";
body.style.overflow = "visible";
raw.innerText = "Show preview";
preview.style.display = "none";
content.style.display = "block";
settings.style.display = "block";
} else {
html.style.overflow = "hidden";
body.style.overflow = "hidden";
raw.innerText = "Show raw";
preview.style.display = "block";
content.style.display = "none";
settings.style.display = "none";
}
});
} else if (extension === "md") {
const simplemde = new SimpleMDE({element: modify, hideIcons: ["fullscreen", "preview", "guide"]});
simplemde.value(originalContent);
content.style.display = "none";
html.style.overflow = "visible";
body.style.overflow = "visible";
} else {
settings.style.display = "block";
}
code.addEventListener("change", () => {
if (code.checked) {
content.classList.remove("prettyprinted");
content.innerHTML = "";
content.classList.add("linenums");
content.innerText = originalContent;
PR.prettyPrint();
} else {
content.classList.remove("prettyprinted");
content.innerHTML = "";
content.classList.remove("linenums");
content.innerText = originalContent;
PR.prettyPrint();
}
});
dark.addEventListener("change", () => {
if (dark.checked) {
document.getElementsByTagName("head")[0]
.insertAdjacentHTML("beforeend", '<link id="darkTheme" href="/css/darkTheme.css" rel="stylesheet" />');
document.getElementById("lightTheme").outerHTML = "";
} else {
document.getElementsByTagName("head")[0]
.insertAdjacentHTML("beforeend", '<link id="lightTheme" href="/css/lightTheme.css" rel="stylesheet" />');
document.getElementById("darkTheme").outerHTML = "";
}
});
|