Discuss Scratch

GH-group
Scratcher
14 posts

Adding javascript

Hello

I would like to add a piece of JavaScript code to a sprite.
Heard about extensions but did not find anything that let me add this kind of code to a project.
or maybe I should do this another way..
Please put me on track.. thnks
MegaApuTurkUltra
Scratcher
1000+ posts

Adding javascript

GH-group wrote:

Hello

I would like to add a piece of JavaScript code to a sprite.
Heard about extensions but did not find anything that let me add this kind of code to a project.
or maybe I should do this another way..
Please put me on track.. thnks
AFAIK you will need to make an extension to do this. Read the official extension docs for info about this.

Try something like
(function(ext) {
    ext._shutdown = function() {};
    ext._getStatus = function() {
        return {status: 2, msg: 'Swag'};
    };
    ext.run_code= function() {
        // insert code here
    };
    var descriptor = {
        blocks: [
            [' ', 'Run Custom JavaScript Code', 'run_code'],
        ]
    };
    ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
})({});
Then use
Run Custom JavaScript Code::extension

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
ChocolatePi
Scratcher
1000+ posts

Adding javascript

MegaApuTurkUltra wrote:

GH-group wrote:

Hello

I would like to add a piece of JavaScript code to a sprite.
Heard about extensions but did not find anything that let me add this kind of code to a project.
or maybe I should do this another way..
Please put me on track.. thnks
AFAIK you will need to make an extension to do this. Read the official extension docs for info about this.

Try something like
(function(ext) {
    ext._shutdown = function() {};
    ext._getStatus = function() {
        return {status: 2, msg: 'Swag'};
    };
    ext.run_code= function() {
        // insert code here
    };
    var descriptor = {
        blocks: [
            [' ', 'Run Custom JavaScript Code', 'run_code'],
        ]
    };
    ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
})({});
Then use
Run Custom JavaScript Code::extension
keep in mind you wouldn't be able to share.
GH-group
Scratcher
14 posts

Adding javascript

Thanks I'll try. I really appreciate your answers. I let you know what I did if (when) I got to work what Im trying to achieve here

Last edited by GH-group (Jan. 27, 2015 18:58:50)

GH-group
Scratcher
14 posts

Adding javascript

So I need to be a member of Scratch Developer Program first. Right?

What is the custom of getting an invitation? Anyone willing to invite me ?
MegaApuTurkUltra
Scratcher
1000+ posts

Adding javascript

GH-group wrote:

So I need to be a member of Scratch Developer Program first. Right?

What is the custom of getting an invitation? Anyone willing to invite me ?
You don't. Make your extension be a userscript so it adds itself automatically, and it should work (note that sharing projects with extensions is probably not allowed, but you can put them on your own site if you want!)

@djdolphin and I asked to be in the developer group months ago, and while part of the ST acknowledged and forwarded our requests, the ST members who should have put us in the group haven't responded yet.

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
GH-group
Scratcher
14 posts

Adding javascript

Ok
i try . Tutorial for userscript?
GH-group
Scratcher
14 posts

Adding javascript

Now I am confused
Extension cannot be added, except for some Lego and what it was other if I am not a Dev
But a userscript can be somehow. But userscript is browser dependent. or what is this userscript? where is it stored?
Or does the Scratch add the userscripts that I make in a browser extension as an extension automaticly?

What comes to dev I am not that interested to have status like that in itself. But as I said in first place I want to add javascript to the program.
That it cannot be shared is not a big deal if it can be compiled to something that can be shared. Which I believe it can be. But belief is nothing testing is.
MegaApuTurkUltra
Scratcher
1000+ posts

Adding javascript

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
GH-group
Scratcher
14 posts

Adding javascript

Thank you for clarifying.
I will try but this is only for evaluating or own fun.

at the moment it looks like I have to compile the scratch file to something else and add some code there.
But the compilers to be found are noy exatly to be found in abundace nor easy to use
merkourisa
Scratcher
3 posts

Adding javascript


MegaApuTurkUltra wrote:

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

Hello,

I installed Greasemonkey plugin in Firefox and added the userscript (myawesomescript.user.js) as you have already suggested but the Run Custom JavaScript Code Block doesn't appear in the More Blocks section. MegaApuTurkUltra do you have any ideas what is wrong?

Thanks in advance for the help

liam48D
Scratcher
1000+ posts

Adding javascript

merkourisa wrote:

MegaApuTurkUltra wrote:

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

Hello,

