@@ -3,14 +3,7 @@ ScratchTools.Scratch = {
33 blockly : null ,
44} ;
55try {
6- ScratchTools . Scratch . vm =
7- window . vm ||
8- ( ( ) => {
9- const app = document . querySelector ( "#app" ) ;
10- return app [
11- Object . keys ( app ) . find ( ( key ) => key . startsWith ( "__reactContainer" ) )
12- ] . child . stateNode . store . getState ( ) . scratchGui . vm ;
13- } ) ( ) ;
6+ ScratchTools . Scratch . vm = window . vm || window . __steTraps . _onceMap . vm ;
147 ste . console . log ( "Able to load Virtual Machine." , "ste-traps" ) ;
158} catch ( err ) {
169 ste . console . warn ( "Unable to load Virtual Machine." , "ste-traps" ) ;
@@ -28,22 +21,24 @@ try {
2821
2922ScratchTools . Scratch . scratchSound = function ( ) {
3023 try {
31- return document . querySelector ( "div. sound-editor_editor-container_iUSW- " ) [
24+ let rI = document . querySelector ( "[class^= sound-editor_editor-container] " ) [
3225 Object . keys (
33- document . querySelector ( "div.sound-editor_editor-container_iUSW-" )
34- ) . find ( ( key ) => key . startsWith ( "__reactInternalInstance" ) )
35- ] . return . return . return . stateNode ;
26+ document . querySelector ( "[class^=sound-editor_editor-container]" )
27+ ) . find ( ( key ) => key . startsWith ( "__reactFiber" ) )
28+ ] ;
29+
30+ while ( ! rI . stateNode ?. audioBufferPlayer ) {
31+ rI = rI . return ;
32+ }
33+ return rI . stateNode ;
3634 } catch ( err ) {
3735 return null ;
3836 }
3937} ;
4038
4139ScratchTools . Scratch . scratchGui = function ( ) {
4240 try {
43- const app = document . querySelector ( "#app" ) ;
44- return app [
45- Object . keys ( app ) . find ( ( key ) => key . startsWith ( "__reactContainer" ) )
46- ] . child . stateNode . store . getState ( ) . scratchGui ;
41+ return window . __steRedux . state . scratchGui ;
4742 } catch ( err ) {
4843 return null ;
4944 }
@@ -176,46 +171,42 @@ ScratchTools.Scratch.waitForContextMenu = function (info) {
176171} ;
177172
178173ScratchTools . Scratch . scratchPaint = function ( ) {
179- var app = document . querySelector ( ".paint-editor_mode-selector_28iiQ" ) || document . querySelector ( ".paint-editor_mode-selector_O2uhP" ) || document . querySelector ( "[class*='paint-editor_mode-selector_']" ) ;
180- if ( app !== null ) {
181- return (
182- app [
183- Object . keys ( app ) . find ( ( key ) =>
184- key . startsWith ( "__reactInternalInstance" )
185- )
186- ] . child . stateNode . store ?. getState ( ) ?. scratchPaint || null
187- ) ;
188- } else {
174+ try {
175+ return __steRedux . state . scratchPaint ;
176+ } catch ( err ) {
189177 return null ;
190178 }
191179} ;
192180
193- ScratchTools . Scratch . getPaper = function ( ) {
194- let paintElement = document . querySelector (
195- "[class*='paint-editor_mode-selector']"
196- ) ;
197- let paintState =
198- paintElement [
199- Object . keys ( paintElement ) . find ( ( key ) =>
200- key . startsWith ( "__reactInternalInstance" )
201- )
202- ] . child ;
181+ window . __paperCache = null
182+
183+ async function getPaper ( ) {
184+ const modeSelector = document . querySelector ( "[class*='paint-editor_mode-selector']" ) ;
185+ const internalState = modeSelector [ Object . keys ( modeSelector ) . find ( ( el ) => el . startsWith ( "__reactFiber" ) ) ] . child ;
186+ let toolState = internalState ;
203187 let tool ;
204- while ( paintState ) {
205- let paintIn = paintState . child ? .stateNode ;
206- if ( paintIn ? .tool ) {
207- tool = paintIn . tool ;
188+ while ( toolState ) {
189+ const toolInstance = toolState . child . child . stateNode ;
190+ if ( toolInstance . tool ) {
191+ tool = toolInstance . tool ;
208192 break ;
209193 }
210- if ( paintIn ? .blob && paintIn ? .blob . tool ) {
211- tool = paintIn . blob . tool ;
194+ if ( toolInstance . blob && toolInstance . blob . tool ) {
195+ tool = toolInstance . blob . tool ;
212196 break ;
213197 }
214- paintState = paintState . sibling ;
198+ toolState = toolState . sibling ;
215199 }
216200 if ( tool ) {
217- return tool . _scope ;
201+ const paperScope = tool . _scope ;
202+ window . __paperCache = paperScope
203+ return paperScope ;
218204 }
205+ return null
206+ }
207+
208+ ScratchTools . Scratch . getPaper = async function ( ) {
209+ return await getPaper ( )
219210} ;
220211
221212async function alertForUpdates ( ) {
0 commit comments