Created
January 7, 2009 16:24
-
-
Save eban/44323 to your computer and use it in GitHub Desktop.
ldr favicon hack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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