1+ export default async function ( { feature, console, className } ) {
2+ if ( document . querySelector ( "." + className ( "real profile date" ) ) ) return ;
3+
4+ const PROFILE = Scratch . INIT_DATA . PROFILE . model . username
5+
6+ const data = await ( await fetch ( `https://api.scratch.mit.edu/users/${ PROFILE } /` ) ) . json ( )
7+ const joined = data . history . joined
8+
9+ const profileDetails = document . querySelector ( ".profile-details" )
10+ profileDetails . classList . add ( className ( "real profile date" ) )
11+ const profileDetailsChildNodes = profileDetails . childNodes
12+ const profileLocation = profileDetails . querySelector ( ".location" )
13+
14+ const locationIndex = [ ...profileDetailsChildNodes ] . indexOf ( profileLocation )
15+ const agoIndex = locationIndex - 1
16+ const dateIndex = locationIndex - 2
17+
18+ const oldJoined = profileDetailsChildNodes [ dateIndex ] . textContent
19+
20+ const newAgo = Object . assign ( document . createElement ( "span" ) , {
21+ textContent : profileDetailsChildNodes [ agoIndex ] . textContent ,
22+ className : className ( "hide ago real date" )
23+ } )
24+
25+ profileDetails . insertBefore ( newAgo , profileDetails . querySelector ( ".location" ) )
26+ profileDetailsChildNodes [ agoIndex ] . remove ( )
27+
28+ profileDetailsChildNodes [ dateIndex ] . textContent = new Date ( joined ) . toLocaleString ( )
29+
30+ feature . addEventListener ( "disabled" , function ( ) {
31+ profileDetailsChildNodes [ dateIndex ] . textContent = oldJoined
32+ } )
33+
34+ feature . addEventListener ( "enabled" , function ( ) {
35+ profileDetailsChildNodes [ dateIndex ] . textContent = new Date ( joined ) . toLocaleString ( )
36+ } )
37+ }
0 commit comments