Spritz Macro

Hi Everyone,

I’m not sure if it is possible but I presently use Spritzlet, a bookmark that basically takes the highlighted text from the web page that is being viewed and runs it through a javascript that invokes the spritz floating window for speed reading. I was wondering if this would be something that could be invoked in other applications such as mail using a keyboard command/shortcut.
Thanks in advance for your help.

The following is the javascript command that is invoked, for reference if necessary:

javascript:(function(){function loadScript()%7Bif(console %26%26 typeof(console.log)===%27function%27)%7Bconsole.log(%27SpritzletInit v1.1.8 - Loading https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js%27);
}var script=document.createElement(%27script%27);
script.setAttribute(%27type%27,%27text/javascript%27);
script.setAttribute(%27charset%27,%27UTF-8%27);
script.setAttribute(%27async%27,%27true%27);
script.setAttribute(%27src%27,%27https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js%3F%27+(new Date().getTime()).toString().substring(0,7));
document.documentElement.appendChild(script);
setTimeout(function()%7Bif(Spritzlet.timedOut===true)%7Balert(%22Sorry, it looks like this site doesn%27t allow bookmarklets to be run or Spritz servers aren%27t responding.%22);
}},3000);
script.onload=function()%7BSpritzlet.timedOut=false;
var rs=script.readyState;
if(!rs || rs===%27loaded%27 || rs===%27complete%27)%7Bscript.onload=script.onreadystatechange=null;
Spritzlet.init();
}};
}if(window.Spritzlet)%7BSpritzlet.activate();
}else%7Bwindow.Spritzlet=window.Spritzlet ||%7B};
window.Spritzlet=%7Borigin:window.location.protocol+%27//%27+window.location.host,loaderVersion:1.1,timedOut:true};
loadScript();
}})();

To make your scripts more readable in a forum post, you can put the script in a code block like this:

 ```javascript
 // put your script here

Also, add a return/linefeed after every semicolon.
I have revised your post using this.

Thank you for letting me know and revising the post.
I will keep in mind for future posts.

1 Like

What you have is some JavaScript code encoded in a javascript URL. It’ll take more than the editing that @JMichaelTX has done to turn the javascript URL into proper code. There is probably a site on the web to do it.

Yes, this does it: http://meyerweb.com/eric/tools/dencoder/

Which, after removing the javascript: from the front produces:

(function(){function loadScript(){if(console && typeof(console.log)==='function'){console.log('SpritzletInit v1.1.8 - Loading https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js');}var script=document.createElement('script');script.setAttribute('type','text/javascript');script.setAttribute('charset','UTF-8');script.setAttribute('async','true');script.setAttribute('src','https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js?' (new Date().getTime()).toString().substring(0,7));document.documentElement.appendChild(script);setTimeout(function(){if(Spritzlet.timedOut===true){alert("Sorry, it looks like this site doesn't allow bookmarklets to be run or Spritz servers aren't responding.");}},3000);script.onload=function(){Spritzlet.timedOut=false;var rs=script.readyState;if(!rs || rs==='loaded' || rs==='complete'){script.onload=script.onreadystatechange=null;Spritzlet.init();}};}if(window.Spritzlet){Spritzlet.activate();}else{window.Spritzlet=window.Spritzlet ||{};window.Spritzlet={origin:window.location.protocol '//' window.location.host,loaderVersion:1.1,timedOut:true};loadScript();}})();

Which is still unreadable gibberish, but which quite probably would work within an Execute JavaScript in Safari/Chrome action as is.

You can use: http://jsbeautifier.org

to format the result to get the actual code:

(function() {
    function loadScript() {
        if (console && typeof(console.log) === 'function') {
            console.log('SpritzletInit v1.1.8 - Loading https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js');
        }
        var script = document.createElement('script');
        script.setAttribute('type', 'text/javascript');
        script.setAttribute('charset', 'UTF-8');
        script.setAttribute('async', 'true');
        script.setAttribute('src', 'https://sdk.spritzinc.com/bookmarklet/latest/js/SpritzletOuter.js?' (new Date().getTime()).toString().substring(0, 7));
        document.documentElement.appendChild(script);
        setTimeout(function() {
            if (Spritzlet.timedOut === true) {
                alert("Sorry, it looks like this site doesn't allow bookmarklets to be run or Spritz servers aren't responding.");
            }
        }, 3000);
        script.onload = function() {
            Spritzlet.timedOut = false;
            var rs = script.readyState;
            if (!rs || rs === 'loaded' || rs === 'complete') {
                script.onload = script.onreadystatechange = null;
                Spritzlet.init();
            }
        };
    }
    if (window.Spritzlet) {
        Spritzlet.activate();
    } else {
        window.Spritzlet = window.Spritzlet || {};
        window.Spritzlet = {
            origin: window.location.protocol '//'
            window.location.host,
            loaderVersion: 1.1,
            timedOut: true
        };
        loadScript();
    }
})();

It’ll take more of a JavaScript expert to check whether it works or what modifications are needed to work with an Execute JavaScript in browser action.

Hi Peter,

Thanks for looking into it and also providing insight into the tools you have used. The code provided is definitely much easier to tinker with.