I installed Greasemonkey plugin in Firefox and added the userscript (myawesomescript.user.js) as you have already suggested but the Run Custom JavaScript Code Block doesn't appear in the More Blocks section. MegaApuTurkUltra do you have any ideas what is wrong?

Thanks in advance for the help

You're necroposting, I see this a lot from new scratchers on their first forum posts hehe..

I'd suggest using Google Chrome as it seems to work better on there (I can't get extensions running myself on FF).

202e-202e-202e-202e-202e UNI-CODE~~~~~
merkourisa
Scratcher
3 posts

Adding javascript

liam48D wrote:

merkourisa wrote:

MegaApuTurkUltra wrote:

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

Hello,

I installed Greasemonkey plugin in Firefox and added the userscript (myawesomescript.user.js) as you have already suggested but the Run Custom JavaScript Code Block doesn't appear in the More Blocks section. MegaApuTurkUltra do you have any ideas what is wrong?

Thanks in advance for the help

You're necroposting, I see this a lot from new scratchers on their first forum posts hehe..

I'd suggest using Google Chrome as it seems to work better on there (I can't get extensions running myself on FF).

I also used Chrome with the TamperMonkey plugin but still i can get the Run Custom JavaScript Code Block.

Any other suggestions?

merkourisa
Scratcher
3 posts

Adding javascript

merkourisa wrote:

liam48D wrote:

merkourisa wrote:

MegaApuTurkUltra wrote:

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

Hello,

I installed Greasemonkey plugin in Firefox and added the userscript (myawesomescript.user.js) as you have already suggested but the Run Custom JavaScript Code Block doesn't appear in the More Blocks section. MegaApuTurkUltra do you have any ideas what is wrong?

Thanks in advance for the help

You're necroposting, I see this a lot from new scratchers on their first forum posts hehe..

I'd suggest using Google Chrome as it seems to work better on there (I can't get extensions running myself on FF).

I also used Chrome with the TamperMonkey plugin but still i can get the Run Custom JavaScript Code Block.

Any other suggestions?


There was a missing s in the includes
// @include https: //scratch.mit.edu/projects/*

Now it works in Chrome

Thanks

Last edited by merkourisa (April 16, 2015 13:52:27)

CatsUnited
Scratcher
1000+ posts

Adding javascript

merkourisa wrote:

merkourisa wrote:

liam48D wrote:

merkourisa wrote:

MegaApuTurkUltra wrote:

Userscripts are browser dependent, yes. It's basically a hack for automatically adding your extensions when you're not in the dev group. You need a userscript manager (browser add-on) such as Greasemonkey (FF), or Tampermonkey (Chrome, Opera), and then you'll need a javascript file ending in .user.js
Then you write code like this
// ==UserScript==
// @name		My amazing scratch extention
// @author		You
// @description	Your custom userscript
// @include		http://scratch.mit.edu/projects/*
// @version		0.0.1
// @grant		unsafeWindow
// ==/UserScript==
setTimeout(function(){
    (function(ext) {
        ext._shutdown = function() {};
        ext._getStatus = function() {
            return {status: 2, msg: 'Swag'};
        };
        ext.run_code= function() {
            // insert code here
        };
        var descriptor = {
            blocks: [
                [' ', 'Run Custom JavaScript Code', 'run_code'],
            ]
        };
        // unsafeWindow is important here!
        // it references the window of the actual page,
        // rather than the window of the sandbox this script runs in
        unsafeWindow.ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
    })({});
}, 10000); // set timeout to wait for flash to load
Name it myawesomescript.user.js and finally drag the file onto your browser to have it installed by your userscript manager

Hello,

I installed Greasemonkey plugin in Firefox and added the userscript (myawesomescript.user.js) as you have already suggested but the Run Custom JavaScript Code Block doesn't appear in the More Blocks section. MegaApuTurkUltra do you have any ideas what is wrong?

Thanks in advance for the help

You're necroposting, I see this a lot from new scratchers on their first forum posts hehe..

I'd suggest using Google Chrome as it seems to work better on there (I can't get extensions running myself on FF).

I also used Chrome with the TamperMonkey plugin but still i can get the Run Custom JavaScript Code Block.

Any other suggestions?


There was a missing s in the includes
// @include https: //scratch.mit.edu/projects/*

Now it works in Chrome

Thanks

Scratch used to have http support but that was removed recently and we now use https

bottom text
MouseGames123
Scratcher
31 posts

Adding javascript

If you could add js, then you could make links!

I wrote:

