From c91ce65f21f3caa6ae8bcbc5955f6a48878320fa Mon Sep 17 00:00:00 2001 From: Mark Christian Date: Wed, 30 Mar 2011 18:41:27 -0700 Subject: Rebuild the bookmarklet on the fly and elide boring fonts --- bookmarklet/ffffallback.js | 49 +++++++++++++++++++++++++++++++++++++++++++--- 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 @@ -
+

FFFFALLBACK

A simple tool for bulletproof web typography.

-
+

Shhhh! This is top secret. Grab the bookmarklet and take it for a spin. Please send any and all feedback to me at feedback@ffffallback.com

-

This is the bookmarklet: ffffallback—drag it to your bookmarks bar and brace yourself for an onslaught of unicorns and rainbows.

+

This is the bookmarklet: ffffallback—drag it to your bookmarks bar and brace yourself for an onslaught of unicorns and rainbows.

+ -- cgit v1.2.3