Echo JavaScript Safely

What you’re asking for is impossible, there is no such thing as a safe javascript entry box.

Even if we strip out extra script and style tags, it’s pointless, as the javascript code itself is inherently dangerous, and can create any elements it wants using DOM construction, e.g.:

var s = jQuery( 'script', { 'src': 'example.com/dangerous.js' } );
jQuery('body').append( s );

Or

var s = jQuery( 'link', {
    'rel': 'stylesheet',
    'type': 'text/css',
    'href': 'example.com/broken.css'
} );
jQuery('body').append( s );

Nevermind something that steals your login cookies, etc. Javascript is inherently dangerous, and what you’re trying to implement is an attack vector. This isn’t because people might break out of javascript, but because the javascript itself is potentially dangerous