Skip to content

Commit 2fd8944

Browse files
authored
Merge pull request #947 from rgantzos/main
Disable Cloud
2 parents b2e1389 + 8451773 commit 2fd8944

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

features/disable-cloud/data.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"title": "Disable Cloud",
3+
"description": "Allows you to disable cloud data on any project. This will still receive cloud data information, but will not send any.",
4+
"credits": [
5+
{ "username": "rgantzos", "url": "https://scratch.mit.edu/users/rgantzos/" }
6+
],
7+
"scripts": [{ "file": "script.js", "runOn": "/projects/*" }],
8+
"styles": [{ "file": "style.css", "runOn": "/projects/*" }],
9+
"type": ["Editor"],
10+
"tags": ["New", "Featured"],
11+
"dynamic": true
12+
}
13+

features/disable-cloud/script.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export default async function ({ feature, console }) {
2+
feature.traps.gui().projectState.cloudStatus = "ENABLED";
3+
4+
ScratchTools.waitForElements(".extension-chip", function (chip) {
5+
if (!chip.firstChild.src.endsWith("/svgs/project/clouddata.svg")) return;
6+
if (chip.querySelector(".ste-cloud-disable")) return;
7+
8+
let content = chip.querySelector(".extension-content");
9+
10+
let outer = document.createElement("div");
11+
outer.className = "ste-action-holder";
12+
outer.appendChild(content.lastChild);
13+
14+
let div = document.createElement("div");
15+
div.className = "extension-action ste-cloud-disable";
16+
outer.appendChild(div);
17+
18+
feature.self.hideOnDisable(div)
19+
20+
let span = document.createElement("span");
21+
span.textContent = "Disable";
22+
div.appendChild(span);
23+
24+
span.addEventListener("click", function () {
25+
if (span.textContent === "Disable") {
26+
span.textContent = "Enable";
27+
feature.traps.gui().projectState.cloudStatus = "DISABLED";
28+
} else {
29+
span.textContent = "Disable";
30+
feature.traps.gui().projectState.cloudStatus = "ENABLED";
31+
}
32+
});
33+
34+
content.appendChild(outer);
35+
});
36+
37+
const nativeWsSend = WebSocket.prototype.send;
38+
WebSocket.prototype.send = function (...args) {
39+
let data = JSON.parse(args[0]);
40+
if (
41+
data.method === "set" &&
42+
feature.traps.gui().projectState.cloudStatus === "DISABLED" &&
43+
feature.self.enabled
44+
)
45+
return;
46+
return nativeWsSend.call(this, ...args);
47+
};
48+
}

features/disable-cloud/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.ste-cloud-disable {
2+
height: 14px;
3+
margin-left: .25rem;
4+
cursor: pointer;
5+
padding-top: 1px !important;
6+
position: relative;
7+
top: 1px;
8+
}
9+
10+
.extension-chip .extension-action {
11+
display: inline-flex !important;
12+
}

features/features.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[
2+
{
3+
"version": 2,
4+
"id": "disable-cloud",
5+
"versionAdded": "v4.0.0"
6+
},
27
{
38
"version": 2,
49
"id": "webp-uploads",

0 commit comments

Comments
 (0)