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 /bookmarklet | |
| parent | 0b56868cafc04bcca61a9bda36d6351f05a2461c (diff) | |
| download | ffffallback-c91ce65f21f3caa6ae8bcbc5955f6a48878320fa.tar.bz2 | |
Rebuild the bookmarklet on the fly and elide boring fonts
Diffstat (limited to 'bookmarklet')
| -rw-r--r-- | bookmarklet/ffffallback.js | 49 |
1 files changed, 46 insertions, 3 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(); } |
