File tree Expand file tree Collapse file tree 5 files changed +61
-0
lines changed
Expand file tree Collapse file tree 5 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11[
2+ {
3+ "version" : 2 ,
4+ "id" : " download-project" ,
5+ "versionAdded" : " v3.7.0"
6+ },
27 {
38 "version" : 2 ,
49 "id" : " blur-modal" ,
You can’t perform that action at this time.
0 commit comments