Skip to content

Commit 1d3a799

Browse files
authored
Merge pull request #1010 from MaterArc/studio-invite-comments
Invite to Studio from Comments
2 parents e4718b4 + a0cc57d commit 1d3a799

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "studio-invite-comments",
5+
"versionAdded": "v4.2.0"
6+
},
27
{
38
"version": 2,
49
"id": "copy-paste-lists",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"title": "Invite to Studio from Comments",
3+
"description": "Adds an invite option next to report on studio comments.",
4+
"credits": [
5+
{
6+
"username": "Masaabu-YT",
7+
"url": "https://scratch.mit.edu/users/Masaabu-YT/"
8+
},
9+
{ "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" }
10+
],
11+
"type": ["Website"],
12+
"tags": ["New", "Featured"],
13+
"dynamic": true,
14+
"styles": [{ "file": "style.css", "runOn": "/studios/*" }],
15+
"scripts": [{ "file": "script.js", "runOn": "/studios/*" }],
16+
"resources": [{ "name": "invite", "path": "/invite.svg" }]
17+
}
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export default async function ({ feature }) {
2+
const parts = window.location.pathname.split("/");
3+
const studioId = parts[parts.length - 2];
4+
if (!studioId) return;
5+
6+
const session = await ScratchTools.Session();
7+
if (!session?.user?.username) return;
8+
9+
const csrfToken = document.cookie.match(/scratchcsrftoken=([^;]+)/)?.[1];
10+
if (!csrfToken) return;
11+
12+
ScratchTools.waitForElements(
13+
".comment-body",
14+
(comment) => {
15+
const topRow = comment.querySelector(".comment-top-row");
16+
const actionList = topRow?.querySelector(".action-list");
17+
if (!topRow || !actionList) return;
18+
if (actionList.querySelector(".ste-comment-invite")) return;
19+
20+
const inviteBtn = document.createElement("span");
21+
inviteBtn.classList.add("ste-comment-invite");
22+
23+
const innerSpan = document.createElement("span");
24+
innerSpan.textContent = "Invite";
25+
inviteBtn.appendChild(innerSpan);
26+
27+
inviteBtn.onclick = async () => {
28+
const username = topRow.querySelector(".username")?.textContent.trim();
29+
if (!username) return;
30+
const url = `https://scratch.mit.edu/site-api/users/curators-in/${studioId}/invite_curator/?usernames=${encodeURIComponent(
31+
username
32+
)}`;
33+
await fetch(url, {
34+
method: "PUT",
35+
headers: {
36+
"x-csrftoken": csrfToken,
37+
"Content-Type": "application/json",
38+
},
39+
credentials: "include",
40+
});
41+
};
42+
43+
actionList.appendChild(inviteBtn);
44+
},
45+
"ste-invite-buttons",
46+
false
47+
);
48+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.ste-comment-invite {
2+
cursor: pointer;
3+
margin-left: 10px;
4+
font-size: 0.75rem;
5+
font-weight: 500;
6+
opacity:0.5;
7+
}
8+
9+
.ste-comment-invite::before {
10+
content: "";
11+
display: inline-block;
12+
width: 1.1rem;
13+
height: 1.1rem;
14+
margin-right: 0.25rem;
15+
vertical-align: -0.27rem;
16+
background-image: var(--scratchtoolsresource-invite);
17+
background-repeat: no-repeat;
18+
background-size: contain;
19+
background-position: center;
20+
filter: brightness(0) saturate(100%) invert(38%) sepia(7%) saturate(582%) hue-rotate(185deg) brightness(94%) contrast(86%);
21+
}

0 commit comments

Comments
 (0)