Discuss Scratch

BookOwl
Scratcher
1000+ posts

Splendid Strings, a scratch extension

Here is a extension I made, called Splendid Strings.

(function(ext) {
// Cleanup function when the extension is unloaded
ext._shutdown = function() {};

// Status reporting code
// Use this to report missing hardware, plugin or unsupported browser
ext._getStatus = function() {
return {status: 2, msg: 'Ready'};
};
ext.replace = function(old,str,neww){
return str.replace(new RegExp(old, 'g'),neww);
}
ext.slice = function(b,e,str){
return str.slice(b,e);
}
ext.trim = function(str){
return str.trim();
}
ext.eq = function(str1,str2){
return (str1 === str2);
}
ext.split = function(str,sep,max){
if(max<=0){
return JSON.stringify(str.split(sep));
}
return JSON.stringify(str.split(sep,max));
}
ext.get = function(i,a){
return JSON.parse(a)[i-1];
}
// Block and block menu descriptions
var descriptor = {
blocks: [
['r', 'Replace %s in %s with %s', 'replace', 'Python', 'Python is a great programming language', 'Scratch'],
['r', 'Characters %n to %n in %s', 'slice', '9','16','Imagine, Program, Share.'],
['r', 'Remove beginning and trailing whitespace from %s','trim',' Scratch '],
['b', '%s === %s','eq','Scratch','Cat'],
['r', 'Split %s by %s %n times', 'split','ScratchxCat','x','-1'],
['r', 'Item %n from the StringSplit %s', 'get','1'],
]
};

// Register the extension
ScratchExtensions.register('Splendid Strings', descriptor, ext);
})({});
To use,create a new project, open a javascript console in your web browser, paste in the previous code, and hit enter.
It gives you the following blocks:
( Replace [] in [] with [])

( Remove beginning and trailing whitespace from [])

('Characters [] to [] in [])

<[]===[]>

(Split [] by [] [] times)
(returns a string that you will need to pass to the next block)
(Item [] from the StringSplit [])
The
<[] === []>
is really cool because it makes B NOT EQUAL B!!! (unlike
<[] = [ ]>
does)

Last edited by BookOwl (Dec. 20, 2014 14:29:57)


who needs signatures
AonymousGuy
Scratcher
1000+ posts

Splendid Strings, a scratch extension

You may want to fix your code by putting it in [code] tags - right now some information is missing because of BBCode parsing.
BookOwl
Scratcher
1000+ posts

Splendid Strings, a scratch extension

It is fixed

who needs signatures
iwotastic
Scratcher
100+ posts

Splendid Strings, a scratch extension

Cool extension! Check out mine (link in sig).
sparks
Forum Moderator
100+ posts

Splendid Strings, a scratch extension

I'm new to Scratch extensions as an idea (been away for a while) will extensions like this save blocks to the project and let other people view them if they remix or see-inside the project?

“Dude, suckin' at something is the first step to being sorta good at something!” ~ Jake the Dog
djdolphin
Scratcher
1000+ posts

Splendid Strings, a scratch extension

sparks wrote:

I'm new to Scratch extensions as an idea (been away for a while) will extensions like this save blocks to the project and let other people view them if they remix or see-inside the project?
Not unless you're in the Extension Developer Group. I've been trying to join since around August, and I'm still not in. I never even got a reply from one of the people in charge of the group until a month ago. You'd probably have an easier time getting in the group since you're a forum moderator.

Edit: Actually, no, that's wrong. Extension developers just have access to a development environment. They still can't share projects with extensions, but they actually have a button to import them and can save them with their projects. Non-developers have to inject extensions using the console every time they want to use them.

Last edited by djdolphin (Dec. 21, 2014 13:24:04)


!
sparks
Forum Moderator
100+ posts

Splendid Strings, a scratch extension

Ah, thanks for the info!

From what I recently saw in This thread it looks like you could create a bookmark button for your browser that, when clicked, runs the above JS to import the extensions for you, saving you opening the console and pasting in code.

Sorry if that doesn't work or has already been thought of

“Dude, suckin' at something is the first step to being sorta good at something!” ~ Jake the Dog
nathanprocks
Scratcher
1000+ posts

Splendid Strings, a scratch extension

sparks wrote:

Ah, thanks for the info!

From what I recently saw in This thread it looks like you could create a bookmark button for your browser that, when clicked, runs the above JS to import the extensions for you, saving you opening the console and pasting in code.

Sorry if that doesn't work or has already been thought of
Try the Mega Scratch Userscript. It has a button to import extensions as well a built in extension library!


My browser / operating system: Macrosoft Winding XO, Internet Exploder 6.0, Angel Player ver.:1.2.5
;
MrSherlockHolmes
Scratcher
500+ posts

Splendid Strings, a scratch extension

Nice! I tested it on chrome.

Centred signature.
Petersonlong
Scratcher
14 posts

Splendid Strings, a scratch extension

I guess you will have to go to Scratch Wiki.com
Futurebot5
Scratcher
1000+ posts

Splendid Strings, a scratch extension

Petersonlong wrote:

I guess you will have to go to Scratch Wiki.com
Please don't necropost.

So…hello, ou bonjour, o hola, o ciao, oder hallo.

Powered by DjangoBB