Skip to content

Instantly share code, notes, and snippets.

@azu
Created May 1, 2011 06:44
Show Gist options
  • Save azu/950300 to your computer and use it in GitHub Desktop.
Save azu/950300 to your computer and use it in GitHub Desktop.
Firefox4+Scriptitshで動かなかったので修正
// ==UserScript==
// @name ldr favicon hack
// @namespace http://d.hatena.ne.jp/javascripter/
// @include http://reader.livedoor.com/reader/
// ==/UserScript==
(function() {
// 未読数の数値が変化したら更新
document.getElementById("total_unread_count").addEventListener("DOMAttrModified", function(e) {
updateFavicon();
}, true);
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();
canvas.width = canvas.height = 16;
with (canvas.getContext('2d')) {
clearRect(0, 0, 16, 16);
mozTextStyle = 22 + (unread.toString().length) * -4 + "px sans-serif";
translate(0, 14);
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