MouseGames123 is Awesome!
liam48D
Scratcher
1000+ posts

Adding javascript

MouseGames123 wrote:

If you could add js, then you could make links!
You're necroposting..

202e-202e-202e-202e-202e UNI-CODE~~~~~
NoahBellybutton
Scratcher
25 posts

Adding javascript

MegaApuTurkUltra wrote:

GH-group wrote:

Hello

I would like to add a piece of JavaScript code to a sprite.
Heard about extensions but did not find anything that let me add this kind of code to a project.
or maybe I should do this another way..
Please put me on track.. thnks
AFAIK you will need to make an extension to do this. Read the official extension docs for info about this.

Try something like
(function(ext) {
    ext._shutdown = function() {};
    ext._getStatus = function() {
        return {status: 2, msg: 'Swag'};
    };
    ext.run_code= function() {
        // insert code here
    };
    var descriptor = {
        blocks: [
            [' ', 'Run Custom JavaScript Code', 'run_code'],
        ]
    };
    ScratchExtensions.register('JavaScript Code Runner', descriptor, ext);
})({});
Then use
Run Custom JavaScript Code::extension
How do you MAKE an extension?
\_0-0_/
Jonathan50
Scratcher
1000+ posts

Adding javascript

NoahBellybutton wrote:

How do you MAKE an extension?
\_0-0_/
Read this. You will need to use Javascript.

Last edited by Jonathan50 (March 6, 2018 02:49:55)


Not yet a Knight of the Mu Calculus.
wrobedera
Scratcher
4 posts

Adding javascript

ukaž [x myši v]::sensing // bylo by to dobré :-)
ukaž [y myši v]::sensing
ukaž [odpověď v]::sensing
ukaž [hlasitost v]::sensing
ukaž [uživatelské jméno v]::sensing

skryj [x myši v]::sensing
skryj [y myši v]::sensing
skryj [odpověď v]::sensing
skryj [hlasitost v]::sensing
skryj [uživatelské jméno v]::sensing

ukaž [směr v]::motion
ukaž [pozice x v]::motion
ukaž [pozice y v]::motion
ukaž [pozice x v]::motion

skryj [směr v]::motion
skryj [pozice x v]::motion
skryj [pozice y v]::motion
skryj [pozice x v]::motion

ukaž [hlasitost v]::sound
ukaž [tempo v]::sound

skryj [hlasitost v]::sound
skryj [tempo v]::sound

ukaž [kostým číslo v]::looks
ukaž [kostým číslo v]::looks
ukaž [pozadí číslo v]::looks
ukaž [pozadí číslo v]::looks
ukaž [velikost v]::looks

skryj [kostým číslo v]::looks
skryj [kostým číslo v]::looks
skryj [pozadí číslo v]::looks
skryj [pozadí číslo v]::looks
skryj [velikost v]::looks

ukaž [počet klonů v]::control //tyto skripty by pomohly
skryj [počet klonů v]::control
zruš (počet klonů::control) náhodné kony::control
zruš (náhodné číslo od (1) do (10)::operators) náhodné kony::control


napiš [ahoj] na scénu písmem [donegal v]::pen //tento blok by neuškodil


spusť([JavaScript v] kód \{[]\}::custom)::control // mohla by to být rozšíření
spusť([Java v] kód \{[]\}::custom)::control
spusť([C# v] kód \{[]\}::custom)::control
spusť([C++ v] kód \{[]\}::custom)::control

nastav [a v] na ([JavaScript v] kód \{[]\}::custom)::variables // s ním se dá dělat více věcí!
nastav [b v] na ([Java v] kód \{[]\}::custom)::variables
nastav [c v] na (náhodné číslo od (1) do (2)::operators)::variables
když <(c) = [1]> tak {
spusť(a)::control
}::control
když <(c) = [2]> tak {
spusť(b)::control
}::control
opakuj (náhodné číslo od (1) do (10)::operators) krát {
když <(c) = (náhodné číslo od (1) do (2)::operators)> tak {
přidej k [d v] (a)::list
}::control
když <(c) = (náhodné číslo od (1) do (2)::operators)> tak {
přidej k [d v] (a)::list
}::control
}::control
spusť(prvek [náhodně v] z [d v]::list)::control
when I receive [zpráva1 v] // a napadly mě další skripty
udělej za postavu [postava2 v] {
spusť ([a v] z [postava1 v]::sensing)::control
}::control

Last edited by wrobedera (Aug. 3, 2018 11:21:21)

Powered by DjangoBB