Yesterday I added a little featurette to Wordie: a keyboard shortcut (ctl-b) that automatically launches a work-appropriate site. The idea was to help people enjoy Wordie at work, without it being quite so obvious that they weren’t actually working. Silly, but whatever. I think it’s funny.
A few people have asked how to do the same, so here it is: how to implement a Wordie-style boss button.
First, download this open-source javascript library: http://www.openjs.com/scripts/events/keyboard_shortcuts/shortcut.js
Put it in the docroot of your webserver wherever you keep your javascript files (mine are in /javascripts), and add this function to the top of the file:
var rand = Math.floor(Math.random()*10);
switch(rand) {
case 0: url = ‘http://www.igra.com/’; break;
case 1: url = ‘http://www.census.gov/hhes/www/housing/hvs/qtr207/q207tab1.html’; break;
case 2: url = ‘http://www.ssa.gov/OACT/STATS/table4c6.html’; break;
case 3: url = ‘http://affiliate.amalgamatedlife.com/hipaa-Privacy_notice-SPA.asp’; break;
case 4: url = ‘http://www.barrymaher.com/’; break;
case 5: url = ‘http://www.batonrougeyogacompany.com/corporate.htm’; break;
case 6: url = ‘http://www.amazon.com/Chicken-Whole-Giannone-Chilled-3-25/dp/B000H4YZM8/’; break;
case 7: url = ‘http://en.wikipedia.org/wiki/Liver’; break;
case 8: url = ‘http://www.cachebeauty.com/wholsale/king.htm#jars’; break;
case 9: url = ‘http://www.thermo.com/com/cda/product/detail/0,1055,10121515,00.html’; break;
}
shortcut.add(“Ctrl+b”,function() {
location.href=url;
});
}
Then add this line to your web pages, inside the <head> tags at the top of the page, ideally in a commonly called template so you only have to do it once for the whole site. Make sure to edit the path so it matches where you actually put shortcuts.js:
Then, at the bottom of every page (again, ideally in a template), add this:
Now you can hit ‘ctl-b’, and the page will automatically change to one of the 10 urls in the bossButton function. You can change the urls, of course. To use a different keyboard shortcut, change the text in the “shortcut.add(…)” line towards the bottom of the bossButton() function.
Have fun, and don’t work too hard 🙂
Hi John! Thanks for your little script, which inspired me for a boss button on my little pointless web project carscount.com 😉 Works like a charm! Peter