diff --git a/addons/data-category-tweaks-v2/addon.json b/addons/data-category-tweaks-v2/addon.json
index 15c14735c2..fdbae1b160 100644
--- a/addons/data-category-tweaks-v2/addon.json
+++ b/addons/data-category-tweaks-v2/addon.json
@@ -4,6 +4,12 @@
"credits": [
{
"name": "GarboMuffin"
+ },
+ {
+ "name": "Jazza",
+ "note": "Variable count",
+ "id": "variableCount",
+ "link": "https://scratch.mit.edu/users/greeny--231"
}
],
"dynamicEnable": true,
@@ -34,6 +40,12 @@
"id": "moveReportersDown",
"type": "boolean",
"default": false
+ },
+ {
+ "name": "Show exact variable and list count",
+ "id": "showCounts",
+ "type": "boolean",
+ "default": true
}
],
"tags": ["editor", "codeEditor", "recommended"],
diff --git a/addons/data-category-tweaks-v2/userscript.js b/addons/data-category-tweaks-v2/userscript.js
index bee0799fe3..d170f6dbc6 100644
--- a/addons/data-category-tweaks-v2/userscript.js
+++ b/addons/data-category-tweaks-v2/userscript.js
@@ -9,6 +9,7 @@ export default async function ({ addon, console, msg, safeMsg }) {
// Used in setting change handler. Updated in getBlocksXML.
// (Yes this is weird but it's how it was originally and I'm too scared to change it)
let hasSeparateListCategory = false;
+ let hasGetCounts = false;
const separateVariablesByType = (toolboxXML) => {
const listButtonIndex = toolboxXML.findIndex(
@@ -152,12 +153,17 @@ export default async function ({ addon, console, msg, safeMsg }) {
vm.runtime.getBlocksXML = function (target) {
const result = originalGetBlocksXML.call(this, target);
hasSeparateListCategory = addon.settings.get("separateListCategory");
- if (!addon.self.disabled && hasSeparateListCategory) {
+ hasGetCounts = addon.settings.get("showCounts");
+
+ if (!addon.self.disabled && (hasSeparateListCategory || hasGetCounts)) {
result.push({
id: "data",
- xml: `
+ xml: hasSeparateListCategory
+ ? `
- `,
+ `
+ : `
+
+ `,
});
result.map = (callback) => {
// Prevent Scratch from trying to change the color of the added category in high contrast mode.
@@ -189,11 +205,25 @@ export default async function ({ addon, console, msg, safeMsg }) {
vm.emitWorkspaceUpdate();
}
+ if (addon.settings.get("showCounts")) {
+ hasGetCounts = true;
+ addon.tab.redux.initialize();
+
+ addon.tab.redux.addEventListener("statechanged", (event) => {
+ if (event.detail.action.type === "scratch-gui/monitors/UPDATE_MONITORS") {
+ vm.refreshWorkspace();
+ }
+ });
+ }
+
addon.settings.addEventListener("change", (e) => {
// When the separate list category option changes, we need to do a workspace update.
// For all other options, just refresh the toolbox.
// Always doing both of these in response to a settings change causes many issues.
- if (addon.settings.get("separateListCategory") !== hasSeparateListCategory) {
+ if (
+ addon.settings.get("separateListCategory") !== hasSeparateListCategory ||
+ addon.settings.get("showCounts") !== hasGetCounts
+ ) {
if (vm.editingTarget) {
vm.emitWorkspaceUpdate();
}