Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch+ #1492

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
62 changes: 62 additions & 0 deletions extensions/PPPDUD/fetchplus.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cursor",
"runtime-options",
"fetch",
"pppdud/fetchplus",
"text",
"local-storage",
"true-fantom/base",
Expand Down
1 change: 1 addition & 0 deletions images/PPPDUD/fetchplus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading