-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement-loader.js
More file actions
64 lines (44 loc) · 1.61 KB
/
element-loader.js
File metadata and controls
64 lines (44 loc) · 1.61 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
54
55
56
57
58
59
60
61
62
63
64
// Start Time
const startTime = new Date();
// Attempting to Read Cookie
import { readCookie } from "./cookie-reader.js";
const elementsCookie = readCookie("elements");
let text;
if (elementsCookie != "") {
text = elementsCookie.replaceAll("/n", "\n").replaceAll("?", " ")
.replaceAll("^", ",").replaceAll("%", ";").trim();
} else {
// Fetching Elements
const response = await fetch('/elements.html');
text = await response.text();
// Saving Cookie
document.cookie =
"elements=" + text.replaceAll(" ", "").replaceAll("\n\n", "\n")
.replaceAll("\n", "/n").replaceAll(" ", "?").replaceAll(",", "^").replaceAll(";", "%") +
"; path=/;";
}
// Loading Elements
const parser = new DOMParser();
const documentElements = parser.parseFromString(text, 'text/html');
const elements = ['first-header', 'second-header', 'footer'];
for (let i in elements) {
const elementId = elements[i];
document.getElementById(elementId + '-loader').innerHTML =
documentElements.getElementById(elementId).outerHTML;
}
// Getting Website Version Data
let websiteVersion;
const projectsCookie = readCookie("projects");
if (projectsCookie != "") {
websiteVersion = projectsCookie.split("_")[6];
} else {
const { projects } = await import("/data-loader.js");
websiteVersion = projects[2].version;
}
document.getElementById("first-header-version").textContent = "Version " + websiteVersion;
// Log Script Time
const endTime = new Date();
console.log(
("/element-loader.js: ").padEnd(35) + // script path
(endTime - startTime).toString().padStart(4) + "ms" // time
);