/*
 * favcount.js v1.1.0
 * http://chrishunt.co/favcount
 * Dynamically updates the favicon with a number.
 *
 * Copyright 2013, Chris Hunt
 * Released under the MIT license
 */

(function(){
  function Favcount(icon) {
    this.icon = icon;
    this.canvas = document.createElement('canvas');
  }

  Favcount.prototype.set = function(count) {
    var self = this,
        img  = document.createElement('img');

    if (self.canvas.getContext) {
      img.onload = function() {
        drawCanvas(self.canvas, img, normalize(count));
      };

      img.src = this.icon;
    }
  }

  function normalize(count) {
    count = Math.round(count);

    if (isNaN(count) || count < 1) {
      return '';
    } else if (count < 10) {
      return ' ' + count;
    } else if (count > 99) {
      return '99';
    } else {
      return count;
    }
  }

  function drawCanvas(canvas, img, count) {
    var head = document.getElementsByTagName('head')[0],
        favicon = document.createElement('link'),
        multiplier, fontSize, context, xOffset, yOffset, border, shadow;

    favicon.rel = 'icon';

    // Scale canvas elements based on favicon size
    multiplier = img.width / 16;
    fontSize   = multiplier * 11;
    xOffset    = multiplier;
    yOffset    = multiplier * 11;
    border     = multiplier;
    shadow     = multiplier * 2;

    canvas.height = canvas.width = img.width;
    context = canvas.getContext('2d');
    context.font = 'bold ' + fontSize + 'px "helvetica", sans-serif';

    // Draw faded favicon background
    if (count) { context.globalAlpha = 0.4; }
    context.drawImage(img, 0, 0);
    context.globalAlpha = 1.0;

    // Draw white drop shadow
    context.shadowColor = '#FFF';
    context.shadowBlur = shadow;
    context.shadowOffsetX = 0;
    context.shadowOffsetY = 0;

    // Draw white border
    context.fillStyle = '#FFF';
    context.fillText(count, xOffset, yOffset);
    context.fillText(count, xOffset + border, yOffset);
    context.fillText(count, xOffset, yOffset + border);
    context.fillText(count, xOffset + border, yOffset + border);

    // Draw black count
    context.fillStyle = '#000';
    context.fillText(count,
      xOffset + (border / 2.0),
      yOffset + (border / 2.0)
    );

    // Replace favicon with new favicon
    favicon.href = canvas.toDataURL('image/png');
    head.removeChild(document.querySelector('link[rel=icon]'));
    head.appendChild(favicon);
  }

  this.Favcount = Favcount;
}).call(this);

(function(){
  Favcount.VERSION = '1.1.0';
}).call(this);

@@ -14,17 +14,17 @@
 t.js v1.
-1
+4
 .0%0A * ht
@@ -231,24 +231,48 @@
 con = icon;%0A
+    this.opacity = 0.4;%0A
     this.can
@@ -311,16 +311,64 @@
 nvas');%0A
+    this.font = %22Helvetica, Arial, sans-serif%22;%0A
   %7D%0A%0A  F
@@ -570,24 +570,49 @@
 self.canvas,
+ self.opacity, self.font,
  img, normal
@@ -662,32 +662,33 @@
 .icon;%0A    %7D%0A  %7D
+;
 %0A%0A  function nor
@@ -965,16 +965,31 @@
 (canvas,
+ opacity, font,
  img, co
@@ -1580,32 +1580,16 @@
 'px 
-%22helvetica%22, sans-serif'
+' + font
 ;%0A%0A 
@@ -1663,19 +1663,23 @@
 Alpha = 
-0.4
+opacity
 ; %7D%0A    
@@ -2608,17 +2608,17 @@
 ON = '1.
-1
+4
 .0';%0A%7D).

Update favcount.js to v1.4.0