Skip to content

Commit

Permalink
Merge pull request #696 from rgantzos/main
Browse files Browse the repository at this point in the history
  • Loading branch information
rgantzos authored Sep 5, 2023
2 parents 5d84d80 + 7889c35 commit c2ba80b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
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": "remove-project-button",
"versionAdded": "v3.3.0"
},
{
"version": 2,
"id": "right-side-flag",
Expand Down
16 changes: 16 additions & 0 deletions features/remove-project-button/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "Remove Project Button",
"description": "Adds a button to projects in studios that allows you to easily remove it from the studio without opening the menu.",
"credits": [
{
"username": "rgantzos",
"url": "https://scratch.mit.edu/users/rgantzos/"
}
],
"dynamic": true,
"styles": [{ "file": "style.css", "runOn": "/studios/*" }],
"scripts": [{ "file": "script.js", "runOn": "/studios/*" }],
"tags": ["New"],
"type": ["Website"],
"resources": [{ "name": "remove-project-trash", "path": "/remove.svg" }]
}
35 changes: 35 additions & 0 deletions features/remove-project-button/remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions features/remove-project-button/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
export default async function ({ feature, console }) {
ScratchTools.waitForElements(
".studio-project-bottom .overflow-menu-container",
function (menu) {
let img = document.createElement("img");
img.src = feature.self.getResource("remove-project-trash");
img.classList.add("ste-remove-project");

feature.self.hideOnDisable(img);

menu.appendChild(img);

img.addEventListener("click", async function () {
let projectId = menu
.closest(".studio-project-tile")
.firstChild.href.split("/")[4];
await fetch(
"https://api.scratch.mit.edu/studios/" +
window.location.pathname.split("/")[2] +
"/project/" +
projectId,
{
headers: {
"x-token": feature.redux.getState().session.session.user.token,
},
method: "DELETE",
}
);
menu.closest(".studio-project-tile").remove();
});
}
);
}
19 changes: 19 additions & 0 deletions features/remove-project-button/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.overflow-menu-container .overflow-menu-trigger {
display: none;
}

.ste-remove-project {
height: 2rem;
position: relative;
top: 0.35rem;
cursor: pointer;
transition: transform .3s, opacity .3s;
opacity: .6;
transform: scale(90%);
margin-right: .5rem;
}

.ste-remove-project:hover {
transform: scale(95%);
opacity: 1;
}

0 comments on commit c2ba80b

Please sign in to comment.