diff --git a/extensions/PPPDUD/fetchplus.js b/extensions/PPPDUD/fetchplus.js new file mode 100644 index 0000000000..724020dfc3 --- /dev/null +++ b/extensions/PPPDUD/fetchplus.js @@ -0,0 +1,62 @@ +// Name: Fetch+ +// ID: fetchplus +// Description: Make requests to the broader internet and use CORS proxies. +// License: MPL-2.0 + +(function(Scratch) { + 'use strict' + class AsyncExtension { + getInfo() { + return { + id: 'fetchplus', + name: 'Fetch+', + blocks: [{ + opcode: 'fetch_norm', + text: 'fetch [URL]', + blockType: Scratch.BlockType.REPORTER, + arguments: { + URL: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'https://extensions.turbowarp.org/hello.txt' + } + } + }, + + { + opcode: 'cors_fetch', + text: 'fetch with CORS proxy [URL]', + blockType: Scratch.BlockType.REPORTER, + arguments: { + URL: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'https://extensions.turbowarp.org/hello.txt' + } + } + } + ] + }; + } + fetch_norm(args) { + return Scratch.fetch(args.URL) + .then((response) => { + return response.text(); + }) + .catch((error) => { + console.error(error); + return 'Uh oh! Something went wrong.'; + }); + } + + cors_fetch(args) { + return Scratch.fetch('https://corsproxy.io/?' + encodeURIComponent(args.URL)) + .then((response) => { + return response.text(); + }) + .catch((error) => { + console.error(error); + return 'Uh oh! Something went wrong.'; + }); + } + } + Scratch.extensions.register(new AsyncExtension()); +})(Scratch); diff --git a/extensions/extensions.json b/extensions/extensions.json index 1afb46a935..436da73c38 100644 --- a/extensions/extensions.json +++ b/extensions/extensions.json @@ -9,6 +9,7 @@ "cursor", "runtime-options", "fetch", + "pppdud/fetchplus", "text", "local-storage", "true-fantom/base", diff --git a/images/PPPDUD/fetchplus.svg b/images/PPPDUD/fetchplus.svg new file mode 100644 index 0000000000..9b1a2615fa --- /dev/null +++ b/images/PPPDUD/fetchplus.svg @@ -0,0 +1 @@ +