diff options
| author | Mark Christian | 2011-03-30 18:41:27 -0700 |
|---|---|---|
| committer | Mark Christian | 2011-03-30 18:41:27 -0700 |
| commit | c91ce65f21f3caa6ae8bcbc5955f6a48878320fa (patch) | |
| tree | 626b42aed07db34a14abaec1054a248e75ac3d1f | |
| parent | 0b56868cafc04bcca61a9bda36d6351f05a2461c (diff) | |
| download | ffffallback-c91ce65f21f3caa6ae8bcbc5955f6a48878320fa.tar.bz2 | |
Rebuild the bookmarklet on the fly and elide boring fonts
| -rw-r--r-- | bookmarklet/ffffallback.js | 49 | ||||
| -rw-r--r-- | secret.html | 33 |
2 files changed, 76 insertions, 6 deletions
diff --git a/bookmarklet/ffffallback.js b/bookmarklet/ffffallback.js index 1e622ac..c3ac131 100644 --- a/bookmarklet/ffffallback.js +++ b/bookmarklet/ffffallback.js @@ -79,13 +79,56 @@ return uniquedArray; } + $.removeBoringFonts = function(allFonts) { + if(allFonts.length === 0) { + return allFonts; + } + + var knownBoringFonts = [ + 'helvetica', + 'lucida grande', + 'tahoma', + 'microsoft sans serif', + 'arial', + 'courier new', + 'times new roman', + 'verdana', + 'courier', + 'geneva', + 'monaco', + 'trebuchet ms', + 'lucida console', + 'comic sans ms', + 'georgia', + 'impact', + 'lucida sans unicode', + 'times' + ]; + + var interestingFonts = []; + $.each(allFonts, function(declaration) { + var fontsInDeclaration = $.getFontsFromDeclaration(declaration); + if(fontsInDeclaration.length === 0) { + return; + } + + if(knownBoringFonts.indexOf(fontsInDeclaration[0].toLowerCase()) >= 0) { + return; + } + + interestingFonts.push(declaration); + }); + + return interestingFonts; + } + $.getAllFontsInUse = function(elem) { var elemFont = $.getElementFont(elem); var fonts = elemFont ? [elemFont] : []; $.each(elem.childNodes, function(childElem) { fonts = fonts.concat($.getAllFontsInUse(childElem)); }); - return $.unique(fonts).sort(); + return $.removeBoringFonts($.unique(fonts)).sort(); } $.getClassForFont = function(font) { @@ -300,11 +343,11 @@ $.setFallbackCSS(cssDeclarations); }); } - + window.addEventListener('load', function() { $.init(); }, false); - + if(document.body) { $.init(); } diff --git a/secret.html b/secret.html index 5fa0df4..cd1970e 100644 --- a/secret.html +++ b/secret.html @@ -11,11 +11,38 @@ </style> </head> <body> - <hgroup> + <hgroup> <h1>FFFFALLBACK</h1> <h2>A simple tool for bulletproof web typography.</h2> - </hgroup> + </hgroup> <p>Shhhh! This is top secret. Grab the bookmarklet and take it for a spin. Please send any and all feedback to me at <a href="mailto:josh@jbrewer.me">feedback@ffffallback.com</a></p> - <p>This is the bookmarklet: <a href="javascript:(function(){var scriptTag=document.createElement('script');scriptTag.setAttribute('src','http://ffffallback.com/bookmarklet/ffffallback.js?r' + Math.random());var linkTag=document.createElement('link');linkTag.setAttribute('href','http://ffffallback.com/bookmarklet/ffffallback.css');linkTag.setAttribute('rel','stylesheet');document.body.appendChild(scriptTag);document.body.appendChild(linkTag);})();">ffffallback</a>—drag it to your bookmarks bar and brace yourself for an onslaught of unicorns and rainbows.</p> + <p>This is the bookmarklet: <a id="bookmarklet" href="#">ffffallback</a>—drag it to your bookmarks bar and brace yourself for an onslaught of unicorns and rainbows.</p> + <script> + var myURL = window.location.toString(); + var baseURL; + if(myURL.match(/\.html$/)) { + var urlChunks = myURL.split('/'); + baseURL = urlChunks.slice(0, urlChunks.length - 1).join('/') + } else { + baseURL = myURL; + } + if(baseURL.substring(myURL.length - 1) !== '/') { + baseURL += '/'; + } + var jsURL = baseURL + 'bookmarklet/ffffallback.js?r=' + Math.random(); + var cssURL = baseURL + 'bookmarklet/ffffallback.css?r=' + Math.random(); + var bookmarkletSource = 'javascript:' + +"(function() {\ + var scriptTag = document.createElement('script');\ + scriptTag.setAttribute('src', '" + jsURL + "');\ + var linkTag = document.createElement('link');\ + linkTag.setAttribute('href', '" + cssURL + "');\ + linkTag.setAttribute('rel','stylesheet');\ + document.body.appendChild(scriptTag);\ + document.body.appendChild(linkTag);\ +})();".replace(/\n/g, ' '); + + document.getElementById('bookmarklet').setAttribute('href', bookmarkletSource); + </script> </body> </html> |
