File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1
1
[
2
+ {
3
+ "version" : 2 ,
4
+ "id" : " studio-creation-date" ,
5
+ "versionAdded" : " v4.0.0"
6
+ },
2
7
{
3
8
"version" : 2 ,
4
9
"id" : " explore-filter" ,
Original file line number Diff line number Diff line change
1
+ {
2
+ "title" : " Studio Creation Date" ,
3
+ "description" : " Adds the creation date of the studio to the studio footer." ,
4
+ "credits" : [
5
+ {
6
+ "username" : " MaterArc" ,
7
+ "url" : " https://scratch.mit.edu/users/MaterArc/"
8
+ }
9
+ ],
10
+ "type" : [" Website" ],
11
+ "tags" : [" New" ],
12
+ "dynamic" : true ,
13
+ "scripts" : [{ "file" : " script.js" , "runOn" : " /studios/*" }],
14
+ "resources" : [{ "name" : " calendar" , "path" : " /calendar.svg" }]
15
+ }
Original file line number Diff line number Diff line change
1
+ export default function ( { feature } ) {
2
+ ScratchTools . waitForElements (
3
+ ".studio-info-footer-stats" ,
4
+ async function ( footer ) {
5
+ if ( document . querySelector ( ".ste-studio-created" ) ) return ;
6
+
7
+ const studioId = window . location . href . match ( / s t u d i o s \/ ( \d + ) / ) [ 1 ] ;
8
+ const apiUrl = `https://api.scratch.mit.edu/studios/${ studioId } ` ;
9
+
10
+ const response = await fetch ( apiUrl ) ;
11
+ const data = await response . json ( ) ;
12
+
13
+ const createdDate = new Date ( data . history . created ) ;
14
+ const monthNames = [
15
+ "Jan" ,
16
+ "Feb" ,
17
+ "Mar" ,
18
+ "Apr" ,
19
+ "May" ,
20
+ "Jun" ,
21
+ "Jul" ,
22
+ "Aug" ,
23
+ "Sep" ,
24
+ "Oct" ,
25
+ "Nov" ,
26
+ "Dec" ,
27
+ ] ;
28
+ const formattedDate = `Created ${
29
+ monthNames [ createdDate . getUTCMonth ( ) ]
30
+ } ${ createdDate . getUTCDate ( ) } , ${ createdDate . getUTCFullYear ( ) } `;
31
+
32
+ const creationDateDiv = document . createElement ( "div" ) ;
33
+ creationDateDiv . classList . add ( "studio-creation-date" ) ;
34
+ creationDateDiv . classList . add ( "ste-studio-created" )
35
+
36
+ const creationDateImg = document . createElement ( "img" ) ;
37
+ creationDateImg . src = feature . self . getResource ( "calendar" ) ;
38
+
39
+ const creationDateSpan = document . createElement ( "span" ) ;
40
+ creationDateSpan . textContent = formattedDate ;
41
+
42
+ creationDateDiv . appendChild ( creationDateImg ) ;
43
+ creationDateDiv . appendChild ( creationDateSpan ) ;
44
+
45
+ footer . insertBefore ( creationDateDiv , footer . firstChild ) ;
46
+ }
47
+ ) ;
48
+ }
You can’t perform that action at this time.
0 commit comments