-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (65 loc) · 2.22 KB
/
script.js
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
76
77
78
79
80
81
(function(){
//Just a custom element for retitling the page
class titleElement extends HTMLElement {
constructor() {
super();
document.title = this.innerText;
this.style.visibility = "hidden";
this.style.display = "none";
this.style.position = "absolute";
}
// Element functionality written in here
}
customElements.define("page-title", titleElement);
class infoBox extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
console.log(this);
this.innerHTML = `<p style="margin:0;padding:0;">${this.innerHTML}</p>`;
this.style.display = "block";
this.style.padding = "8px";
this.style.margin = "8px 0";
this.style.borderRadius = "8px";
if (this.getAttribute("color")) {
this.style.background = `${this.getAttribute("color")}3e`;
this.style.border = `1px solid ${this.getAttribute("color")}9a`;
}
else {
this.style.background = "rgba(0, 149, 255, 0.245)";
this.style.border = "1px solid rgba(0, 149, 255, 0.604)";
}
}
}
customElements.define("info-box", infoBox);
//Get the page path
window.penPlusPath = window.location.origin + window.location.pathname;
window.gotoPath = (path) => {
window.location.href = window.penPlusPath + '?page=' + path.replaceAll("/","%2F");
}
//The source page for the documents
const docSource = window.penPlusPath + "/main/";
//Search parameters
const searchParams = new URLSearchParams(window.location.search);
//The doc to find
const page = searchParams.get("page") || "main";
//Fetch the doc info
fetch(`${docSource}${page}.html`).then(Response => {Response.text().then((dat) => {
document.getElementById("documentContents").innerHTML = dat;
})});
//Get the theme
document.body.className = localStorage.getItem("theme") || "theme-dark";
//Retheming
document.getElementById("theme-button").onclick = () => {
switch (document.body.className) {
case "theme-light":
document.body.className = "theme-dark";
break;
default:
document.body.className = "theme-light";
break;
}
localStorage.setItem("theme", document.body.className)
}
})();