Skip to content

Commit c0b57e3

Browse files
Merge pull request #64 from pooiod/develop
Updated things, and added extension
2 parents e7f2a39 + 0c9c44e commit c0b57e3

File tree

6 files changed

+239
-56
lines changed

6 files changed

+239
-56
lines changed

src/lib/libraries/extensions/SuperStorage/SuperStorage.svg

Lines changed: 1 addition & 0 deletions
Loading

src/lib/libraries/extensions/cloudstorage/CloudStorage.svg

Lines changed: 1 addition & 0 deletions
Loading

src/lib/libraries/extensions/index.jsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import React from 'react';
33
import { FormattedMessage } from 'react-intl';
44

55
import VideoSharing from './VidShare/VideoSharing.svg';
6+
import SuperStorage from './SuperStorage/SuperStorage.svg';
67
import NoahgptThumb from './noahgpt/costume1.svg';
78
import typescriptIcon from './snail-ide/typescript.svg';
89
import twGalleryIcon from './snail-ide/turbowarpgallery.svg';
910
import pmGalleryIcon from './snail-ide/penguinmodgallery.svg';
1011
import musicIconURL from './music/music.png';
1112
import roku from './roku/roku.png';
1213
import share from './share/share.svg';
13-
import cloudstorageIconURL from './cloudstorage/costume1.svg';
14+
import cloudstorageIconURL from './cloudstorage/CloudStorage.svg';
1415
import pythonIcon from './python/py.svg';
1516
import extCreateIcon from './ext-create/logo.svg';
1617
import extCreateInset from './ext-create/inset.svg';
@@ -229,15 +230,6 @@ const menuItems = [
229230
description: 'Do many things via the Scratch API; you can even fetch cloud data from projects!',
230231
featured: true
231232
},
232-
{
233-
name: 'Screensharing',
234-
extensionId: 'https://editor.snail-ide.com/screen-sharing.js',
235-
iconURL: 'https://editor.snail-ide.com/Screensharing.png', // please forgive me the text is slightly offcenter
236-
collaborator: 'pooiod7',
237-
tags: ['penguinmod'],
238-
description: 'Share your screen and get the current frame as a image.',
239-
featured: true
240-
},
241233
{
242234
name: 'VideoSharing',
243235
extensionId: 'https://editor.snail-ide.com/VideoSharing.js',
@@ -541,11 +533,20 @@ const menuItems = [
541533
name: 'Cloud Storage',
542534
extensionId: 'https://editor.snail-ide.com/cloudstorage.js',
543535
collaborator: 'pooiod7',
544-
iconURL: cloudstorageIconURL, // this needs to be redone soon
536+
iconURL: cloudstorageIconURL,
545537
tags: ['penguinmod'],
546538
description: 'Store data in a database, similar to Storage and Better Storage, but powered by a Snap! extension.',
547539
featured: true
548540
},
541+
{
542+
name: 'SuperStorage',
543+
extensionId: 'https://editor.snail-ide.com/SuperStorage.js',
544+
iconURL: SuperStorage,
545+
tags: ['penguinmod'],
546+
description: 'Store and retrieve data locally on device or remotely on a server.',
547+
collaborator: 'pooiod7',
548+
featured: true
549+
},
549550
{
550551
name: 'Text to Speech 2.0',
551552
extensionId: 'https://sharkpools-extensions.vercel.app/extension-code/Text-to-Speech.js',

static/SuperStorage.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
(function(Scratch) {
2+
'use strict';
3+
4+
if (!Scratch.extensions.unsandboxed) {
5+
throw new Error('This extension must run unsandboxed');
6+
}
7+
8+
class StorageV2 {
9+
constructor() {
10+
this.currentServer = "https://storage-ext.penguinmod.com/";
11+
this.useGlobal = true;
12+
this.waitingForResponse = false;
13+
this.serverFailedResponse = false;
14+
this.serverError = "";
15+
}
16+
17+
getInfo() {
18+
return {
19+
id: 'P7SuperStorage',
20+
name: 'Super Storage',
21+
color1: '#31b3d4',
22+
color2: '#179fc2',
23+
docsURI: 'https://pooiod7.neocities.org/markdown/#/projects/scratch/extensions/other/markdown/SuperStorage',
24+
blocks: [
25+
{ blockType: Scratch.BlockType.LABEL, text: "Local Storage" },
26+
{
27+
opcode: 'getValue',
28+
text: 'get local [KEY]',
29+
disableMonitor: true,
30+
blockType: Scratch.BlockType.REPORTER,
31+
arguments: {
32+
KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" }
33+
}
34+
},
35+
{
36+
opcode: 'setValue',
37+
text: 'set local [KEY] to [VALUE]',
38+
blockType: Scratch.BlockType.COMMAND,
39+
arguments: {
40+
KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" },
41+
VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "value" }
42+
}
43+
},
44+
{
45+
opcode: 'deleteValue',
46+
text: 'delete local [KEY]',
47+
blockType: Scratch.BlockType.COMMAND,
48+
arguments: { KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" } }
49+
},
50+
{
51+
opcode: 'getKeys',
52+
text: 'get all local stored names',
53+
disableMonitor: true,
54+
blockType: Scratch.BlockType.REPORTER
55+
},
56+
{
57+
blockType: Scratch.BlockType.LABEL,
58+
text: "Server Storage"
59+
},
60+
{
61+
opcode: 'waitingForConnection',
62+
text: 'waiting for server to respond?',
63+
disableMonitor: true,
64+
blockType: Scratch.BlockType.BOOLEAN
65+
},
66+
{
67+
opcode: 'connectionFailed',
68+
text: 'server failed to respond?',
69+
disableMonitor: true,
70+
blockType: Scratch.BlockType.BOOLEAN
71+
},
72+
{
73+
opcode: 'serverErrorOutput',
74+
text: 'server error',
75+
disableMonitor: false,
76+
blockType: Scratch.BlockType.REPORTER
77+
},
78+
"---",
79+
{
80+
opcode: 'getServerValue',
81+
text: 'get server [KEY]',
82+
disableMonitor: true,
83+
blockType: Scratch.BlockType.REPORTER,
84+
arguments: { KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" } }
85+
},
86+
{
87+
opcode: 'setServerValue',
88+
text: 'set server [KEY] to [VALUE]',
89+
blockType: Scratch.BlockType.COMMAND,
90+
arguments: {
91+
KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" },
92+
VALUE: { type: Scratch.ArgumentType.STRING, defaultValue: "value" }
93+
}
94+
},
95+
{
96+
opcode: 'deleteServerValue',
97+
text: 'delete server [KEY]',
98+
blockType: Scratch.BlockType.COMMAND,
99+
arguments: { KEY: { type: Scratch.ArgumentType.STRING, defaultValue: "key" } }
100+
}
101+
]
102+
};
103+
}
104+
105+
getPrefix() {
106+
return `P7_PROJECTSTORAGE_`;
107+
}
108+
109+
getAllKeys() {
110+
return Object.keys(localStorage).filter(key => key.startsWith(this.getPrefix())).map(key => key.replace(this.getPrefix(), ""));
111+
}
112+
113+
runPenguinWebRequest(url, options, ifFailReturn) {
114+
this.waitingForResponse = true;
115+
this.serverFailedResponse = false;
116+
this.serverError = "";
117+
118+
return fetch(url, options)
119+
.then(response => response.ok ? response.text() : Promise.reject(response.text()))
120+
.then(text => {
121+
this.waitingForResponse = false;
122+
return text;
123+
})
124+
.catch(err => {
125+
this.waitingForResponse = false;
126+
this.serverFailedResponse = true;
127+
this.serverError = err;
128+
return ifFailReturn;
129+
});
130+
}
131+
132+
getKeys() {
133+
return JSON.stringify(this.getAllKeys());
134+
}
135+
136+
getValue(args) {
137+
return localStorage.getItem(this.getPrefix() + args.KEY) || "";
138+
}
139+
140+
setValue(args) {
141+
localStorage.setItem(this.getPrefix() + args.KEY, args.VALUE);
142+
}
143+
144+
deleteValue(args) {
145+
localStorage.removeItem(this.getPrefix() + args.KEY);
146+
}
147+
148+
waitingForConnection() {
149+
return this.waitingForResponse;
150+
}
151+
152+
connectionFailed() {
153+
return this.serverFailedResponse;
154+
}
155+
156+
serverErrorOutput() {
157+
return this.serverError;
158+
}
159+
160+
getServerValue(args) {
161+
return this.runPenguinWebRequest(`${this.currentServer}get?key=${args.KEY}`, null, "");
162+
}
163+
164+
setServerValue(args) {
165+
return this.runPenguinWebRequest(`${this.currentServer}set?key=${args.KEY}`, {
166+
method: "POST",
167+
headers: { "Content-Type": "application/json" },
168+
body: JSON.stringify({ "value": args.VALUE })
169+
});
170+
}
171+
172+
deleteServerValue(args) {
173+
return this.runPenguinWebRequest(`${this.currentServer}delete?key=${args.KEY}`, { method: "DELETE" });
174+
}
175+
}
176+
177+
Scratch.extensions.register(new StorageV2());
178+
})(Scratch);

static/VideoSharing.js

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Video sharing (v2.4.1) by pooiod7
2-
// The successor to ScreenSharing
1+
// Video sharing (v2.4.2) by pooiod7
2+
// Was originally the "ScreenSharing" extension
33

44
(function(Scratch) {
55
'use strict';
@@ -21,7 +21,7 @@
2121

2222
let haswarned;
2323
function shouldwarn(){
24-
return Scratch.vm.runtime.isPackaged;
24+
return !Scratch.vm.runtime.isPackaged;
2525
}
2626

2727
class VideoSharing {
@@ -245,18 +245,12 @@
245245
}
246246

247247
startScreenSharing() {
248-
if (this.isSharing()) {
249-
this.stopSharing();
250-
}
248+
if (this.isSharing()) this.stopSharing();
251249

252-
if (!this.canScreen()) {
253-
return;
254-
}
250+
if (!this.canScreen()) return;
255251

256252
if (shouldwarn()) {
257-
if (!this.warn("screen")) {
258-
return;
259-
}
253+
if (!this.warn("screen")) return;
260254
}
261255

262256
return new Promise((resolve) => {
@@ -283,14 +277,10 @@
283277
}
284278

285279
startCameraSharing() {
286-
if (this.isSharing()) {
287-
this.stopSharing();
288-
}
280+
if (this.isSharing()) this.stopSharing();
289281

290282
if (shouldwarn()) {
291-
if (!this.warn("camera")) {
292-
return;
293-
}
283+
if (!this.warn("camera")) return;
294284
}
295285

296286
return new Promise((resolve, reject) => {
@@ -326,14 +316,10 @@
326316
}
327317

328318
getHEX(args) {
329-
if (!this.isSharing()) {
330-
return;
331-
}
319+
if (!this.isSharing()) return;
332320

333321
var rez = args.REZ;
334-
if (rez > 1) {
335-
rez = 1;
336-
}
322+
if (rez > 1) rez = 1;
337323
const canvas = document.createElement('canvas');
338324
const context = canvas.getContext('2d');
339325
const width = videoElement.videoWidth * rez;
@@ -357,14 +343,10 @@
357343
}
358344

359345
getPNG(args) {
360-
if (!this.isSharing()) {
361-
return;
362-
}
346+
if (!this.isSharing()) return;
363347

364348
var rez = args.REZ;
365-
if (rez > 1) {
366-
rez = 1;
367-
}
349+
if (rez > 1) rez = 1;
368350
const canvas = document.createElement('canvas');
369351
const context = canvas.getContext('2d');
370352
const width = videoElement.videoWidth * rez;
@@ -380,14 +362,10 @@
380362
}
381363

382364
getJPEG(args) {
383-
if (!this.isSharing()) {
384-
return;
385-
}
365+
if (!this.isSharing()) return;
386366

387367
let rez = args.REZ;
388-
if (rez > 1) {
389-
rez = 1;
390-
}
368+
if (rez > 1) rez = 1;
391369
const canvas = document.createElement('canvas');
392370
const context = canvas.getContext('2d');
393371
const width = videoElement.videoWidth * rez;
@@ -404,14 +382,10 @@
404382
}
405383

406384
getWEBP(args) {
407-
if (!this.isSharing()) {
408-
return;
409-
}
385+
if (!this.isSharing()) return;
410386

411387
let rez = args.REZ;
412-
if (rez > 1) {
413-
rez = 1;
414-
}
388+
if (rez > 1) rez = 1;
415389

416390
const canvas = document.createElement('canvas');
417391
const context = canvas.getContext('2d');

0 commit comments

Comments
 (0)