Skip to content
Open
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
1 change: 1 addition & 0 deletions addons/addons.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"fix-costume-drag",
"recolor-custom-blocks",
"totally-normal-modes",
"dropdown-numbers",

"// NEW ADDONS ABOVE THIS ↑↑",
"// Note: these themes need this exact order to work properly,",
Expand Down
30 changes: 30 additions & 0 deletions addons/dropdown-numbers/addon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Costume numbers in block dropdowns",
"description": "Shows the numbers of costumes in block dropdowns.",
"credits": [
{
"name": "DNin01",
"link": "https://github.com/DNin01"
},
{
"name": "mybearworld",
"link": "https://scratch.mit.edu/users/mybearworld"
}
],
"userstyles": [
{
"matches": ["projects"],
"url": "style.css"
}
],
"userscripts": [
{
"matches": ["projects"],
"url": "userscript.js"
}
],
"tags": ["editor", "codeEditor", "featured"],
"versionAdded": "1.45.0",
"dynamicEnable": true,
"dynamicDisable": true
}
5 changes: 5 additions & 0 deletions addons/dropdown-numbers/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.sa-dropdown-costume-numbers:not(.sa-dropdown-costume-numbers-cut-three) .goog-menuitem-content[data-index]::before {
content: attr(data-index) ". ";
opacity: 0.85;
font-weight: 400;
}
35 changes: 35 additions & 0 deletions addons/dropdown-numbers/userscript.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mxmou, would you be able to make this compatible with the new Blockly?

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default async function ({ addon, console }) {
const COSTUME_BLOCKS = {
looks_switchcostumeto: {},
looks_switchbackdropto: { cutThree: true },
looks_switchbackdroptoandwait: { cutThree: true },
event_whenbackdropswitchesto: {},
};

const Blockly = await addon.tab.traps.getBlockly();

async function showCostumeNumbers() {
const workspace = await addon.tab.traps.getWorkspace();
const block = workspace.getBlockById(document.querySelector(".blocklySelected").dataset.id);
if (block.type in COSTUME_BLOCKS) {
const dropDownContent = Blockly.DropDownDiv.getContentDiv();
dropDownContent.classList.add("sa-dropdown-costume-numbers");
const allItems = dropDownContent.querySelectorAll("[role='menuitemcheckbox']");
// Exclude previous/next/random backdrop
const { cutThree } = COSTUME_BLOCKS[block.type];
const limit = allItems.length - !!cutThree * 3;
for (let i = 0; i < limit; i++) {
allItems[i].lastChild.dataset.index = i + 1;
}
}
}
const oldDropDownDivShow = Blockly.DropDownDiv.show;
Blockly.DropDownDiv.show = function (...args) {
oldDropDownDivShow.call(this, ...args);
showCostumeNumbers();
};
const oldDropDownDivClearContent = Blockly.DropDownDiv.clearContent;
Blockly.DropDownDiv.clearContent = function () {
oldDropDownDivClearContent.call(this);
};
}