Skip to content

Commit 0b79b53

Browse files
committed
Download project
1 parent 71bd509 commit 0b79b53

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"title": "Download Projects",
3+
"description": "Adds a button to project pages that allows you to download the project as an .sb3 file.",
4+
"credits": [
5+
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
6+
],
7+
"type": ["Website"],
8+
"tags": ["New", "Featured"],
9+
"scripts": [{ "file": "script.js", "runOn": "/projects/*" }],
10+
"styles": [{ "file": "style.css", "runOn": "/projects/*" }],
11+
"resources": [{ "name": "download-btn", "path": "/download.svg" }]
12+
}
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export default async function ({ feature, console }) {
2+
ScratchTools.waitForElements(
3+
".preview .inner .flex-row.action-buttons",
4+
async function (row) {
5+
if (row.querySelector(".ste-download")) return;
6+
let button = document.createElement("button");
7+
button.className = "button action-button ste-download";
8+
button.textContent = "Download"
9+
button.addEventListener("click", async function () {
10+
let { title } = feature.redux.getState().preview.projectInfo;
11+
saveBlob(await feature.traps.vm.saveProjectSb3(), title + ".sb3");
12+
});
13+
row.appendChild(button)
14+
15+
window.feature = feature;
16+
var saveBlob = (function () {
17+
var a = document.createElement("a");
18+
document.body.appendChild(a);
19+
a.style = "display: none";
20+
return function (blob, fileName) {
21+
var url = window.URL.createObjectURL(blob);
22+
a.href = url;
23+
a.download = fileName;
24+
a.click();
25+
window.URL.revokeObjectURL(url);
26+
};
27+
})();
28+
}
29+
);
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.ste-download::before {
2+
background-image: var(--scratchtoolsresource-download-btn);
3+
display: inline-block;
4+
margin-right: .25rem;
5+
background-repeat: no-repeat;
6+
background-position: center center;
7+
background-size: contain;
8+
width: .875rem;
9+
height: .875rem;
10+
vertical-align: bottom;
11+
content: "";
12+
transform: scale(1.3);
13+
}

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": "download-project",
5+
"versionAdded": "v3.7.0"
6+
},
27
{
38
"version": 2,
49
"id": "blur-modal",

0 commit comments

Comments
 (0)