Discuss Scratch
- Discussion Forums
- » Show and Tell
- » Scratch: Plugin/Extension
- -Elec-
-
Scratcher
78 posts
Scratch: Plugin/Extension
So i made a scratch plugin and/or extension and i just thought i'd come to the forums here to share it 
It adds multiple new blocks:
Advanced stuff:
Mod Installed?
Run HTML
Run JS
Variables
Please Note: All data on the Advanced Category comes from thewebsite
Source Code:
Please note: Everything is written in JavaScript and the code shown above needs to be pasted into the console for the blocks to work. (press F12, go to the console tab and paste it in the input box)
Also: Everyone that views this project MUST need the mod installed before use. Blocks will just not work unless you have the extension installed.
If this extension is used, please post a link to this forum and the creator (me, @-Elec-)
I need help with:
Supporters will be credited in an object shown in the JavaScript console.

It adds multiple new blocks:
Advanced stuff:
(GET Cloud_Vars ProjID:[140134783] CloudID:[Cloud_Variable])
(GET Views UserID:[-Elec-] ProjID:[140134783])
(GET Loves UserID:[-Elec-] ProjID:[140134783])
(GET Favourites UserID:[-Elec-] ProjID:[140134783])
(GET Comment Count UserID:[-Elec-] ProjID:[140134783])
Mod Installed?
<Installed?>
(Installed?)
Run HTML
Run HTML [Hello World!]- Warning: Generates a new window (Classed as popup)
Run JS
RUn JS [console.log("Hello world!");]Variables
Create Variable [name]- Please Note: Creates local variables (not scratch variables)
Set variable [name] to [value]
Delete Variable [name]
(Variable [name])
Please Note: All data on the Advanced Category comes from the
api.scratch.mit.edu
Source Code:
var vars = {
names: [],
values: [],
toreturn: "",
}
new function() {
var ext = this;
ext.t = function(a) {
return !0;
}, ext.t2 = function(a) {
return !0;
}, ext._shutdown = function() {}, ext._getStatus = function() {
return {
status: 2,
msg: "Ready"
};
};
var descriptor = {
blocks: [
["b", "Installed?", "t"],
["r", "Installed?", "t2"]
]
};
ScratchExtensions.register("Mod Installed?", descriptor, ext)
}, new function() {
var ext = this,
Code = "";
ext.Code = function(code, callback) {
eval(code);
if("function" == typeof callback) callback();
}, ext._shutdown = function() {}, ext._getStatus = function() {
return {
status: 2,
msg: "Ready"
};
};
var descriptor = {
blocks: [
["w", "Run JS %s", "Code", 'console.log("Hello world!");']
]
};
ScratchExtensions.register("Run Javascript", descriptor, ext)
}, new function() {
var ext = this;
ext.Code = function(code, callback) {
var c = window.open("", "", "location=no,toolbar=0,width=720,height=720");
c.document.body.innerHTML = code;
if("function" == typeof callback) callback();
}, ext._shutdown = function() {}, ext._getStatus = function() {
return {
status: 2,
msg: "Ready"
};
};
var descriptor = {
blocks: [
["w", "Run HTML %s", "Code", "Hello World!"]
]
};
ScratchExtensions.register("Run HTML", descriptor, ext)
}, new function() {
var ext = this;
ext.crtVar = function(name,callback) {
vars.names.push(name);
vars.values.push(0);
console.log(name,"=",0);
if("function" == typeof callback) callback();
},
ext.setVar = function(name,value,callback){
if(vars.names.indexOf(name)>(-1)) {
vars.values[vars.names.indexOf(name)] = value;
console.log(name,"=",value);
} else {
console.log("Variable name,",name,"not found!");
}
if("function" == typeof callback) callback();
},
ext.delVar = function(name,callback){
if(vars.names.indexOf(name)>(-1)) {
vars.values.splice(vars.names.indexOf(name),vars.names.indexOf(name));
console.log("Variable",name,"deleted!");
} else {
console.log("Variable name,",name,"not found!");
}
if("function" == typeof callback) callback();
},
ext.getVal = function(name,callback){
return vars.values[vars.names.indexOf(name)];
}, ext._shutdown = function() {}, ext._getStatus = function() {
return {
status: 2,
msg: "Ready",
};
};
var descriptor = {
blocks: [
["w", "Create Variable %s", "crtVar", "name"],
["w", "Set Variable %s to %s", "setVar", "name", "value"],
["w", "Delete Variable %s", "delVar", "name"],
["r", "Variable %s", "getVal", "name"]
]
};
ScratchExtensions.register("Variables", descriptor, ext);
}, new function() {
var ext = this;
ext.Get_CloudVar = function(ProjID,CloudDataID,callback){
$.getJSON("https://scratch.mit.edu/varserver/"+ProjID,function(json){
var GETnum = function(name){
list = json.variables;
for(ASjF=0;ASjF<list.length;ASjF++){
if(list[ASjF].name==name){
return ASjF;
}
}
return undefined;
}
vars.toreturn = json.variables[GETnum("☁ "+CloudDataID)].value.toString();
});
return vars.toreturn;
},
ext.getStatsViews = function(UserID,ProjID,callback){
$.getJSON("https://api.scratch.mit.edu/users/"+UserID+"/projects/"+ProjID,function(json){
vars.toreturn = json.stats.views;
});
return vars.toreturn;
},
ext.getStatsLoves = function(UserID,ProjID,callback){
$.getJSON("https://api.scratch.mit.edu/users/"+UserID+"/projects/"+ProjID,function(json){
vars.toreturn = json.stats.loves;
});
return vars.toreturn;
},
ext.getStatsFavourites = function(UserID,ProjID,callback){
$.getJSON("https://api.scratch.mit.edu/users/"+UserID+"/projects/"+ProjID,function(json){
vars.toreturn = json.stats.favorites;
});
return vars.toreturn;
},
ext.getStatsComments = function(UserID,ProjID,callback){
$.getJSON("https://api.scratch.mit.edu/users/"+UserID+"/projects/"+ProjID,function(json){
vars.toreturn = json.stats.comments;
});
return vars.toreturn;
},
ext._shutdown = function() {}, ext._getStatus = function() {
return {
status: 2,
msg: "Ready",
};
};
var descriptor = {
blocks: [
["r", "GET Cloud_Vars ProjID: %s CloudDataID: ☁ %s", "Get_CloudVar", "140134783","Cloud_Variable"],
["r", "GET Views from UserID: %s ProjID: %s", "getStatsViews", "-Elec-", "140134783"],
["r", "GET Loves from UserID: %s ProjID: %s", "getStatsLoves", "-Elec-", "140134783"],
["r", "GET Favorites UserID: %s from ProjID: %s", "getStatsFavourites", "-Elec-", "140134783"],
["r", "GET Comment Count from UserID: %s ProjID: %s", "getStatsComments", "-Elec-", "140134783"],
]
};
ScratchExtensions.register("EXPERIMENTAL: Advanced stuff", descriptor, ext)
};Please note: Everything is written in JavaScript and the code shown above needs to be pasted into the console for the blocks to work. (press F12, go to the console tab and paste it in the input box)
Also: Everyone that views this project MUST need the mod installed before use. Blocks will just not work unless you have the extension installed.
If this extension is used, please post a link to this forum and the creator (me, @-Elec-)
I need help with:
- A tampermonkey installment of this
Using github as a cdn. (for block to get code from github to use in the run HTML block or the run JavaScript block)
Supporters will be credited in an object shown in the JavaScript console.
- noogai34
-
Scratcher
46 posts
Scratch: Plugin/Extension
a horrible hat:: #ff00ff hat
do {
decorate (show::stack)
} in [sick v]::control
a cool cap:: #ff00ff cap
ring around the rosie :: ring
Last edited by noogai34 (April 23, 2019 23:52:24)
- f9racer452
-
Scratcher
27 posts
Scratch: Plugin/Extension
how do you do this because it says not defined at <anonymus>
- SUS-GAMES-CEO
-
Scratcher
1 post
Scratch: Plugin/Extension
define ()
define
say []
think [] for (2) secs
think []
switch costume to [ v]
play sound [ v]
stop all sounds
rest for () beats
- 5Y573M_F41LUR3
-
Scratcher
4 posts
Scratch: Plugin/Extension
How do I add it to my project without DevTools? My school has blocked DevTools. BTW DevTools = Console.
- Discussion Forums
- » Show and Tell
-
» Scratch: Plugin/Extension





