-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
154 lines (123 loc) · 5.02 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const projectsDiv = document.getElementById("pageElements");
const searchDiv = document.getElementById("searchHelpers");
const searchParams = {
Type:"",
Name:""
}
const projectListing = [];
const addProject = (projectData) => {
let projectDiv = document.createElement("div");
projectDiv.className = "extension";
projectDiv.style.backgroundColor = "var(--background-3)";
projectDiv.style.borderRadius = "8px";
projectDiv.style.lineHeight = "0.4"
projectDiv.innerHTML = `
<div style="position: relative; width:calc(100% - 16px); margin: 8px; border-radius:8px;">
<img style="width:100%" src="Projects/${encodeURIComponent(projectData.Author)}/${encodeURIComponent(projectData.Name)}/Thumb.png">
<div class="hoverBOX" id="HoverBox_${projectData.Name}"></div>
</div>
<h2 style="color:var(--text-1);">${projectData.Name}</h2>
<p>By:${(projectData["Author-Link"]) ? `<a href="${projectData["Author-Link"]}">${projectData.Author}</a>` : projectData.Author}</p>
<p style="line-height:1;">${projectData.Description}</p>
`;
projectsDiv.appendChild(projectDiv);
const hoverBox = document.getElementById(`HoverBox_${projectData.Name}`);
if (projectData["In-Site"]) {
const linkButton = document.createElement("a");
linkButton.href = `${window.location.href}/Projects/${encodeURIComponent(projectData.Author)}/${encodeURIComponent(projectData.Name)}`;
linkButton.innerText = "Open Project";
linkButton.style.color = "#ffffff";
linkButton.style.backgroundColor = "#a34cff";
hoverBox.appendChild(linkButton);
}
if (projectData["External-Links"]) {
Object.keys(projectData["External-Links"]).forEach(Link => {
const link = projectData["External-Links"][Link];
const linkButton = document.createElement("a");
linkButton.href = link;
linkButton.innerText = `View on ${Link}`;
linkButton.style.color = "#ffffff";
if (Link == "Scratch") {
linkButton.innerText = `Original Version`;
}
linkButton.className = `hoverBOX-${Link}`;
hoverBox.appendChild(linkButton);
})
}
if (projectData["Project-File"]) {
const linkButton = document.createElement("a");
if (projectData.Type && projectData.Type == "Shader") {
linkButton.href = `https://pen-group.github.io/penPlus-shader-editor/Source/?project_url=${window.location.href}/Projects/${encodeURIComponent(projectData.Author)}/${encodeURIComponent(projectData.Name)}/${projectData["Project-File"]}`;
}
else {
linkButton.href = `https://turbowarp.org/?project_url=${window.location.href}/Projects/${encodeURIComponent(projectData.Author)}/${encodeURIComponent(projectData.Name)}/${projectData["Project-File"]}`;
}
linkButton.innerText = "Open in TurboWarp";
linkButton.style.color = "#ffffff";
linkButton.className = `hoverBOX-Turbowarp`;
hoverBox.appendChild(linkButton);
}
projectListing.push({
data:projectData,
element:projectDiv
});
}
fetch("FeaturedProjects.json")
.then((response) => response.text())
.then((text) => {
projectsDiv.innerHTML = ``;
let Projects = JSON.parse(text);
for (let projectID = 0; projectID < Projects.length; projectID++) {
addProject(Projects[projectID]);
}
});
const refreshProjectListing = () => {
projectsDiv.style.gridTemplateColumns = "1fr 1fr";
projectsDiv.innerHTML = ``;
const keys = Object.keys(searchParams);
projectListing.forEach(project => {
let projectValid = true;
//Search through keys
keys.forEach(key => {
if (project.data[key]) {
if (!project.data[key].toLowerCase().includes(searchParams[key].toLowerCase())) {
projectValid = false;
}
}
})
if (projectValid) {
projectsDiv.appendChild(project.element);
}
});
if (projectsDiv.children.length == 0) {
projectsDiv.innerHTML = `<h3 class="centered" style="margin-top: 48px; margin-bottom: 48px;">No projects match your search. 😕</h3>`;
projectsDiv.style.gridTemplateColumns = "1fr";
}
}
const handleInputTypes = (element) => {
switch (element.type) {
case "text":
element.addEventListener("change", () => {
searchParams.Name = element.value;
refreshProjectListing();
})
break;
default:
break;
}
}
Array.from(searchDiv.children).forEach(child => {
switch (child.localName) {
case "button":
child.onclick = () => {
searchParams.Type = child.getAttribute("typeSetter");
refreshProjectListing();
}
break;
case "input":
handleInputTypes(child);
break;
default:
break;
}
})