-
Notifications
You must be signed in to change notification settings - Fork 1
/
project.html
218 lines (200 loc) · 9.36 KB
/
project.html
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="en">
<head>
<title>Project | gnaw</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<meta name="background-color" content="#010409">
<meta name="theme-color" content="#0d1117">
<link rel="icon" sizes="512x512" href="images/icon.png">
<link rel="icon" sizes="64x64" href="images/icon64.png">
<link rel="manifest" href="manifest.webmanifest">
<link rel="stylesheet" href="styles.css">
<script src="theme.js"></script>
<style>
.thumbnail-container {
flex-shrink: 0;
margin-right: 10px;
}
.thumbnail {
width: 100px;
height: auto;
border-radius: 5px;
}
.flex {
display: flex;
}
.desc {
word-wrap: anywhere;
height: 155px;
overflow-y: scroll;
background-color: var(--accent);
}
#outer-desc {
width: 50%;
}
.comments {
overflow-wrap: anywhere;
}
.mobile-desc {
display: none;
}
@media screen and (max-width: 600px) {
#outer-desc {
display: none;
}
.mobile-desc {
display: block;
}
.desc {
flex: 1;
border: 1px solid var(--border-color);
padding: 15px;
border-radius: 5px;
}
.comment {
flex: 1;
border: 1px solid var(--border-color);
padding: 15px;
border-radius: 5px;
}
}
</style>
<script>
window.addEventListener("load", function() {
const urlParams = new URLSearchParams(window.location.search);
const embed = urlParams.get('project');
var descVisible = false;
var projectUrl = "https://corsproxy.io/?https://api.scratch.mit.edu/projects/" + embed;
var commentsVisible = false;
var toggleCommentsLink = document.getElementById('toggle-comments');
var toggleDescLink;
fetch(projectUrl).then(function(response) {
return response.json();
}).then(function(data) {
displayProjectInfo(data);
var commentsUrl = "https://corsproxy.io/?https://api.scratch.mit.edu/users/" + data.author.username + "/projects/" + embed + "/comments";
fetch(commentsUrl).then(function(response) {
return response.json();
}).then(function(comments) {
displayComments(data, comments);
toggleDescLink = document.getElementById('toggle-desc');
toggleCommentsLink.addEventListener('click', function() {
var commentsSection = document.getElementById('comments-list');
if (commentsVisible) {
commentsSection.style.display = 'none';
toggleCommentsLink.textContent = 'Show Comments';
} else {
commentsSection.style.display = 'block';
toggleCommentsLink.textContent = 'Hide Comments';
}
commentsVisible = !commentsVisible;
});
toggleDescLink.addEventListener('click', function() {
var desc = document.getElementById('desc-mobile');
if (descVisible) {
desc.style.display = 'none';
toggleDescLink.textContent = 'Show Description';
} else {
desc.style.display = 'block';
toggleDescLink.textContent = 'Hide Description';
}
descVisible = !descVisible;
});
}).catch(function(error) {
console.log("Error:", error);
});
}).catch(function(error) {
console.log("Error:", error);
});
});
function displayComments(projectData, commentsResponse) {
var commentsList = document.getElementById("comments-list");
if (Array.isArray(commentsResponse)) {
commentsResponse.forEach(function(comment) {
var commentItem = document.createElement("div");
commentItem.className = "comment read";
commentItem.innerHTML = `
<div class="comment-author" style='margin-bottom:10px;'><strong style='font-size:18px;'><a href='profile.html?username=${comment.author.username}'>${comment.author.username}</strong></a></div>
<div class="comment-content">${comment.content}</div>
`;
commentsList.appendChild(commentItem);
});
} else {
console.error("nope");
}
}
function displayProjectInfo(data) {
var projectInfo = document.getElementById("embed");
var html = "<div class='read flex proj'><iframe src='https://turbowarp.org/" + data.id + "/embed' allowtransparency='true' width='485' height='402' class='project-frame' frameborder='0' scrolling='no' allowfullscreen='yes'></iframe>" + "<div id='outer-desc'><div class='read desc'>" + formatText(data.instructions) + "</div>";
if (data.description && data.description.trim() !== "") {
html += "<div class='read desc'>" + formatText(data.description) + "</div></div>";
}
html += "</div>";
projectInfo.innerHTML = html;
var projectStats = document.getElementById("project-stats");
var htmlStats = "<div class='read'>" + "<h1 class='title wrap'><a href='https://scratch.mit.edu/projects/" + data.id + "'>" + data.title + "</a><font style='font-size:16px;'><em>#" + data.id + "</em></font></h1>" + "<p class='sub'><em>by <a href='profile.html?username=" + data.author.username + "'>" + data.author.username + "</a></em>" + " | Loves: " + data.stats.loves + " | Favorites: " + data.stats.favorites + " | Views: " + data.stats.views + " | Remixes: " + data.stats.remixes + " | Shared on: " + formatDate(data.history.shared) + " | <a href='https://gnaw.pages.dev/project?project=" + data.id + "' id='share'>Link</a>" + "</p>" + "<a href='javascript:void(0);' id='toggle-desc' class='mobile-desc'> Show Description</a>" + "<div id='desc-mobile' class='mobile-desc' style='display:none;'><div class='read desc'>" + formatText(data.instructions) + "</div>" + "<div class='read desc'>" + formatText(data.description) + "</div></div>" + "</div>";
projectStats.innerHTML = htmlStats;
document.title = data.title + " | gnaw";
}
function formatText(text) {
return text.replace(/\n/g, "<br>");
}
function formatDate(dateString) {
var date = new Date(dateString);
var options = {
year: 'numeric',
month: 'long',
day: 'numeric'
};
return date.toLocaleDateString('en-US', options);
}
</script>
</head>
<body>
<div class="nav">
<div class="inner-nav">
<div class="nav-item">
<a class="icon desktop" href="index.html">gnaw</a>
<a class="icon mobile" href="index.html">g</a>
<div class="nav-item" style="justify-content: right;">
<a class="icon desktop nvl" href="explore.html">Explore</a>
<a class="icon desktop nvl" href="featured.html">Featured</a>
</div>
</div>
</div>
</div>
<div class="page">
<div class="project-container">
<div id="embed"></div>
<div class="project-description" id="project-stats"></div>
</div>
<div class="comments read">
<div>
<h2 style="margin-top: 10px;">Comments</h2>
<a href="javascript:void(0);" id="toggle-comments"> Show Comments </a>
</div>
<div id="comments-list" style="display: none;"></div>
</div>
<div class="about">
<div id="about">
<a href="index.html" style="font-weight: bold; ">gnaw</a> / <a href="https://discord.com/users/797570703419244594">discord</a> / <a href="mailto:[email protected]">email me</a> / <a href="profile.html?username=3r1s_s">profile</a> / <a href="https://github.com/3r1s-s">github</a> / <a href="health.html">health</a> / <a href="about.html">about</a> / <a href="settings.html">settings</a> /
</div>
</div>
<div class="mobile-nav">
<div class="mobile-nav-item">
<a href="index.html"><i class="material-symbols-outlined">home</i></a>
</div>
<div class="mobile-nav-item">
<a href="featured.html"><i class="material-symbols-outlined">star</i></a>
</div>
<div class="mobile-nav-item">
<a href="explore.html"><i class="material-symbols-outlined">globe</i></a>
</div>
<div class="mobile-nav-item">
<a href="settings.html"><i class="material-symbols-outlined">settings</i></a>
</div>
</div>
</div>
</body>
</html>