Skip to content

Instantly share code, notes, and snippets.

@eban
Created January 7, 2009 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eban/44323 to your computer and use it in GitHub Desktop.
Save eban/44323 to your computer and use it in GitHub Desktop.
ldr favicon hack
// ==UserScript==
// @name ldr favicon hack
// @namespace http://d.hatena.ne.jp/javascripter/
// @include http://reader.livedoor.com/reader/
// @include http://fastladder.com/reader/
// ==/UserScript==
(function() {
unsafeWindow.document.watch('title',
function(id, before, after) {
updateFavicon();
return after
});
var favicon = document.evaluate('//head/link[@rel="shortcut icon"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var canvas = document.createElement('canvas');
var head = document.getElementsByTagName('head')[0];
function updateFavicon() {
var unread = unsafeWindow.subs.model.get_unread_count();
var img = new Image();
img.src = '/favicon.ico';
canvas.width = canvas.height = 16;
if (999 < unread) unread = "1k+";
with(canvas.getContext('2d')) {
drawImage(img, 0, 0, 16, 8);
mozTextStyle = 22 + (unread.toString().length) * -4 + "px monospace";
translate(0, 16);
fillStyle = "blue";
mozDrawText(unread);
}
favicon.href = canvas.toDataURL();
head.appendChild(favicon);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment