Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions api/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,51 @@ async function alertForUpdates() {
}
}

function getScratchBlocks() {
var blocksWrapper = document.querySelector(
'div[class^="gui_blocks-wrapper"]'
);
var key = Object.keys(blocksWrapper).find((key) =>
key.startsWith("__reactInternalInstance$")
);
const internal = blocksWrapper[key];
var recent = internal.child;
while (!recent.stateNode?.ScratchBlocks) {
recent = recent.child;
window.__steScratchBlocks = null

async function _getBlocksWrapperComponent() {
const BLOCKS_CLASS = '[class^="gui_blocks-wrapper"]';
let elem = document.querySelector(BLOCKS_CLASS);
if (!elem) {
elem = document.querySelector(BLOCKS_CLASS);
}
return recent.stateNode.ScratchBlocks || null;
return _getBlocksComponent(elem);
}

function _getBlocksComponent(wrapper) {
const internal = wrapper[getInternalKey(wrapper)];
let childable = internal;
while (((childable = childable.child), !childable || !childable.stateNode || !childable.stateNode.ScratchBlocks)) {}
return childable;
}

function getInternalKey(elem) {
return Object.keys(elem).find((key) => key.startsWith("__react"))
}

function _getBlocksComponent(wrapper) {
const internal = wrapper[getInternalKey(wrapper)];
let childable = internal;
while (((childable = childable.child), !childable || !childable.stateNode || !childable.stateNode.ScratchBlocks)) {}
return childable;
}

async function getBlockly() {
const childable = await _getBlocksWrapperComponent();
return childable.stateNode.ScratchBlocks
}

window.__steRedux.target.addEventListener("statechanged", async function() {
try {
let blockly = await getBlockly()
if (blockly) {
window.__steScratchBlocks = blockly
}
} catch(err) {}
})

function getScratchBlocks() {
return window.__steScratchBlocks
}

ScratchTools.waitForElements(
Expand Down
4 changes: 2 additions & 2 deletions features/more-block-themes/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function ({ feature, console, scratchClass }) {
if (firstTheme) {
let css = await (await fetch(feature.self.getResource(firstTheme))).text();

feature.traps.gui().theme.theme = "default";
feature.traps.gui().settings.theme = "default";
feature.traps.vm.emitWorkspaceUpdate();

let style = document.createElement("style");
Expand Down Expand Up @@ -158,7 +158,7 @@ export default async function ({ feature, console, scratchClass }) {
.classList?.remove(SELECTED_CLASS);
this.querySelector("img").classList.add(SELECTED_CLASS);

feature.traps.gui().theme.theme = "default";
feature.traps.gui().settings.theme = "default";
feature.traps.vm.emitWorkspaceUpdate();
feature.traps.gui().menus.settingsMenu = false;

Expand Down