Skip to content

Instantly share code, notes, and snippets.

@syoichi
Forked from azu/ldr favicon hack.user.js
Created May 4, 2011 07:14
Show Gist options
  • Save syoichi/954866 to your computer and use it in GitHub Desktop.
Save syoichi/954866 to your computer and use it in GitHub Desktop.
Firefox 4.0.1上のGreasemonkey 0.9.3、Scriptish 0.1で動作を確認した。Chrome 11.0.696.60ではfaviconを置き換えられないようで動作せず。
// ==UserScript==
// @name ldr favicon hack
// @namespace http://d.hatena.ne.jp/javascripter/
// @include http://reader.livedoor.com/reader/
// ==/UserScript==
document.getElementById('total_unread_count').addEventListener('DOMAttrModified', function () {
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
unread = unsafeWindow.subs.model.get_unread_count().toString(),
h = document.head,
favicon = h.querySelector('[rel*="icon"]');
canvas.width = canvas.height = 16;
ctx.font = 22 + unread.length * -4 + 'px sans-serif';
ctx.fillText(unread, 0, 13);
favicon.href = canvas.toDataURL();
h.appendChild(favicon);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment