11document . querySelectorAll ( "body > *" ) . forEach ( function ( el ) {
2- el . remove ( ) ;
3- } ) ;
4- document . body . style . backgroundColor = "white" ;
5- document . body . style . textAlign = "center" ;
6- document . body . style . padding = "3rem" ;
7- var h1 = document . createElement ( "h1" ) ;
8- h1 . textContent = "ScratchTools Authentication" ;
9- document . body . appendChild ( h1 ) ;
10- h1 . style . fontFamily = "Inter" ;
11- h1 . style . color = "#ff9f00" ;
12- var style = document . createElement ( "style" ) ;
13- style . textContent =
14- '@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");' ;
15- document . body . appendChild ( style ) ;
16- var p = document . createElement ( "p" ) ;
17- p . textContent = "Thank you for your patience while we authorize you." ;
18- p . style . color = "black" ;
19- p . style . opacity = ".5" ;
20- p . style . fontSize = "1rem" ;
21- document . body . appendChild ( p ) ;
22-
23- var verifyUser = async function ( callback ) {
24- var code = await (
25- await fetch ( `https://data.scratchtools.app/verification/code/` )
2+ el . remove ( ) ;
3+ } ) ;
4+ document . body . style . backgroundColor = "white" ;
5+ document . body . style . textAlign = "center" ;
6+ document . body . style . padding = "3rem" ;
7+ var h1 = document . createElement ( "h1" ) ;
8+ h1 . textContent = "ScratchTools Authentication" ;
9+ document . body . appendChild ( h1 ) ;
10+ h1 . style . fontFamily = "Inter" ;
11+ h1 . style . color = "#ff9f00" ;
12+ var style = document . createElement ( "style" ) ;
13+ style . textContent =
14+ '@import url("https://fonts.googleapis.com/css2?family=Inter&display=swap");' ;
15+ document . body . appendChild ( style ) ;
16+ var p = document . createElement ( "p" ) ;
17+ p . textContent = "Thank you for your patience while we authorize you." ;
18+ p . style . color = "black" ;
19+ p . style . opacity = ".5" ;
20+ p . style . fontSize = "1rem" ;
21+ document . body . appendChild ( p ) ;
22+
23+ var verifyUser = async function ( callback ) {
24+ var code = await (
25+ await fetch ( `https://data.scratchtools.app/verification/code/` )
26+ ) . json ( ) ;
27+ var PROJECT_ID = "854593681" ;
28+ var user = Scratch . INIT_DATA . LOGGED_IN_USER . model . username ;
29+ var connection = new WebSocket ( "wss://clouddata.scratch.mit.edu" ) ;
30+ connection . onerror = console . error ;
31+ connection . onopen = async ( ) => {
32+ connection . send (
33+ JSON . stringify ( { method : "handshake" , project_id : PROJECT_ID , user } ) +
34+ "\n"
35+ ) ;
36+ await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
37+ connection . send (
38+ JSON . stringify ( {
39+ value : code . code . toString ( ) ,
40+ name : "☁ verify" ,
41+ method : "set" ,
42+ project_id : PROJECT_ID ,
43+ user,
44+ } ) + "\n"
45+ ) ;
46+ connection . close ( ) ;
47+ var data = await (
48+ await fetch ( "https://data.scratchtools.app/verify/" , {
49+ method : "POST" ,
50+ headers : {
51+ Accept : "application/json" ,
52+ "Content-Type" : "application/json" ,
53+ } ,
54+ body : JSON . stringify ( { secret : code . secret } ) ,
55+ } )
2656 ) . json ( ) ;
27- var PROJECT_ID = "854593681" ;
28- var user = Scratch . INIT_DATA . LOGGED_IN_USER . model . username ;
29- var connection = new WebSocket ( "wss://clouddata.scratch.mit.edu" ) ;
30- connection . onerror = console . error ;
31- connection . onopen = async ( ) => {
32- connection . send (
33- JSON . stringify ( { method : "handshake" , project_id : PROJECT_ID , user } ) +
34- "\n"
35- ) ;
36- await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
37- connection . send (
38- JSON . stringify ( {
39- value : code . code . toString ( ) ,
40- name : "☁ verify" ,
41- method : "set" ,
42- project_id : PROJECT_ID ,
43- user,
44- } ) + "\n"
45- ) ;
46- connection . close ( ) ;
47- var data = await (
48- await fetch ( "https://data.scratchtools.app/verify/" , {
49- method : "POST" ,
50- headers : {
51- Accept : "application/json" ,
52- "Content-Type" : "application/json" ,
53- } ,
54- body : JSON . stringify ( { secret : code . secret } ) ,
55- } )
56- ) . json ( ) ;
57- callback ( data . code ) ;
58- } ;
57+ callback ( data . code ) ;
5958 } ;
60-
59+ } ;
60+
61+ if ( Scratch ?. INIT_DATA ?. LOGGED_IN_USER ?. model ?. username ) {
6162 verifyUser ( function ( code ) {
62- chrome . runtime . sendMessage ( steSupportId , { msg : "openFeedbackPage" , code } ) ;
63+ chrome . runtime . sendMessage ( steSupportId , { msg : "openFeedbackPage" , code } ) ;
6364 } ) ;
64-
65+ } else {
66+ window . location . href = "/login/" ;
67+ }
0 commit comments