# Toggling Javascript for imported libraries

Hi all,

I'm wondering if there's a way to automatically toggle javascript extensions for imported libraries. I recall prior to Snap! 7 that this would happen when importing the extended math library (which included transpose, matrix mult, etc).

I get that there is security concerns with this, but considering users willingly import libraries, is there a way to allow JS extensions for those library blocks and no others? Thanks!

We have a solution for official libraries in the File>Libraries list.

For personal libraries that you import from a file or URL, the trouble is that the end user of a project may not be its creator. So if you "willingly import" a library into your project, that doesn't mean the person running the project knows anything about it. So we can't assume the end user wants to allow the library to do whatever it does.

Snap! has gone down another route called primitive extensions

These are trusted blocks that contain any JavaScript that all the current library blocks need.

If your own library blocks need JS, then you should convert them into extensions and ask that they be included as part of core Snap! (or get the team to authorise the site they are stored on)

How do we convert in to extension?

You don't. You make the concept and if the devs like it they'll implement it in JS and it'll be available in the primitive block.

and once you create a file for it, you can then create a repository on github, turn on github pages, and then use the url. Sorry if none of this makes sense.

I've made a few extensions myself. Here they are https://github.com/ego-lay-atman-bay/snap-extensions/tree/main/block-extensions
and here's links to the examples snap-extensions

oh, and to turn on github pages, just go into the settings tab of the repo, then click on pages. Under source, choose the main branch, or the branch you have the extensions under. Then choose the root folder, then click save.

oh ok

???
what

They are saying it's a complex process involving many steps.

It's unlikely that anyone's proposed extensions would be accepted into the core unless they really enhanced Snap! and couldn't be done without the use of JS

Examples of ones that have been accepted are the Serial Ports and the Signada robotics libraries

Ok, let me simplify it. Just make a js file.

To make a function for the primitie block, just put this function in the file for each function you want.

SnapExtensions.primitives.set(
'This is what'll show up in the primitive menu',
function (function,vars) {
//this is where you stick the js function
}
);


For example

SnapExtensions.primitives.set(
function (thing) {

Once you make that, you need to make a site to host the file on, like github, then you can load it into snap using the src_load(url) option in the primitive block. You do need js enabled to load the url, unless it has been whitelisted.