Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions features/features.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"version": 2,
"id": "studio-invite-comments",
"versionAdded": "v4.2.0"
},
{
"version": 2,
"id": "copy-paste-lists",
Expand Down
17 changes: 17 additions & 0 deletions features/studio-invite-comments/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"title": "Invite to Studio from Comments",
"description": "Adds an invite option next to report on studio comments.",
"credits": [
{
"username": "Masaabu-YT",
"url": "https://scratch.mit.edu/users/Masaabu-YT/"
},
{ "username": "MaterArc", "url": "https://scratch.mit.edu/users/MaterArc/" }
],
"type": ["Website"],
"tags": ["New", "Featured"],
"dynamic": true,
"styles": [{ "file": "style.css", "runOn": "/studios/*" }],
"scripts": [{ "file": "script.js", "runOn": "/studios/*" }],
"resources": [{ "name": "invite", "path": "/invite.svg" }]
}
4 changes: 4 additions & 0 deletions features/studio-invite-comments/invite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions features/studio-invite-comments/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export default async function ({ feature }) {
const parts = window.location.pathname.split("/");
const studioId = parts[parts.length - 2];
if (!studioId) return;

const session = await ScratchTools.Session();
if (!session?.user?.username) return;

const csrfToken = document.cookie.match(/scratchcsrftoken=([^;]+)/)?.[1];
if (!csrfToken) return;

ScratchTools.waitForElements(
".comment-body",
(comment) => {
const topRow = comment.querySelector(".comment-top-row");
const actionList = topRow?.querySelector(".action-list");
if (!topRow || !actionList) return;
if (actionList.querySelector(".ste-comment-invite")) return;

const inviteBtn = document.createElement("span");
inviteBtn.classList.add("ste-comment-invite");

const innerSpan = document.createElement("span");
innerSpan.textContent = "Invite";
inviteBtn.appendChild(innerSpan);

inviteBtn.onclick = async () => {
const username = topRow.querySelector(".username")?.textContent.trim();
if (!username) return;
const url = `https://scratch.mit.edu/site-api/users/curators-in/${studioId}/invite_curator/?usernames=${encodeURIComponent(
username
)}`;
await fetch(url, {
method: "PUT",
headers: {
"x-csrftoken": csrfToken,
"Content-Type": "application/json",
},
credentials: "include",
});
};

actionList.appendChild(inviteBtn);
},
"ste-invite-buttons",
false
);
}
21 changes: 21 additions & 0 deletions features/studio-invite-comments/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.ste-comment-invite {
cursor: pointer;
margin-left: 10px;
font-size: 0.75rem;
font-weight: 500;
opacity:0.5;
}

.ste-comment-invite::before {
content: "";
display: inline-block;
width: 1.1rem;
height: 1.1rem;
margin-right: 0.25rem;
vertical-align: -0.27rem;
background-image: var(--scratchtoolsresource-invite);
background-repeat: no-repeat;
background-size: contain;
background-position: center;
filter: brightness(0) saturate(100%) invert(38%) sepia(7%) saturate(582%) hue-rotate(185deg) brightness(94%) contrast(86%);
}