alg.garron.us / alg.cubing.net bookmarklet

Tao Yu

Master
Joined
Jun 29, 2011
Messages
1,172
Location
Ireland
WCA ID
2012YUTA01
YouTube
Visit Channel
I hope this is the right section, as this is just a tiny piece of code that I put together.

This is a simple bookmarklet that lets you highlight text on a webpage and then view it on alg.garron.us or alg.cubing.net.

alg.cubing.net version
Code:
javascript:(function() {
function se(d) {
    return d.selection ? d.selection.createRange().text : d.getSelection()
}
s = se(document);
for (i=0; i<frames.length && !s; i++) s = se(frames.document);
if (!s || s=='') s = prompt('Enter%20an%20algorithm%20to%20%20view%20on%20alg.cubing.net','');
if (s!=null&&s!=''){
open('http://alg.cubing.net/?alg=' + (s ?  encodeURIComponent(s.toString().replace(/[’`]/g,"'").replace(/'(\d+)/g, "$1'")) :'')+'&type=alg').focus();
}
})();

alg.garron.us version
Code:
javascript:(function() {
function se(d) {
    return d.selection ? d.selection.createRange().text : d.getSelection()
}
s = se(document);
for (i=0; i<frames.length && !s; i++) s = se(frames.document);
if (!s || s=='') s = prompt('Enter%20an%20algorithm%20to%20%20view%20on%20alg.cubing.net','');
if (s!=null&&s!=''){
open('http://alg.garron.us/?alg=' + (s ?  encodeURIComponent(s.toString().replace(/[’`]/g,"'").replace(/'(\d+)/g, "$1'")) :'')).focus();
}
})();


I modified the code at the bottom of the Bookmarklet page on Wikipedia to make this. I can't take credit for writing the code. I just modified it so that it works with alg.garron.us and alg.cubing.net. I have next to no knowledge of javascript right now.

Obviously, credit goes to Lucas Garron for making alg.garron.us and alg.cubing.net.

How to install this:
This may differ with different browsers.

1. Bookmark this page.
2. Find the bookmark that you made and edit it (right click + Edit).
3. Copy and paste the code above into the "URL" box. Save your bookmark.

How to use this:

Highlight an algorithm on a page and open up the bookmark. A new tab should open with the algorithm entered into the algorithm box. Alternatively, pressing on the bookmark without highlighting something on a webpage will open up a popup asking you to enter an algorithm.

I hope that you will all find this useful.

Edit: I don't know what happened to the title of the thread...
Edit: Added '&type=alg' to the search path.
Edit: ’ is now automatically replaced by ' and R'2 is automatically replaced by R2'
 
Last edited:
Trivia: this is is how alg.garron.us came to be in the first place. I wanted a Firefox "search" that would let me view arbitrary algs so I first posted something in 2007. (In those days, Chrome didn't exist and speedsolving.com was just starting up!)

If you visit alg.cubing.net in Chrome, you can actually search for algs from the URL bar. In Firefox, you can add it with two clicks.
Unfortunately, this doesn't allow you to view a selected alg if you don't use it as your default "search engine".
(Also, you might want to add "&type=alg" to the search path if you know how.)

However, I do want to make a tool that lets you view a highlighted alg by popping up an animation on the page. Someone would be welcome to try to do that before me, but a bookmarklet like this should serve some needs for now.

alg_chrome.gif

alg_firefox.gif
 
Last edited:
Back
Top