Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
javascript:%20(function(){var%20a=document.getElementsByTagName('script'),i,l,result,rurl=/^http:\/\/use\.typekit\.com\/([0-9A-Za-z]+)\.js/;for(i=0,l=a.length-1;i<l;i++){if(result=rurl.exec(a[i].getAttribute('src'))){window.location.assign('http://typekit.com/colophons/'+result[1]);break;}}%20if(!result){alert('This%20site%20doesn\'t%20use%20Typekit!');}})();
(function() {
var a = document.getElementsByTagName('script'),
i, l, result,
rurl = /^http:\/\/use\.typekit\.com\/([0-9A-Za-z]+)\.js/;
for (i = 0, l = a.length - 1; i < l; i++) {
if (result = rurl.exec(a[i].getAttribute('src'))) {
window.location.assign('http://typekit.com/colophons/' + result[1]);
break;
}
}
if (!result) {
alert('This site doesn\'t use Typekit!');
}
})();
Owner

pdokas commented Nov 13, 2010

A few improvements:

  1. Wrap everything in a self-executing function to prevent polluting the global namespace.
  2. Use regex to acquire the kit ID in the src of scripts.
  3. Don't recalculate the length of the script NodeList since that's an expensive recalculation on the live DOM every time through.

Awesome! I'm definitely going to replace my code with yours. Works great!

This is also why I posted it as a gist. I knew someone who had a better-than-hacky knowledge of JS would write something better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment