diff --git a/features/disable-cloud/data.json b/features/disable-cloud/data.json new file mode 100644 index 00000000..42601723 --- /dev/null +++ b/features/disable-cloud/data.json @@ -0,0 +1,13 @@ +{ + "title": "Disable Cloud", + "description": "Allows you to disable cloud data on any project. This will still receive cloud data information, but will not send any.", + "credits": [ + { "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" } + ], + "scripts": [{ "file": "script.js", "runOn": "/projects/*" }], + "styles": [{ "file": "style.css", "runOn": "/projects/*" }], + "type": ["Editor"], + "tags": ["New", "Featured"], + "dynamic": true + } + \ No newline at end of file diff --git a/features/disable-cloud/script.js b/features/disable-cloud/script.js new file mode 100644 index 00000000..92f441b0 --- /dev/null +++ b/features/disable-cloud/script.js @@ -0,0 +1,48 @@ +export default async function ({ feature, console }) { + feature.traps.gui().projectState.cloudStatus = "ENABLED"; + + ScratchTools.waitForElements(".extension-chip", function (chip) { + if (!chip.firstChild.src.endsWith("/svgs/project/clouddata.svg")) return; + if (chip.querySelector(".ste-cloud-disable")) return; + + let content = chip.querySelector(".extension-content"); + + let outer = document.createElement("div"); + outer.className = "ste-action-holder"; + outer.appendChild(content.lastChild); + + let div = document.createElement("div"); + div.className = "extension-action ste-cloud-disable"; + outer.appendChild(div); + + feature.self.hideOnDisable(div) + + let span = document.createElement("span"); + span.textContent = "Disable"; + div.appendChild(span); + + span.addEventListener("click", function () { + if (span.textContent === "Disable") { + span.textContent = "Enable"; + feature.traps.gui().projectState.cloudStatus = "DISABLED"; + } else { + span.textContent = "Disable"; + feature.traps.gui().projectState.cloudStatus = "ENABLED"; + } + }); + + content.appendChild(outer); + }); + + const nativeWsSend = WebSocket.prototype.send; + WebSocket.prototype.send = function (...args) { + let data = JSON.parse(args[0]); + if ( + data.method === "set" && + feature.traps.gui().projectState.cloudStatus === "DISABLED" && + feature.self.enabled + ) + return; + return nativeWsSend.call(this, ...args); + }; +} diff --git a/features/disable-cloud/style.css b/features/disable-cloud/style.css new file mode 100644 index 00000000..88d0712c --- /dev/null +++ b/features/disable-cloud/style.css @@ -0,0 +1,12 @@ +.ste-cloud-disable { + height: 14px; + margin-left: .25rem; + cursor: pointer; + padding-top: 1px !important; + position: relative; + top: 1px; +} + +.extension-chip .extension-action { + display: inline-flex !important; +} \ No newline at end of file diff --git a/features/features.json b/features/features.json index 605227cb..6ccffea7 100644 --- a/features/features.json +++ b/features/features.json @@ -1,4 +1,9 @@ [ + { + "version": 2, + "id": "disable-cloud", + "versionAdded": "v4.0.0" + }, { "version": 2, "id": "webp-uploads",