File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
features/studio-creation-date Expand file tree Collapse file tree 3 files changed +65
-0
lines changed 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 ( ! footer ) 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+
35+ const creationDateImg = document . createElement ( "img" ) ;
36+ creationDateImg . src = feature . self . getResource ( "calendar" ) ;
37+
38+ const creationDateSpan = document . createElement ( "span" ) ;
39+ creationDateSpan . textContent = formattedDate ;
40+
41+ creationDateDiv . appendChild ( creationDateImg ) ;
42+ creationDateDiv . appendChild ( creationDateSpan ) ;
43+
44+ footer . insertBefore ( creationDateDiv , footer . firstChild ) ;
45+ }
46+ ) ;
47+ }
You can’t perform that action at this time.
0 commit comments